Skip to content

Commit 8cb9a3e

Browse files
committed
tests: use ::class instead of string literals
1 parent fe8773a commit 8cb9a3e

9 files changed

Lines changed: 39 additions & 39 deletions

File tree

tests/Github/Api.decode.phpt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,74 +24,74 @@ Assert::same([], $api->decode($response));
2424
$e = Assert::exception(function() use ($api) {
2525
$response = new Milo\Github\Http\Response(200, ['Content-Type' => 'application/json'], '[');
2626
$api->decode($response);
27-
}, 'Milo\Github\InvalidResponseException', 'JSON decoding failed.');
27+
}, Milo\Github\InvalidResponseException::class, 'JSON decoding failed.');
2828
$e = Assert::exception(function() use ($e) {
2929
throw $e->getPrevious();
30-
}, 'Milo\Github\JsonException');
30+
}, Milo\Github\JsonException::class);
3131
Assert::null($e->getPrevious());
3232

3333

3434
# Invalid JSON
3535
$e = Assert::exception(function() use ($api) {
3636
$response = new Milo\Github\Http\Response(200, ['Content-Type' => 'application/json'], '""');
3737
$api->decode($response);
38-
}, 'Milo\Github\InvalidResponseException', 'Decoded JSON is not an array or object.');
38+
}, Milo\Github\InvalidResponseException::class, 'Decoded JSON is not an array or object.');
3939
Assert::null($e->getPrevious());
4040

4141

4242
$e = Assert::exception(function() use ($api) {
4343
$response = new Milo\Github\Http\Response(400, ['Content-Type' => 'application/json'], '{"message":"error"}');
4444
$api->decode($response);
45-
}, 'Milo\Github\BadRequestException', 'error', 400);
45+
}, Milo\Github\BadRequestException::class, 'error', 400);
4646
Assert::null($e->getPrevious());
4747

4848

4949
$e = Assert::exception(function() use ($api) {
5050
$response = new Milo\Github\Http\Response(401, ['Content-Type' => 'application/json'], '{"message":"error"}');
5151
$api->decode($response);
52-
}, 'Milo\Github\UnauthorizedException', 'error', 401);
52+
}, Milo\Github\UnauthorizedException::class, 'error', 401);
5353
Assert::null($e->getPrevious());
5454

5555

5656
$e = Assert::exception(function() use ($api) {
5757
$response = new Milo\Github\Http\Response(403, ['Content-Type' => 'application/json'], '{"message":"error"}');
5858
$api->decode($response);
59-
}, 'Milo\Github\ForbiddenException', 'error', 403);
59+
}, Milo\Github\ForbiddenException::class, 'error', 403);
6060
Assert::null($e->getPrevious());
6161

6262

6363
$e = Assert::exception(function() use ($api) {
6464
$response = new Milo\Github\Http\Response(403, ['Content-Type' => 'application/json', 'X-RateLimit-Remaining' => '0'], '{"message":"error"}');
6565
$api->decode($response);
66-
}, 'Milo\Github\RateLimitExceedException', 'error', 403);
66+
}, Milo\Github\RateLimitExceedException::class, 'error', 403);
6767
Assert::null($e->getPrevious());
6868

6969

7070
$e = Assert::exception(function() use ($api) {
7171
$response = new Milo\Github\Http\Response(404, [], '');
7272
$api->decode($response);
73-
}, 'Milo\Github\NotFoundException', 'Resource not found or not authorized to access.', 404);
73+
}, Milo\Github\NotFoundException::class, 'Resource not found or not authorized to access.', 404);
7474
Assert::null($e->getPrevious());
7575

7676

7777
$e = Assert::exception(function() use ($api) {
7878
$response = new Milo\Github\Http\Response(422, ['Content-Type' => 'application/json'], '{"message":"error"}');
7979
$api->decode($response);
80-
}, 'Milo\Github\UnprocessableEntityException', 'error', 422);
80+
}, Milo\Github\UnprocessableEntityException::class, 'error', 422);
8181
Assert::null($e->getPrevious());
8282

8383

