mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
Docgen/action add missing goals
This commit is contained in:
@@ -14,6 +14,7 @@ namespace Chill\DocGeneratorBundle\tests\Serializer\Normalizer;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
@@ -33,6 +34,49 @@ final class DocGenObjectNormalizerTest extends KernelTestCase
|
||||
$this->normalizer = self::$container->get(NormalizerInterface::class);
|
||||
}
|
||||
|
||||
public function testChangeContextOnAttribute()
|
||||
{
|
||||
$object = new TestableParentClass();
|
||||
$actual = $this->normalizer->normalize(
|
||||
$object,
|
||||
'docgen',
|
||||
['groups' => 'docgen:read']
|
||||
);
|
||||
|
||||
$this->assertIsArray($actual);
|
||||
$this->assertArrayHasKey('child', $actual);
|
||||
$this->assertIsArray($actual['child']);
|
||||
$this->assertArrayHasKey('foo', $actual['child']);
|
||||
$this->assertEquals('bar', $actual['child']['foo']);
|
||||
$this->assertArrayNotHasKey('baz', $actual['child']);
|
||||
|
||||
// test with child = null
|
||||
$object->child = null;
|
||||
$actual = $this->normalizer->normalize(
|
||||
$object,
|
||||
'docgen',
|
||||
['groups' => 'docgen:read']
|
||||
);
|
||||
$this->assertIsArray($actual);
|
||||
$this->assertArrayHasKey('child', $actual);
|
||||
$this->assertIsArray($actual['child']);
|
||||
$this->assertArrayHasKey('foo', $actual['child']);
|
||||
$this->assertEquals('', $actual['child']['foo']);
|
||||
$this->assertArrayNotHasKey('baz', $actual['child']);
|
||||
|
||||
$actual = $this->normalizer->normalize(
|
||||
null,
|
||||
'docgen',
|
||||
['groups' => 'docgen:read', 'docgen:expects' => TestableParentClass::class],
|
||||
);
|
||||
$this->assertIsArray($actual);
|
||||
$this->assertArrayHasKey('child', $actual);
|
||||
$this->assertIsArray($actual['child']);
|
||||
$this->assertArrayHasKey('foo', $actual['child']);
|
||||
$this->assertEquals('', $actual['child']['foo']);
|
||||
$this->assertArrayNotHasKey('baz', $actual['child']);
|
||||
}
|
||||
|
||||
public function testNormalizationBasic()
|
||||
{
|
||||
$scope = new Scope();
|
||||
@@ -99,3 +143,30 @@ final class DocGenObjectNormalizerTest extends KernelTestCase
|
||||
$this->assertEquals($expected, $normalized, 'test normalization fo an user with null center');
|
||||
}
|
||||
}
|
||||
|
||||
class TestableParentClass
|
||||
{
|
||||
/**
|
||||
* @Serializer\Groups("docgen:read")
|
||||
* @Serializer\Context(normalizationContext={"groups": "docgen:read:foo"}, groups={"docgen:read"})
|
||||
*/
|
||||
public ?TestableChildClass $child;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->child = new TestableChildClass();
|
||||
}
|
||||
}
|
||||
|
||||
class TestableChildClass
|
||||
{
|
||||
/**
|
||||
* @Serializer\Groups("docgen:read")
|
||||
*/
|
||||
public string $baz = 'bloup';
|
||||
|
||||
/**
|
||||
* @Serializer\Groups("docgen:read:foo")
|
||||
*/
|
||||
public string $foo = 'bar';
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ namespace Chill\DocGeneratorBundle\tests\Service\Context;
|
||||
|
||||
use Chill\DocGeneratorBundle\Service\Context\BaseContextData;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
@@ -23,6 +24,8 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
*/
|
||||
final class BaseContextDataTest extends KernelTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
Reference in New Issue
Block a user