Skip to content

Commit

Permalink
minor #12652 [API][Product] Add additional specs for product normaliz…
Browse files Browse the repository at this point in the history
…er (GSadee)

This PR was merged into the 1.10-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | master
| Bug fix?        | yes?
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | fixes #Sylius/Sylius#12649
| License         | MIT


Commits
-------

ef975695645c3b0176d733da55a857aa77f2bfc5 [API][Product] Add additional specs for product normalizer
  • Loading branch information
AdamKasp committed May 20, 2021
2 parents d074102 + 0adb253 commit 74620da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions Serializer/ProductNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function __construct(
public function normalize($object, $format = null, array $context = [])
{
Assert::isInstanceOf($object, ProductInterface::class);
Assert::keyNotExists($context, self::ALREADY_CALLED);

$context[self::ALREADY_CALLED] = true;

Expand Down
22 changes: 22 additions & 0 deletions spec/Serializer/ProductNormalizerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ function it_supports_only_product_interface(ProductInterface $product, OrderInte
$this->supportsNormalization($order)->shouldReturn(false);
}

function it_does_not_support_if_the_normalizer_has_been_already_called(ProductVariantInterface $variant): void
{
$this
->supportsNormalization($variant, null, ['product_normalizer_already_called' => true])
->shouldReturn(false)
;
}

function it_adds_default_variant_iri_to_serialized_product(
ProductVariantResolverInterface $defaultProductVariantResolver,
IriConverterInterface $iriConverter,
Expand Down Expand Up @@ -67,4 +75,18 @@ function it_adds_default_variant_field_with_null_value_to_serialized_product_if_

$this->normalize($product, null, [])->shouldReturn(['defaultVariant' => null]);
}

function it_throws_an_exception_if_the_normalizer_has_been_already_called(
NormalizerInterface $normalizer,
ProductInterface $product
): void {
$this->setNormalizer($normalizer);

$normalizer->normalize($product, null, ['product_normalizer_already_called' => true])->shouldNotBeCalled();

$this
->shouldThrow(\InvalidArgumentException::class)
->during('normalize', [$product, null, ['product_normalizer_already_called' => true]])
;
}
}

0 comments on commit 74620da

Please sign in to comment.