8484
$e = Assert::exception(function() use ($api) {
8585
$response = new Milo\Github\Http\Response(422, ['Content-Type' => 'application/json'], '{"message":"error", "errors":[{"a":"b","c":"d"}]}');
8686
$api->decode($response);
87-
}, 'Milo\Github\UnprocessableEntityException', 'error[b:d]', 422);
87+
}, Milo\Github\UnprocessableEntityException::class, 'error[b:d]', 422);
8888
Assert::null($e->getPrevious());
8989

9090

9191
$e = Assert::exception(function() use ($api) {
9292
$response = new Milo\Github\Http\Response(500, [], '');
9393
$api->decode($response);
94-
}, 'Milo\Github\UnexpectedResponseException', 'Expected response with code < 300.', 500);
94+
}, Milo\Github\UnexpectedResponseException::class, 'Expected response with code < 300.', 500);
9595
Assert::null($e->getPrevious());
9696

9797

@@ -101,5 +101,5 @@ Assert::same('foo', $api->decode($response, [500]));
101101
$e = Assert::exception(function() use ($api) {
102102
$response = new Milo\Github\Http\Response(200, [], '');
103103
$api->decode($response, [201, 304]);
104-
}, 'Milo\Github\UnexpectedResponseException', 'Expected response with code 201 or 304.', 200);
104+
}, Milo\Github\UnexpectedResponseException::class, 'Expected response with code 201 or 304.', 200);
105105
Assert::null($e->getPrevious());

tests/Github/Api.expandColonParameters.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ test(function() {
4040

4141
Assert::exception(function() use ($api) {
4242
$api->expandColonParameters(':a', ['A' => 'a']);
43-
}, 'Milo\Github\MissingParameterException', "Missing parameter 'a' for URL path ':a'.");
43+
}, Milo\Github\MissingParameterException::class, "Missing parameter 'a' for URL path ':a'.");
4444

4545
Assert::exception(function() use ($api) {
4646
$api->expandColonParameters(':a:b', ['a' => 'A', 'b' => 'B']);
47-
}, 'Milo\Github\MissingParameterException', "Missing parameter 'a:b' for URL path ':a:b'.");
47+
}, Milo\Github\MissingParameterException::class, "Missing parameter 'a:b' for URL path ':a:b'.");
4848
});
4949

5050

tests/Github/Api.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,5 @@ test(function() {
131131
$client = new MockIClient;
132132
$api = new Milo\Github\Api($client);
133133

134-
Assert::type('Milo\Github\Paginator', $api->paginator(''));
134+
Assert::type(Milo\Github\Paginator::class, $api->paginator(''));
135135
});

tests/Github/Helpers.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ require __DIR__ . '/../bootstrap.php';
1010

1111

1212
$client1 = Milo\Github\Helpers::createDefaultClient();
13-
Assert::type('Milo\Github\Http\IClient', $client1);
13+
Assert::type(Milo\Github\Http\IClient::class, $client1);
1414

1515
$client2 = Milo\Github\Helpers::createDefaultClient();
16-
Assert::type('Milo\Github\Http\IClient', $client2);
16+
Assert::type(Milo\Github\Http\IClient::class, $client2);
1717

1818
Assert::same($client1, $client2);
1919

2020

2121
$client3 = Milo\Github\Helpers::createDefaultClient(true);
22-
Assert::type('Milo\Github\Http\IClient', $client3);
22+
Assert::type(Milo\Github\Http\IClient::class, $client3);
2323

2424
Assert::notSame($client1, $client3);
2525
Assert::notSame($client2, $client3);

tests/Github/Http/CachedClient.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class CachingTestCase extends Tester\TestCase
149149
};
150150
$response = $this->client->request(new Http\Request('', '', [], '2'));
151151
Assert::same('response-1', $response->getContent());
152-
Assert::type('Milo\Github\Http\Response', $response->getPrevious());
152+
Assert::type(Milo\Github\Http\Response::class, $response->getPrevious());
153153
Assert::same(304, $response->getPrevious()->getCode());
154154
Assert::same(2, $this->innerClient->requestCount);
155155
}
@@ -178,7 +178,7 @@ class CachingTestCase extends Tester\TestCase
178178

