Skip to content

Commit a9cd082

Browse files
Merge branch '3.4' into 4.3
* 3.4: Use `::class` constants instead of `__NAMESPACE__` when possible
2 parents b085f86 + d2cdd95 commit a9cd082

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

Tests/Normalizer/AbstractObjectNormalizerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class AbstractObjectNormalizerTest extends TestCase
4040
public function testDenormalize()
4141
{
4242
$normalizer = new AbstractObjectNormalizerDummy();
43-
$normalizedData = $normalizer->denormalize(['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'], __NAMESPACE__.'\Dummy');
43+
$normalizedData = $normalizer->denormalize(['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'], Dummy::class);
4444

4545
$this->assertSame('foo', $normalizedData->foo);
4646
$this->assertNull($normalizedData->bar);
@@ -50,12 +50,12 @@ public function testDenormalize()
5050
public function testInstantiateObjectDenormalizer()
5151
{
5252
$data = ['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'];
53-
$class = __NAMESPACE__.'\Dummy';
53+
$class = Dummy::class;
5454
$context = [];
5555

5656
$normalizer = new AbstractObjectNormalizerDummy();
5757

58-
$this->assertInstanceOf(__NAMESPACE__.'\Dummy', $normalizer->instantiateObject($data, $class, $context, new \ReflectionClass($class), []));
58+
$this->assertInstanceOf(Dummy::class, $normalizer->instantiateObject($data, $class, $context, new \ReflectionClass($class), []));
5959
}
6060

6161
public function testDenormalizeWithExtraAttributes()
@@ -66,7 +66,7 @@ public function testDenormalizeWithExtraAttributes()
6666
$normalizer = new AbstractObjectNormalizerDummy($factory);
6767
$normalizer->denormalize(
6868
['fooFoo' => 'foo', 'fooBar' => 'bar'],
69-
__NAMESPACE__.'\Dummy',
69+
Dummy::class,
7070
'any',
7171
['allow_extra_attributes' => false]
7272
);

Tests/Normalizer/ArrayDenormalizerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function testSupportsValidArray()
6868
{
6969
$this->serializer->expects($this->once())
7070
->method('supportsDenormalization')
71-
->with($this->anything(), __NAMESPACE__.'\ArrayDummy', $this->anything())
71+
->with($this->anything(), ArrayDummy::class, $this->anything())
7272
->willReturn(true);
7373

7474
$this->assertTrue(
@@ -104,7 +104,7 @@ public function testSupportsNoArray()
104104
$this->assertFalse(
105105
$this->denormalizer->supportsDenormalization(
106106
['foo' => 'one', 'bar' => 'two'],
107-
__NAMESPACE__.'\ArrayDummy'
107+
ArrayDummy::class
108108
)
109109
);
110110
}

Tests/Normalizer/GetSetMethodNormalizerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function setUp(): void
6868

6969
private function createNormalizer(array $defaultContext = [])
7070
{
71-
$this->serializer = $this->getMockBuilder(__NAMESPACE__.'\SerializerNormalizer')->getMock();
71+
$this->serializer = $this->getMockBuilder(SerializerNormalizer::class)->getMock();
7272
$this->normalizer = new GetSetMethodNormalizer(null, null, null, null, null, $defaultContext);
7373
$this->normalizer->setSerializer($this->serializer);
7474
}
@@ -157,7 +157,7 @@ public function testConstructorDenormalize()
157157
{
158158
$obj = $this->normalizer->denormalize(
159159
['foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar'],
160-
__NAMESPACE__.'\GetConstructorDummy', 'any');
160+
GetConstructorDummy::class, 'any');
161161
$this->assertEquals('foo', $obj->getFoo());
162162
$this->assertEquals('bar', $obj->getBar());
163163
$this->assertTrue($obj->isBaz());
@@ -167,7 +167,7 @@ public function testConstructorDenormalizeWithNullArgument()
167167
{
168168
$obj = $this->normalizer->denormalize(
169169
['foo' => 'foo', 'bar' => null, 'baz' => true],
170-
__NAMESPACE__.'\GetConstructorDummy', 'any');
170+
GetConstructorDummy::class, 'any');
171171
$this->assertEquals('foo', $obj->getFoo());
172172
$this->assertNull($obj->getBar());
173173
$this->assertTrue($obj->isBaz());
@@ -177,7 +177,7 @@ public function testConstructorDenormalizeWithMissingOptionalArgument()
177177
{
178178
$obj = $this->normalizer->denormalize(
179179
['foo' => 'test', 'baz' => [1, 2, 3]],
180-
__NAMESPACE__.'\GetConstructorOptionalArgsDummy', 'any');
180+
GetConstructorOptionalArgsDummy::class, 'any');
181181
$this->assertEquals('test', $obj->getFoo());
182182
$this->assertEquals([], $obj->getBar());
183183
$this->assertEquals([1, 2, 3], $obj->getBaz());
@@ -187,7 +187,7 @@ public function testConstructorDenormalizeWithOptionalDefaultArgument()
187187
{
188188
$obj = $this->normalizer->denormalize(
189189
['bar' => 'test'],
190-
__NAMESPACE__.'\GetConstructorArgsWithDefaultValueDummy', 'any');
190+
GetConstructorArgsWithDefaultValueDummy::class, 'any');
191191
$this->assertEquals([], $obj->getFoo());
192192
$this->assertEquals('test', $obj->getBar());
193193
}
@@ -215,14 +215,14 @@ public function testConstructorWithObjectDenormalize()
215215
$data->bar = 'bar';
216216
$data->baz = true;
217217
$data->fooBar = 'foobar';
218-
$obj = $this->normalizer->denormalize($data, __NAMESPACE__.'\GetConstructorDummy', 'any');
218+
$obj = $this->normalizer->denormalize($data, GetConstructorDummy::class, 'any');
219219
$this->assertEquals('foo', $obj->getFoo());
220220
$this->assertEquals('bar', $obj->getBar());
221221
}
222222

