Files
chill-bundles/src/Bundle/ChillTicketBundle/tests/Serializer/Normalizer/SetAddresseesCommandDenormalizerTest.php
Julien Fastré b434d38091 Add functionality to set addressees for a ticket
This update includes the implementation of methods to add and retrieve addressee history in the Ticket entity, a handler for addressee setting command, denormalizer for transforming request data to SetAddresseesCommand, and corresponding tests. Additionally, it adds a SetAddresseesController for handling addressee related requests and updates the API specifications.
2024-04-23 22:50:51 +02:00

67 lines
2.2 KiB
PHP

<?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\TicketBundle\Tests\Serializer\Normalizer;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserGroup;
use Chill\TicketBundle\Action\Ticket\SetAddresseesCommand;
use Chill\TicketBundle\Serializer\Normalizer\SetAddresseesCommandDenormalizer;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
/**
* @internal
*
* @coversNothing
*/
class SetAddresseesCommandDenormalizerTest extends TestCase
{
use ProphecyTrait;
public function testSupportsDenormalization()
{
$denormalizer = new SetAddresseesCommandDenormalizer();
self::assertTrue($denormalizer->supportsDenormalization('', SetAddresseesCommand::class, 'json'));
self::assertFalse($denormalizer->supportsDenormalization('', stdClass::class, 'json'));
}
public function testDenormalize()
{
$denormalizer = $this->buildDenormalizer();
$actual = $denormalizer->denormalize(['addressees' => [['type' => 'user'], ['type' => 'user_group']]], SetAddresseesCommand::class, 'json');
self::assertInstanceOf(SetAddresseesCommand::class, $actual);
self::assertIsArray($actual->addressees);
self::assertCount(2, $actual->addressees);
self::assertInstanceOf(User::class, $actual->addressees[0]);
self::assertInstanceOf(UserGroup::class, $actual->addressees[1]);
}
private function buildDenormalizer(): SetAddresseesCommandDenormalizer
{
$normalizer = $this->prophesize(DenormalizerInterface::class);
$normalizer->denormalize(Argument::any(), User::class, 'json', Argument::any())
->willReturn(new User());
$normalizer->denormalize(Argument::any(), UserGroup::class, 'json', Argument::any())
->willReturn(new UserGroup());
$denormalizer = new SetAddresseesCommandDenormalizer();
$denormalizer->setDenormalizer($normalizer->reveal());
return $denormalizer;
}
}