179179
$response = $this->client->request(new Http\Request('', '', [], '2'));
180180
Assert::same('response-1', $response->getContent());
181-
Assert::type('Milo\Github\Http\Response', $response->getPrevious());
181+
Assert::type(Milo\Github\Http\Response::class, $response->getPrevious());
182182
Assert::same(304, $response->getPrevious()->getCode());
183183
Assert::same(2, $this->innerClient->requestCount);
184184
}
@@ -207,7 +207,7 @@ class CachingTestCase extends Tester\TestCase
207207

208208
$response = $this->client->request(new Http\Request('', '', [], '2'));
209209
Assert::same('response-1', $response->getContent());
210-
Assert::type('Milo\Github\Http\Response', $response->getPrevious());
210+
Assert::type(Milo\Github\Http\Response::class, $response->getPrevious());
211211
Assert::same(304, $response->getPrevious()->getCode());
212212
Assert::same(2, $this->innerClient->requestCount);
213213
}
@@ -226,14 +226,14 @@ class CachingTestCase extends Tester\TestCase
226226
# From cache
227227
$response = $this->client->request($request);
228228
Assert::same('inner-200-same', $response->getContent());
229-
Assert::type('Milo\Github\Http\Response', $response->getPrevious());
229+
Assert::type(Milo\Github\Http\Response::class, $response->getPrevious());
230230
Assert::same('inner-304-same', $response->getPrevious()->getContent());
231231
Assert::same(2, $this->innerClient->requestCount);
232232

233233
# Again
234234
$response = $this->client->request($request);
235235
Assert::same('inner-200-same', $response->getContent());
236-
Assert::type('Milo\Github\Http\Response', $response->getPrevious());
236+
Assert::type(Milo\Github\Http\Response::class, $response->getPrevious());
237237
Assert::same('inner-304-same', $response->getPrevious()->getContent());
238238
Assert::same(3, $this->innerClient->requestCount);
239239
}
@@ -250,13 +250,13 @@ class CachingTestCase extends Tester\TestCase
250250

251251
$response = $this->client->request($request);
252252
Assert::same('inner-200-disabled', $response->getContent());
253-
Assert::type('Milo\Github\Http\Response', $response->getPrevious());
253+
Assert::type(Milo\Github\Http\Response::class, $response->getPrevious());
254254
Assert::same('inner-304-disabled', $response->getPrevious()->getContent());
255255
Assert::same(2, $this->innerClient->requestCount);
256256

257257
$response = $this->client->request($request);
258258
Assert::same('inner-200-disabled', $response->getContent());
259-
Assert::type('Milo\Github\Http\Response', $response->getPrevious());
259+
Assert::type(Milo\Github\Http\Response::class, $response->getPrevious());
260260
Assert::same('inner-304-disabled', $response->getPrevious()->getContent());
261261
Assert::same(3, $this->innerClient->requestCount);
262262
}

tests/Github/Http/Response.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ Assert::same($previous, $response->getPrevious());
2727

2828
Assert::exception(function() use ($response, $previous) {
2929
$response->setPrevious($previous);
30-
}, 'Milo\Github\LogicException', 'Previous response is already set.');
30+
}, Milo\Github\LogicException::class, 'Previous response is already set.');

tests/Github/OAuth/Login.phpt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class LoginTestCase extends Tester\TestCase
6060
Assert::false($this->login->hasToken());
6161
Assert::exception(function() {
6262
$this->login->getToken();
63-
}, 'Milo\Github\LogicException', 'Token has not been obtained yet.');
63+
}, Milo\Github\LogicException::class, 'Token has not been obtained yet.');
6464
}
6565

6666

@@ -83,7 +83,7 @@ class LoginTestCase extends Tester\TestCase
8383
Assert::same(['a','b','c'], $token->getScopes());
8484

8585
Assert::true($this->login->hasToken());
86-
Assert::type('Milo\Github\OAuth\Token', $this->login->getToken());
86+
Assert::type(Milo\Github\OAuth\Token::class, $this->login->getToken());
8787

8888
Assert::same($this->login, $this->login->dropToken());
8989
Assert::false($this->login->hasToken());
@@ -108,7 +108,7 @@ class LoginTestCase extends Tester\TestCase
108108

109109
Assert::exception(function() {
110110
$this->login->obtainToken('', '');
111-
}, 'Milo\Github\OAuth\LoginException', 'OAuth security state does not match.');
111+
}, Milo\Github\OAuth\LoginException::class, 'OAuth security state does not match.');
112112
}
113113

