2017-02-22 15:41:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Symfony\Component\Serializer\Tests\Normalizer;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait;
|
|
|
|
use Symfony\Component\Serializer\Tests\Fixtures\ProxyDummy;
|
|
|
|
|
|
|
|
class ObjectToPopulateTraitTest extends TestCase
|
|
|
|
{
|
|
|
|
use ObjectToPopulateTrait;
|
|
|
|
|
|
|
|
public function testExtractObjectToPopulateReturnsNullWhenKeyIsMissing()
|
|
|
|
{
|
2019-01-16 09:39:14 +00:00
|
|
|
$object = $this->extractObjectToPopulate(ProxyDummy::class, []);
|
2017-02-22 15:41:23 +00:00
|
|
|
|
|
|
|
$this->assertNull($object);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractObjectToPopulateReturnsNullWhenNonObjectIsProvided()
|
|
|
|
{
|
2019-01-16 09:39:14 +00:00
|
|
|
$object = $this->extractObjectToPopulate(ProxyDummy::class, [
|
2017-02-22 15:41:23 +00:00
|
|
|
'object_to_populate' => 'not an object',
|
2019-01-16 09:39:14 +00:00
|
|
|
]);
|
2017-02-22 15:41:23 +00:00
|
|
|
|
|
|
|
$this->assertNull($object);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractObjectToPopulateReturnsNullWhenTheClassIsNotAnInstanceOfTheProvidedClass()
|
|
|
|
{
|
2019-01-16 09:39:14 +00:00
|
|
|
$object = $this->extractObjectToPopulate(ProxyDummy::class, [
|
2017-02-22 15:41:23 +00:00
|
|
|
'object_to_populate' => new \stdClass(),
|
2019-01-16 09:39:14 +00:00
|
|
|
]);
|
2017-02-22 15:41:23 +00:00
|
|
|
|
|
|
|
$this->assertNull($object);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractObjectToPopulateReturnsObjectWhenEverythingChecksOut()
|
|
|
|
{
|
|
|
|
$expected = new ProxyDummy();
|
2019-01-16 09:39:14 +00:00
|
|
|
$object = $this->extractObjectToPopulate(ProxyDummy::class, [
|
2017-02-22 15:41:23 +00:00
|
|
|
'object_to_populate' => $expected,
|
2019-01-16 09:39:14 +00:00
|
|
|
]);
|
2017-02-22 15:41:23 +00:00
|
|
|
|
|
|
|
$this->assertSame($expected, $object);
|
|
|
|
}
|
|
|
|
}
|