This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectToPopulateTraitTest.php

48 lines
1.4 KiB
PHP
Raw Normal View History

<?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, []);
$this->assertNull($object);
}
public function testExtractObjectToPopulateReturnsNullWhenNonObjectIsProvided()
{
2019-01-16 09:39:14 +00:00
$object = $this->extractObjectToPopulate(ProxyDummy::class, [
'object_to_populate' => 'not an object',
2019-01-16 09:39:14 +00:00
]);
$this->assertNull($object);
}
public function testExtractObjectToPopulateReturnsNullWhenTheClassIsNotAnInstanceOfTheProvidedClass()
{
2019-01-16 09:39:14 +00:00
$object = $this->extractObjectToPopulate(ProxyDummy::class, [
'object_to_populate' => new \stdClass(),
2019-01-16 09:39:14 +00:00
]);
$this->assertNull($object);
}
public function testExtractObjectToPopulateReturnsObjectWhenEverythingChecksOut()
{
$expected = new ProxyDummy();
2019-01-16 09:39:14 +00:00
$object = $this->extractObjectToPopulate(ProxyDummy::class, [
'object_to_populate' => $expected,
2019-01-16 09:39:14 +00:00
]);
$this->assertSame($expected, $object);
}
}