mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
DX: [docgen] add more test for docgenObjectNormalizer and AccompanyingPeriodResourceNormalizer
This commit is contained in:
parent
ea5f8c9d08
commit
2a782044e6
@ -77,6 +77,19 @@ final class DocGenObjectNormalizerTest extends KernelTestCase
|
||||
$this->assertArrayNotHasKey('baz', $actual['child']);
|
||||
}
|
||||
|
||||
public function testNormalizableBooleanPropertyOrMethodOnNull()
|
||||
{
|
||||
$actual = $this->normalizer->normalize(null, 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => TestableClassWithBool::class]);
|
||||
|
||||
$expected = [
|
||||
'foo' => null,
|
||||
'thing' => null,
|
||||
'isNull' => true,
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testNormalizationBasic()
|
||||
{
|
||||
$scope = new Scope();
|
||||
@ -93,6 +106,22 @@ final class DocGenObjectNormalizerTest extends KernelTestCase
|
||||
$this->assertEquals($expected, $normalized, 'test normalization fo a scope');
|
||||
}
|
||||
|
||||
public function testNormalizeBooleanPropertyOrMethod()
|
||||
{
|
||||
$testable = new TestableClassWithBool();
|
||||
$testable->foo = false;
|
||||
|
||||
$actual = $this->normalizer->normalize($testable, 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => TestableClassWithBool::class]);
|
||||
|
||||
$expected = [
|
||||
'foo' => false,
|
||||
'thing' => true,
|
||||
'isNull' => false,
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testNormalizeNull()
|
||||
{
|
||||
$actual = $this->normalizer->normalize(null, 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => Scope::class]);
|
||||
@ -170,3 +199,19 @@ class TestableChildClass
|
||||
*/
|
||||
public string $foo = 'bar';
|
||||
}
|
||||
|
||||
class TestableClassWithBool
|
||||
{
|
||||
/**
|
||||
* @Serializer\Groups("docgen:read")
|
||||
*/
|
||||
public bool $foo;
|
||||
|
||||
/**
|
||||
* @Serializer\Groups("docgen:read")
|
||||
*/
|
||||
public function getThing(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Serializer\Normalizer;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class AccompanyingPeriodResourceNormalizerTest extends KernelTestCase
|
||||
{
|
||||
private NormalizerInterface $normalizer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$this->normalizer = self::$container->get(NormalizerInterface::class);
|
||||
}
|
||||
|
||||
public function testNormalizeNullHasSameValueAsNotNull()
|
||||
{
|
||||
$nullResource = $this->normalizer->normalize(null, 'docgen', ['groups' => 'docgen:read', 'docgen:expects' => Resource::class]);
|
||||
$notNull = $this->normalizer->normalize(new Resource(), 'docgen', ['groups' => 'docgen:read', 'docgen:expects' => Resource::class]);
|
||||
|
||||
$this->assertEqualsCanonicalizing(array_keys($notNull), array_keys($nullResource));
|
||||
}
|
||||
|
||||
public function testNormalizeResource()
|
||||
{
|
||||
$resource = new Resource();
|
||||
$resource
|
||||
->setComment('blabla')
|
||||
->setResource(new ThirdParty());
|
||||
|
||||
$expected = [
|
||||
'type' => 'accompanying_period_resource',
|
||||
'isNull' => false,
|
||||
'comment' => 'blabla',
|
||||
];
|
||||
|
||||
$actual = $this->normalizer->normalize($resource, 'docgen', ['groups' => 'docgen:read', 'docgen:expects' => Resource::class]);
|
||||
|
||||
// we do not test for sub array (person, thirdparty). We then check first for base value...
|
||||
foreach ($expected as $key => $value) {
|
||||
$this->assertArrayHasKey($key, $actual);
|
||||
$this->assertEquals($value, $actual[$key]);
|
||||
}
|
||||
|
||||
// ... and then for the existence of some values
|
||||
$this->assertArrayHasKey('person', $actual);
|
||||
$this->assertArrayHasKey('thirdParty', $actual);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user