mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
add a discrimnator type on onbjects
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Tests\Serializer\Normalizer;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Chill\MainBundle\Serializer\Normalizer\DoctrineExistingEntityNormalizer;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
|
||||
|
||||
class DoctrineExistingEntityNormalizerTest extends KernelTestCase
|
||||
{
|
||||
protected DoctrineExistingEntityNormalizer $normalizer;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
$serializerFactory = self::$container->get(ClassMetadataFactoryInterface::class);
|
||||
|
||||
$this->normalizer = new DoctrineExistingEntityNormalizer($em, $serializerFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderUserId
|
||||
*/
|
||||
public function testGetMappedClass($userId)
|
||||
{
|
||||
$data = [ 'type' => 'user', 'id' => $userId];
|
||||
$supports = $this->normalizer->supportsDenormalization($data, User::class);
|
||||
|
||||
$this->assertTrue($supports);
|
||||
}
|
||||
|
||||
public function dataProviderUserId()
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$userIds = self::$container->get(EntityManagerInterface::class)
|
||||
->getRepository(User::class)
|
||||
->createQueryBuilder('u')
|
||||
->select('u.id')
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
|
||||
yield [ $userIds[0]['id'] ];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user