-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathApiClientTest.php
More file actions
70 lines (61 loc) · 2 KB
/
Copy pathApiClientTest.php
File metadata and controls
70 lines (61 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* This file is part of the Cloudinary PHP package.
*
* (c) Cloudinary
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Cloudinary\Test\Unit;
use Cloudinary\Api\ApiClient;
use Cloudinary\Api\Exception\ApiError;
use Exception;
use GuzzleHttp\Psr7\Response;
use Monolog\Logger as Monolog;
use ReflectionException;
use ReflectionMethod;
/**
* Class ApiClientTest
*/
final class ApiClientTest extends UnitTestCase
{
/**
* Test that attempting to upload a non-existent file logs an error and throws an exception
*
* @throws ReflectionException
* @throws ApiError
*/
public function testLoggingPostFileAsyncEmptyFilename()
{
$apiClient = new ApiClient();
$message = null;
$expectedLogMessage = 'Error while attempting to upload a file';
$expectedExceptionMessage = 'Path cannot be empty';
try {
$apiClient->postFileAsync('/', '', []);
} catch (Exception $e) {
$message = $e->getMessage();
}
self::assertStringStartsWith($expectedExceptionMessage, $message);
self::assertObjectLoggedMessage($apiClient, $expectedLogMessage, Monolog::CRITICAL);
}
/**
* @throws ReflectionException
*/
public function testInvalidApiClientParseJsonResponse()
{
$apiClient = new ApiClient();
$reflectionMethod = new ReflectionMethod(ApiClient::class, 'parseJsonResponse');
$reflectionMethod->setAccessible(true);
$message = null;
$expectedExceptionMessage = 'Error parsing server response';
try {
$reflectionMethod->invoke($apiClient, new Response(200, [], '{NOT_A_JSON}'));
} catch (Exception $e) {
$message = $e->getMessage();
}
self::assertStringStartsWith($expectedExceptionMessage, $message);
self::assertObjectLoggedMessage($apiClient, $expectedExceptionMessage, Monolog::ERROR);
}
}