223223
public function testConstructorWArgWithPrivateMutator()
224224
{
225-
$obj = $this->normalizer->denormalize(['foo' => 'bar'], __NAMESPACE__.'\ObjectConstructorArgsWithPrivateMutatorDummy', 'any');
225+
$obj = $this->normalizer->denormalize(['foo' => 'bar'], ObjectConstructorArgsWithPrivateMutatorDummy::class, 'any');
226226
$this->assertEquals('bar', $obj->getFoo());
227227
}
228228

@@ -479,7 +479,7 @@ public function testNoStaticGetSetSupport()
479479

480480
public function testPrivateSetter()
481481
{
482-
$obj = $this->normalizer->denormalize(['foo' => 'foobar'], __NAMESPACE__.'\ObjectWithPrivateSetterDummy');
482+
$obj = $this->normalizer->denormalize(['foo' => 'foobar'], ObjectWithPrivateSetterDummy::class);
483483
$this->assertEquals('bar', $obj->getFoo());
484484
}
485485

Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected function setUp(): void
8080

8181
private function createNormalizer(array $defaultContext = [], ClassMetadataFactoryInterface $classMetadataFactory = null)
8282
{
83-
$this->serializer = $this->getMockBuilder(__NAMESPACE__.'\ObjectSerializerNormalizer')->getMock();
83+
$this->serializer = $this->getMockBuilder(ObjectSerializerNormalizer::class)->getMock();
8484
$this->normalizer = new ObjectNormalizer($classMetadataFactory, null, null, null, null, null, $defaultContext);
8585
$this->normalizer->setSerializer($this->serializer);
8686
}
@@ -159,7 +159,7 @@ public function testConstructorDenormalize()
159159
{
160160
$obj = $this->normalizer->denormalize(
161161
['foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar'],
162-
__NAMESPACE__.'\ObjectConstructorDummy', 'any');
162+
ObjectConstructorDummy::class, 'any');
163163
$this->assertEquals('foo', $obj->getFoo());
164164
$this->assertEquals('bar', $obj->bar);
165165
$this->assertTrue($obj->isBaz());
@@ -169,7 +169,7 @@ public function testConstructorDenormalizeWithNullArgument()
169169
{
170170
$obj = $this->normalizer->denormalize(
171171
['foo' => 'foo', 'bar' => null, 'baz' => true],
172-
__NAMESPACE__.'\ObjectConstructorDummy', 'any');
172+
ObjectConstructorDummy::class, 'any');
173173
$this->assertEquals('foo', $obj->getFoo());
174174
$this->assertNull($obj->bar);
175175
$this->assertTrue($obj->isBaz());
@@ -179,7 +179,7 @@ public function testConstructorDenormalizeWithMissingOptionalArgument()
179179
{
180180
$obj = $this->normalizer->denormalize(
181181
['foo' => 'test', 'baz' => [1, 2, 3]],
182-
__NAMESPACE__.'\ObjectConstructorOptionalArgsDummy', 'any');
182+
ObjectConstructorOptionalArgsDummy::class, 'any');
183183
$this->assertEquals('test', $obj->getFoo());
184184
$this->assertEquals([], $obj->bar);
185185
$this->assertEquals([1, 2, 3], $obj->getBaz());
@@ -189,7 +189,7 @@ public function testConstructorDenormalizeWithOptionalDefaultArgument()
189189
{
190190
$obj = $this->normalizer->denormalize(
191191
['bar' => 'test'],
192-
__NAMESPACE__.'\ObjectConstructorArgsWithDefaultValueDummy', 'any');
192+
ObjectConstructorArgsWithDefaultValueDummy::class, 'any');
193193
$this->assertEquals([], $obj->getFoo());
194194
$this->assertEquals('test', $obj->getBar());
195195
}
@@ -201,7 +201,7 @@ public function testConstructorWithObjectDenormalize()
201201
$data->bar = 'bar';
202202
$data->baz = true;
203203
$data->fooBar = 'foobar';
204-
$obj = $this->normalizer->denormalize($data, __NAMESPACE__.'\ObjectConstructorDummy', 'any');
204+
$obj = $this->normalizer->denormalize($data, ObjectConstructorDummy::class, 'any');
205205
$this->assertEquals('foo', $obj->getFoo());
206206
$this->assertEquals('bar', $obj->bar);
207207
}