114114

@@ -121,10 +121,10 @@ class LoginTestCase extends Tester\TestCase
121121
};
122122
$e = Assert::exception(function() {
123123
$this->login->obtainToken('', '*****');
124-
}, 'Milo\Github\OAuth\LoginException', 'HTTP request failed.');
124+
}, Milo\Github\OAuth\LoginException::class, 'HTTP request failed.');
125125
$e = Assert::exception(function() use ($e) {
126126
throw $e->getPrevious();
127-
}, 'Milo\Github\Http\BadResponseException', 'fail');
127+
}, Milo\Github\Http\BadResponseException::class, 'fail');
128128
Assert::null($e->getPrevious());
129129
}
130130

@@ -138,10 +138,10 @@ class LoginTestCase extends Tester\TestCase
138138
};
139139
$e = Assert::exception(function() {
140140
$this->login->obtainToken('', '*****');
141-
}, 'Milo\Github\OAuth\LoginException', 'Bad JSON in response.');
141+
}, Milo\Github\OAuth\LoginException::class, 'Bad JSON in response.');
142142
$e = Assert::exception(function() use ($e) {
143143
throw $e->getPrevious();
144-
}, 'Milo\Github\JsonException', 'Syntax error, malformed JSON');
144+
}, Milo\Github\JsonException::class, 'Syntax error, malformed JSON');
145145
Assert::null($e->getPrevious());
146146
}
147147

@@ -155,7 +155,7 @@ class LoginTestCase extends Tester\TestCase
155155
};
156156
$e = Assert::exception(function() {
157157
$this->login->obtainToken('', '*****');
158-
}, 'Milo\Github\OAuth\LoginException', 'fail');
158+
}, Milo\Github\OAuth\LoginException::class, 'fail');
159159
Assert::null($e->getPrevious());
160160
}
161161

@@ -168,7 +168,7 @@ class LoginTestCase extends Tester\TestCase
168168
};
169169
$e = Assert::exception(function() {
170170
$this->login->obtainToken('', '*****');
171-
}, 'Milo\Github\OAuth\LoginException', 'Unexpected response.');
171+
}, Milo\Github\OAuth\LoginException::class, 'Unexpected response.');
172172
Assert::null($e->getPrevious());
173173
}
174174

@@ -179,7 +179,7 @@ class LoginTestCase extends Tester\TestCase
179179
$token = new Milo\Github\OAuth\Token('a', 'b', ['c', 'd']);
180180
$this->storage->set('auth.token', $token);
181181

182-
Assert::type('Milo\Github\OAuth\Token', $this->login->getToken());
182+
Assert::type(Milo\Github\OAuth\Token::class, $this->login->getToken());
183183
Assert::same([
184184
'value' => 'a',
185185
'type' => 'b',

tests/Github/Storages/FileCache.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require __DIR__ . '/../../bootstrap.php';
1111

1212
$e = Assert::exception(function() {
1313
new Milo\Github\Storages\FileCache(__DIR__ . DIRECTORY_SEPARATOR . 'non-exists');
14-
}, 'Milo\Github\Storages\MissingDirectoryException', "Directory '%a%non-exists' is missing.");
14+
}, Milo\Github\Storages\MissingDirectoryException::class, "Directory '%a%non-exists' is missing.");
1515

1616
Assert::null($e->getPrevious());
1717

tests/Github/Strict.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class TestStrict
1616

1717
Assert::exception(function() {
1818
(new TestStrict)->undefined;
19-
}, 'Milo\Github\LogicException', 'Cannot read an undeclared property TestStrict::$undefined.');
19+
}, Milo\Github\LogicException::class, 'Cannot read an undeclared property TestStrict::$undefined.');
2020

2121
Assert::exception(function() {
2222
$mock = new TestStrict;
2323
$mock->undefined = '';
24-
}, 'Milo\Github\LogicException', 'Cannot write to an undeclared property TestStrict::$undefined.');
24+
}, Milo\Github\LogicException::class, 'Cannot write to an undeclared property TestStrict::$undefined.');

0 commit comments

Comments
 (0)