mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-01 10:59:45 +00:00
Add an api list of available person identifiers
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
<?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 Chill\PersonBundle\Tests\PersonIdentifier\Normalizer;
|
||||
|
||||
use Chill\PersonBundle\Entity\Identifier\PersonIdentifierDefinition;
|
||||
use Chill\PersonBundle\PersonIdentifier\Normalizer\PersonIdentifierWorkerNormalizer;
|
||||
use Chill\PersonBundle\PersonIdentifier\PersonIdentifierEngineInterface;
|
||||
use Chill\PersonBundle\PersonIdentifier\PersonIdentifierWorker;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class PersonIdentifierWorkerNormalizerTest extends TestCase
|
||||
{
|
||||
public function testSupportsNormalization(): void
|
||||
{
|
||||
$engine = new class () implements PersonIdentifierEngineInterface {
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'dummy';
|
||||
}
|
||||
|
||||
public function canonicalizeValue(array $value, PersonIdentifierDefinition $definition): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, PersonIdentifierDefinition $personIdentifierDefinition): void {}
|
||||
|
||||
public function renderAsString(?\Chill\PersonBundle\Entity\Identifier\PersonIdentifier $identifier, PersonIdentifierDefinition $definition): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
$definition = new PersonIdentifierDefinition(label: ['en' => 'SSN'], engine: 'string');
|
||||
$worker = new PersonIdentifierWorker($engine, $definition);
|
||||
|
||||
$normalizer = new PersonIdentifierWorkerNormalizer();
|
||||
|
||||
self::assertTrue($normalizer->supportsNormalization($worker));
|
||||
self::assertFalse($normalizer->supportsNormalization(new \stdClass()));
|
||||
}
|
||||
|
||||
public function testNormalizeReturnsExpectedArray(): void
|
||||
{
|
||||
$engine = new class () implements PersonIdentifierEngineInterface {
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'dummy';
|
||||
}
|
||||
|
||||
public function canonicalizeValue(array $value, PersonIdentifierDefinition $definition): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, PersonIdentifierDefinition $personIdentifierDefinition): void {}
|
||||
|
||||
public function renderAsString(?\Chill\PersonBundle\Entity\Identifier\PersonIdentifier $identifier, PersonIdentifierDefinition $definition): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
$definition = new PersonIdentifierDefinition(label: ['en' => 'SSN'], engine: 'string');
|
||||
$definition->setActive(false);
|
||||
$worker = new PersonIdentifierWorker($engine, $definition);
|
||||
|
||||
$normalizer = new PersonIdentifierWorkerNormalizer();
|
||||
$normalized = $normalizer->normalize($worker);
|
||||
|
||||
self::assertSame([
|
||||
'type' => 'person_identifier_worker',
|
||||
'id' => null,
|
||||
'engine' => 'string',
|
||||
'label' => ['en' => 'SSN'],
|
||||
'isActive' => false,
|
||||
], $normalized);
|
||||
}
|
||||
|
||||
public function testNormalizeThrowsOnInvalidObject(): void
|
||||
{
|
||||
$normalizer = new PersonIdentifierWorkerNormalizer();
|
||||
$this->expectException(UnexpectedValueException::class);
|
||||
$normalizer->normalize(new \stdClass());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user