|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Sylius package. |
| 5 | + * |
| 6 | + * (c) Paweł Jędrzejewski |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace spec\Sylius\Bundle\ApiBundle\Serializer; |
| 15 | + |
| 16 | +use PhpSpec\ObjectBehavior; |
| 17 | +use Prophecy\Argument; |
| 18 | +use Sylius\Bundle\ApiBundle\Command\RegisterShopUser; |
| 19 | +use Symfony\Component\Serializer\Exception\MissingConstructorArgumentsException; |
| 20 | +use Symfony\Component\Serializer\Normalizer\ContextAwareDenormalizerInterface; |
| 21 | +use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
| 22 | + |
| 23 | +final class CommandOperationDenormalizerSpec extends ObjectBehavior |
| 24 | +{ |
| 25 | + function let(DenormalizerInterface $baseNormalizer): void |
| 26 | + { |
| 27 | + $this->beConstructedWith($baseNormalizer); |
| 28 | + } |
| 29 | + |
| 30 | + function it_throws_exception_if_not_all_required_parameters_are_present_in_the_context( |
| 31 | + DenormalizerInterface $baseNormalizer |
| 32 | + ): void { |
| 33 | + $baseNormalizer->denormalize(Argument::any())->shouldNotBeCalled(); |
| 34 | + |
| 35 | + $this |
| 36 | + ->shouldThrow(new MissingConstructorArgumentsException( |
| 37 | + 'Request does not have the following required fields specified: firstName, lastName.' |
| 38 | + )) |
| 39 | + ->during( |
| 40 | + 'denormalize', |
| 41 | + [ |
| 42 | + [ 'email' => '[email protected]', 'password' => 'pa$$word'], |
| 43 | + '', |
| 44 | + null, |
| 45 | + ['input' => ['class' => RegisterShopUser::class]] |
| 46 | + ] |
| 47 | + ) |
| 48 | + ; |
| 49 | + } |
| 50 | + |
| 51 | + function it_denormalizes_data_if_all_required_parameters_are_specified( |
| 52 | + DenormalizerInterface $baseNormalizer |
| 53 | + ): void { |
| 54 | + $baseNormalizer |
| 55 | + ->denormalize( |
| 56 | + [ 'firstName' => 'John', 'lastName' => 'Doe', 'email' => '[email protected]', 'password' => 'pa$$word'], |
| 57 | + RegisterShopUser::class, |
| 58 | + null, |
| 59 | + ['input' => ['class' => RegisterShopUser::class]] |
| 60 | + ) |
| 61 | + ->willReturn(['key' => 'value']) |
| 62 | + ; |
| 63 | + |
| 64 | + $this->denormalize( |
| 65 | + [ 'firstName' => 'John', 'lastName' => 'Doe', 'email' => '[email protected]', 'password' => 'pa$$word'], |
| 66 | + '', |
| 67 | + null, |
| 68 | + ['input' => ['class' => RegisterShopUser::class]] |
| 69 | + )->shouldReturn(['key' => 'value']); |
| 70 | + } |
| 71 | + |
| 72 | + function it_implements_context_aware_denormalizer_interface(): void |
| 73 | + { |
| 74 | + $this->shouldImplement(ContextAwareDenormalizerInterface::class); |
| 75 | + } |
| 76 | + |
| 77 | + function it_supports_denormalization_for_specified_input_class(): void |
| 78 | + { |
| 79 | + $this->supportsDenormalization(null, '', null, ['input' => ['class' => 'Class']])->shouldReturn(true); |
| 80 | + } |
| 81 | + |
| 82 | + function it_does_not_support_denormalization_for_not_specified_input_class(): void |
| 83 | + { |
| 84 | + $this->supportsDenormalization(null, '', null, [])->shouldReturn(false); |
| 85 | + } |
| 86 | +} |
0 commit comments