Skip to content

Commit e616e2a

Browse files
committed
use ::class constants in tests
1 parent fd35a20 commit e616e2a

File tree

3 files changed

+115
-93
lines changed

3 files changed

+115
-93
lines changed

tests/Functional/ErrorParsingTest.php

+25-18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111
use Art4\JsonApiClient\Helper\Parser;
1212
use Art4\JsonApiClient\Tests\Fixtures\HelperTrait;
13+
use Art4\JsonApiClient\V1\Document;
14+
use Art4\JsonApiClient\V1\Error;
15+
use Art4\JsonApiClient\V1\ErrorCollection;
16+
use Art4\JsonApiClient\V1\ErrorLink;
17+
use Art4\JsonApiClient\V1\ErrorSource;
18+
use Art4\JsonApiClient\V1\Link;
19+
use Art4\JsonApiClient\V1\Meta;
1320
use PHPUnit\Framework\TestCase;
1421

1522
class ErrorParsingTest extends TestCase
@@ -21,7 +28,7 @@ public function testParseErrors(): void
2128
$string = $this->getJsonString('09_errors.json');
2229
$document = Parser::parseResponseString($string);
2330

24-
$this->assertInstanceOf('Art4\JsonApiClient\V1\Document', $document);
31+
$this->assertInstanceOf(Document::class, $document);
2532
$this->assertTrue($document->has('errors'));
2633
$this->assertFalse($document->has('meta'));
2734
$this->assertTrue($document->has('jsonapi'));
@@ -30,37 +37,37 @@ public function testParseErrors(): void
3037
$this->assertFalse($document->has('data'));
3138

3239
$errors = $document->get('errors');
33-
$this->assertInstanceOf('Art4\JsonApiClient\V1\ErrorCollection', $errors);
40+
$this->assertInstanceOf(ErrorCollection::class, $errors);
3441
$this->assertCount(3, $errors->getKeys());
3542

3643
$this->assertTrue($errors->has('0'));
3744
$error0 = $errors->get('0');
3845

39-
$this->assertInstanceOf('Art4\JsonApiClient\V1\Error', $error0);
46+
$this->assertInstanceOf(Error::class, $error0);
4047
$this->assertCount(5, $error0->getKeys());
4148
$this->assertTrue($error0->has('code'));
4249
$this->assertSame('123', $error0->get('code'));
4350
$this->assertTrue($error0->has('source'));
44-
$this->assertInstanceOf('Art4\JsonApiClient\V1\ErrorSource', $error0->get('source'));
51+
$this->assertInstanceOf(ErrorSource::class, $error0->get('source'));
4552
$this->assertTrue($error0->has('source.pointer'));
4653
$this->assertSame('/data/attributes/first-name', $error0->get('source.pointer'));
4754
$this->assertTrue($error0->has('title'));
4855
$this->assertSame('Value is too short', $error0->get('title'));
4956
$this->assertTrue($error0->has('detail'));
5057
$this->assertSame('First name must contain at least three characters.', $error0->get('detail'));
5158
$this->assertTrue($error0->has('meta'));
52-
$this->assertInstanceOf('Art4\JsonApiClient\V1\Meta', $error0->get('meta'));
59+
$this->assertInstanceOf(Meta::class, $error0->get('meta'));
5360
$this->assertSame('bar', $error0->get('meta.foo'));
5461

5562
$this->assertTrue($errors->has('1'));
5663
$error1 = $errors->get('1');
5764

58-
$this->assertInstanceOf('Art4\JsonApiClient\V1\Error', $error1);
65+
$this->assertInstanceOf(Error::class, $error1);
5966
$this->assertCount(4, $error1->getKeys());
6067
$this->assertTrue($error1->has('code'));
6168
$this->assertSame('225', $error1->get('code'));
6269
$this->assertTrue($error1->has('source'));
63-
$this->assertInstanceOf('Art4\JsonApiClient\V1\ErrorSource', $error1->get('source'));
70+
$this->assertInstanceOf(ErrorSource::class, $error1->get('source'));
6471
$this->assertTrue($error1->has('source.pointer'));
6572
$this->assertSame('/data/attributes/password', $error1->get('source.pointer'));
6673
$this->assertTrue($error1->has('title'));
@@ -71,12 +78,12 @@ public function testParseErrors(): void
7178
$this->assertTrue($errors->has('2'));
7279
$error2 = $errors->get('2');
7380