Tests/Normalizer/PropertyNormalizerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function testDenormalize()
103103
{
104104
$obj = $this->normalizer->denormalize(
105105
['foo' => 'foo', 'bar' => 'bar'],
106-
__NAMESPACE__.'\PropertyDummy',
106+
PropertyDummy::class,
107107
'any'
108108
);
109109
$this->assertEquals('foo', $obj->foo);
@@ -142,7 +142,7 @@ public function testConstructorDenormalize()
142142
{
143143
$obj = $this->normalizer->denormalize(
144144
['foo' => 'foo', 'bar' => 'bar'],
145-
__NAMESPACE__.'\PropertyConstructorDummy',
145+
PropertyConstructorDummy::class,
146146
'any'
147147
);
148148
$this->assertEquals('foo', $obj->getFoo());
@@ -153,7 +153,7 @@ public function testConstructorDenormalizeWithNullArgument()
153153
{
154154
$obj = $this->normalizer->denormalize(
155155
['foo' => null, 'bar' => 'bar'],
156-
__NAMESPACE__.'\PropertyConstructorDummy', '
156+
PropertyConstructorDummy::class, '
157157
any'
158158
);
159159
$this->assertNull($obj->getFoo());
@@ -380,13 +380,13 @@ public function testDenormalizeNonExistingAttribute()
380380
{
381381
$this->assertEquals(
382382
new PropertyDummy(),
383-
$this->normalizer->denormalize(['non_existing' => true], __NAMESPACE__.'\PropertyDummy')
383+
$this->normalizer->denormalize(['non_existing' => true], PropertyDummy::class)
384384
);
385385
}
386386

387387
public function testDenormalizeShouldIgnoreStaticProperty()
388388
{
389-
$obj = $this->normalizer->denormalize(['outOfScope' => true], __NAMESPACE__.'\PropertyDummy');
389+
$obj = $this->normalizer->denormalize(['outOfScope' => true], PropertyDummy::class);
390390

391391
$this->assertEquals(new PropertyDummy(), $obj);
392392
$this->assertEquals('out_of_scope', PropertyDummy::$outOfScope);

0 commit comments

Comments
 (0)