Skip to content

Commit

Permalink
Merge branch '4.3' into 4.4
Browse files Browse the repository at this point in the history
* 4.3:
  Use `::class` constants instead of `__NAMESPACE__` when possible
  • Loading branch information
nicolas-grekas committed Dec 16, 2019
2 parents f1024c7 + a9cd082 commit e5bc3f6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions Tests/Normalizer/AbstractObjectNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AbstractObjectNormalizerTest extends TestCase
public function testDenormalize()
{
$normalizer = new AbstractObjectNormalizerDummy();
$normalizedData = $normalizer->denormalize(['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'], __NAMESPACE__.'\Dummy');
$normalizedData = $normalizer->denormalize(['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'], Dummy::class);

$this->assertSame('foo', $normalizedData->foo);
$this->assertNull($normalizedData->bar);
Expand All @@ -50,12 +50,12 @@ public function testDenormalize()
public function testInstantiateObjectDenormalizer()
{
$data = ['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'];
$class = __NAMESPACE__.'\Dummy';
$class = Dummy::class;
$context = [];

$normalizer = new AbstractObjectNormalizerDummy();

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

public function testDenormalizeWithExtraAttributes()
Expand All @@ -66,7 +66,7 @@ public function testDenormalizeWithExtraAttributes()
$normalizer = new AbstractObjectNormalizerDummy($factory);
$normalizer->denormalize(
['fooFoo' => 'foo', 'fooBar' => 'bar'],
__NAMESPACE__.'\Dummy',
Dummy::class,
'any',
['allow_extra_attributes' => false]
);
Expand Down
4 changes: 2 additions & 2 deletions Tests/Normalizer/ArrayDenormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testSupportsValidArray()
{
$this->serializer->expects($this->once())
->method('supportsDenormalization')
->with($this->anything(), __NAMESPACE__.'\ArrayDummy', $this->anything())
->with($this->anything(), ArrayDummy::class, $this->anything())
->willReturn(true);

$this->assertTrue(
Expand Down Expand Up @@ -104,7 +104,7 @@ public function testSupportsNoArray()
$this->assertFalse(
$this->denormalizer->supportsDenormalization(
['foo' => 'one', 'bar' => 'two'],
__NAMESPACE__.'\ArrayDummy'
ArrayDummy::class
)
);
}
Expand Down
16 changes: 8 additions & 8 deletions Tests/Normalizer/GetSetMethodNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function setUp(): void

private function createNormalizer(array $defaultContext = [])
{
$this->serializer = $this->getMockBuilder(__NAMESPACE__.'\SerializerNormalizer')->getMock();
$this->serializer = $this->getMockBuilder(SerializerNormalizer::class)->getMock();
$this->normalizer = new GetSetMethodNormalizer(null, null, null, null, null, $defaultContext);
$this->normalizer->setSerializer($this->serializer);
}
Expand Down Expand Up @@ -157,7 +157,7 @@ public function testConstructorDenormalize()
{
$obj = $this->normalizer->denormalize(
['foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar'],
__NAMESPACE__.'\GetConstructorDummy', 'any');
GetConstructorDummy::class, 'any');
$this->assertEquals('foo', $obj->getFoo());
$this->assertEquals('bar', $obj->getBar());
$this->assertTrue($obj->isBaz());
Expand All @@ -167,7 +167,7 @@ public function testConstructorDenormalizeWithNullArgument()
{
$obj = $this->normalizer->denormalize(
['foo' => 'foo', 'bar' => null, 'baz' => true],
__NAMESPACE__.'\GetConstructorDummy', 'any');
GetConstructorDummy::class, 'any');
$this->assertEquals('foo', $obj->getFoo());
$this->assertNull($obj->getBar());
$this->assertTrue($obj->isBaz());
Expand All @@ -177,7 +177,7 @@ public function testConstructorDenormalizeWithMissingOptionalArgument()
{
$obj = $this->normalizer->denormalize(
['foo' => 'test', 'baz' => [1, 2, 3]],
__NAMESPACE__.'\GetConstructorOptionalArgsDummy', 'any');
GetConstructorOptionalArgsDummy::class, 'any');
$this->assertEquals('test', $obj->getFoo());
$this->assertEquals([], $obj->getBar());
$this->assertEquals([1, 2, 3], $obj->getBaz());
Expand All @@ -187,7 +187,7 @@ public function testConstructorDenormalizeWithOptionalDefaultArgument()
{
$obj = $this->normalizer->denormalize(
['bar' => 'test'],
__NAMESPACE__.'\GetConstructorArgsWithDefaultValueDummy', 'any');
GetConstructorArgsWithDefaultValueDummy::class, 'any');
$this->assertEquals([], $obj->getFoo());
$this->assertEquals('test', $obj->getBar());
}
Expand Down Expand Up @@ -215,14 +215,14 @@ public function testConstructorWithObjectDenormalize()
$data->bar = 'bar';
$data->baz = true;
$data->fooBar = 'foobar';
$obj = $this->normalizer->denormalize($data, __NAMESPACE__.'\GetConstructorDummy', 'any');
$obj = $this->normalizer->denormalize($data, GetConstructorDummy::class, 'any');
$this->assertEquals('foo', $obj->getFoo());
$this->assertEquals('bar', $obj->getBar());
}

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

Expand Down Expand Up @@ -479,7 +479,7 @@ public function testNoStaticGetSetSupport()

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

Expand Down
12 changes: 6 additions & 6 deletions Tests/Normalizer/ObjectNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function setUp(): void

private function createNormalizer(array $defaultContext = [], ClassMetadataFactoryInterface $classMetadataFactory = null)
{
$this->serializer = $this->getMockBuilder(__NAMESPACE__.'\ObjectSerializerNormalizer')->getMock();
$this->serializer = $this->getMockBuilder(ObjectSerializerNormalizer::class)->getMock();
$this->normalizer = new ObjectNormalizer($classMetadataFactory, null, null, null, null, null, $defaultContext);
$this->normalizer->setSerializer($this->serializer);
}
Expand Down Expand Up @@ -159,7 +159,7 @@ public function testConstructorDenormalize()
{
$obj = $this->normalizer->denormalize(
['foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar'],
__NAMESPACE__.'\ObjectConstructorDummy', 'any');
ObjectConstructorDummy::class, 'any');
$this->assertEquals('foo', $obj->getFoo());
$this->assertEquals('bar', $obj->bar);
$this->assertTrue($obj->isBaz());
Expand All @@ -169,7 +169,7 @@ public function testConstructorDenormalizeWithNullArgument()
{
$obj = $this->normalizer->denormalize(
['foo' => 'foo', 'bar' => null, 'baz' => true],
__NAMESPACE__.'\ObjectConstructorDummy', 'any');
ObjectConstructorDummy::class, 'any');
$this->assertEquals('foo', $obj->getFoo());
$this->assertNull($obj->bar);
$this->assertTrue($obj->isBaz());
Expand All @@ -179,7 +179,7 @@ public function testConstructorDenormalizeWithMissingOptionalArgument()
{
$obj = $this->normalizer->denormalize(
['foo' => 'test', 'baz' => [1, 2, 3]],
__NAMESPACE__.'\ObjectConstructorOptionalArgsDummy', 'any');
ObjectConstructorOptionalArgsDummy::class, 'any');
$this->assertEquals('test', $obj->getFoo());
$this->assertEquals([], $obj->bar);
$this->assertEquals([1, 2, 3], $obj->getBaz());
Expand All @@ -189,7 +189,7 @@ public function testConstructorDenormalizeWithOptionalDefaultArgument()
{
$obj = $this->normalizer->denormalize(
['bar' => 'test'],
__NAMESPACE__.'\ObjectConstructorArgsWithDefaultValueDummy', 'any');
ObjectConstructorArgsWithDefaultValueDummy::class, 'any');
$this->assertEquals([], $obj->getFoo());
$this->assertEquals('test', $obj->getBar());
}
Expand All @@ -201,7 +201,7 @@ public function testConstructorWithObjectDenormalize()
$data->bar = 'bar';
$data->baz = true;
$data->fooBar = 'foobar';
$obj = $this->normalizer->denormalize($data, __NAMESPACE__.'\ObjectConstructorDummy', 'any');
$obj = $this->normalizer->denormalize($data, ObjectConstructorDummy::class, 'any');
$this->assertEquals('foo', $obj->getFoo());
$this->assertEquals('bar', $obj->bar);
}
Expand Down
10 changes: 5 additions & 5 deletions Tests/Normalizer/PropertyNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function testDenormalize()
{
$obj = $this->normalizer->denormalize(
['foo' => 'foo', 'bar' => 'bar'],
__NAMESPACE__.'\PropertyDummy',
PropertyDummy::class,
'any'
);
$this->assertEquals('foo', $obj->foo);
Expand Down Expand Up @@ -143,7 +143,7 @@ public function testConstructorDenormalize()
{
$obj = $this->normalizer->denormalize(
['foo' => 'foo', 'bar' => 'bar'],
__NAMESPACE__.'\PropertyConstructorDummy',
PropertyConstructorDummy::class,
'any'
);
$this->assertEquals('foo', $obj->getFoo());
Expand All @@ -154,7 +154,7 @@ public function testConstructorDenormalizeWithNullArgument()
{
$obj = $this->normalizer->denormalize(
['foo' => null, 'bar' => 'bar'],
__NAMESPACE__.'\PropertyConstructorDummy', '
PropertyConstructorDummy::class, '
any'
);
$this->assertNull($obj->getFoo());
Expand Down Expand Up @@ -381,13 +381,13 @@ public function testDenormalizeNonExistingAttribute()
{
$this->assertEquals(
new PropertyDummy(),
$this->normalizer->denormalize(['non_existing' => true], __NAMESPACE__.'\PropertyDummy')
$this->normalizer->denormalize(['non_existing' => true], PropertyDummy::class)
);
}

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

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

0 comments on commit e5bc3f6

Please sign in to comment.