74-
$this->assertInstanceOf('Art4\JsonApiClient\V1\Error', $error2);
81+
$this->assertInstanceOf(Error::class, $error2);
7582
$this->assertCount(3, $error2->getKeys());
7683
$this->assertTrue($error2->has('code'));
7784
$this->assertSame('226', $error2->get('code'));
7885
$this->assertTrue($error2->has('source'));
79-
$this->assertInstanceOf('Art4\JsonApiClient\V1\ErrorSource', $error2->get('source'));
86+
$this->assertInstanceOf(ErrorSource::class, $error2->get('source'));
8087
$this->assertTrue($error2->has('source.pointer'));
8188
$this->assertSame('/data/attributes/password', $error2->get('source.pointer'));
8289
$this->assertTrue($error2->has('title'));
@@ -91,7 +98,7 @@ public function testParseErrorWithLinks(): void
9198
$string = $this->getJsonString('10_error_with_links.json');
9299
$document = Parser::parseResponseString($string);
93100

94-
$this->assertInstanceOf('Art4\JsonApiClient\V1\Document', $document);
101+
$this->assertInstanceOf(Document::class, $document);
95102
$this->assertTrue($document->has('errors'));
96103
$this->assertFalse($document->has('meta'));
97104
$this->assertTrue($document->has('jsonapi'));
@@ -100,42 +107,42 @@ public function testParseErrorWithLinks(): void
100107
$this->assertFalse($document->has('data'));
101108

102109
$errors = $document->get('errors');
103-
$this->assertInstanceOf('Art4\JsonApiClient\V1\ErrorCollection', $errors);
110+
$this->assertInstanceOf(ErrorCollection::class, $errors);
104111
$this->assertCount(2, $errors->getKeys());
105112

106113
$this->assertTrue($errors->has('0'));
107114
$error0 = $errors->get('0');
108115

109-
$this->assertInstanceOf('Art4\JsonApiClient\V1\Error', $error0);
116+
$this->assertInstanceOf(Error::class, $error0);
110117
$this->assertCount(4, $error0->getKeys());
111118
$this->assertTrue($error0->has('code'));
112119
$this->assertSame('123', $error0->get('code'));
113120
$this->assertTrue($error0->has('source'));
114-
$this->assertInstanceOf('Art4\JsonApiClient\V1\ErrorSource', $error0->get('source'));
121+
$this->assertInstanceOf(ErrorSource::class, $error0->get('source'));
115122
$this->assertTrue($error0->has('source.pointer'));
116123
$this->assertSame('/data/attributes/first-name', $error0->get('source.pointer'));
117124
$this->assertTrue($error0->has('title'));
118125
$this->assertSame('Value is too short', $error0->get('title'));
119126
$this->assertTrue($error0->has('links'));
120-
$this->assertInstanceOf('Art4\JsonApiClient\V1\ErrorLink', $error0->get('links'));
127+
$this->assertInstanceOf(ErrorLink::class, $error0->get('links'));
121128
$this->assertTrue($error0->has('links.about'));
122129
$this->assertSame('http://example.org/errors/123', $error0->get('links.about'));
123130

124131
$this->assertTrue($errors->has('1'));
125132
$error1 = $errors->get('1');
126133

127-
$this->assertInstanceOf('Art4\JsonApiClient\V1\Error', $error1);
134+
$this->assertInstanceOf(Error::class, $error1);
128135
$this->assertCount(2, $error1->getKeys());
129136
$this->assertTrue($error1->has('code'));
130137
$this->assertSame('124', $error1->get('code'));
131138
$this->assertTrue($error1->has('links'));
132-
$this->assertInstanceOf('Art4\JsonApiClient\V1\ErrorLink', $error1->get('links'));
139+
$this->assertInstanceOf(ErrorLink::class, $error1->get('links'));
133140
$this->assertTrue($error1->has('links.about'));
134-
$this->assertInstanceOf('Art4\JsonApiClient\V1\Link', $error1->get('links.about'));
141+
$this->assertInstanceOf(Link::class, $error1->get('links.about'));
135142
$this->assertTrue($error1->has('links.about.href'));
136143
$this->assertSame('http://example.org/errors/124', $error1->get('links.about.href'));
137144
$this->assertTrue($error1->has('links.meta'));
138-
$this->assertInstanceOf('Art4\JsonApiClient\V1\Link', $error1->get('links.meta'));
145+
$this->assertInstanceOf(Link::class, $error1->get('links.meta'));
139146
$this->assertTrue($error1->has('links.meta.href'));
140147
$this->assertSame('http://example.org/meta', $error1->get('links.meta.href'));
141148

0 commit comments

Comments
 (0)