function it_normalizes_the_properties_of_the_product($filter, $serializer, ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value, FamilyInterface $family, ArrayCollection $values, \ArrayIterator $iterator, ProductValueInterface $identifier) { $values->getIterator()->willReturn($iterator); $family->getCode()->willReturn('my_family'); $product->getFamily()->willReturn($family); $product->getGroupCodes()->willReturn([]); $product->getVariantGroup()->willReturn(null); $product->getCategoryCodes()->willReturn([]); $product->isEnabled()->willReturn(true); $value->getAttribute()->willReturn($attribute); $attribute->getCode()->willReturn('name'); $product->getIdentifier()->willReturn($identifier); $identifier->getData()->willReturn('my_code'); $product->getValues()->willReturn($values); $filter->filterCollection($values, 'pim.transform.product_value.structured', Argument::type('array'))->shouldBeCalled()->willReturn($values); $iterator->rewind()->willReturn(null); $valueCount = 1; $iterator->valid()->will(function () use(&$valueCount) { return $valueCount-- > 0; }); $iterator->current()->willReturn($value); $iterator->next()->willReturn(null); $context = ['filter_types' => ['pim.transform.product_value.structured']]; $serializer->normalize($value, 'standard', $context)->willReturn(['locale' => null, 'scope' => null, 'value' => 'foo']); $created = new \DateTime('2010-06-23'); $product->getCreated()->willReturn($created); $serializer->normalize($created, 'standard')->willReturn('2010-06-23T00:00:00+01:00'); $updated = new \DateTime('2010-06-23 23:00:00'); $product->getUpdated()->willReturn($updated); $serializer->normalize($updated, 'standard')->willReturn('2010-06-23T23:00:00+01:00'); $this->normalize($product, 'standard', $context)->shouldReturn(['identifier' => 'my_code', 'family' => 'my_family', 'groups' => [], 'variant_group' => null, 'categories' => [], 'enabled' => true, 'values' => ['name' => [['locale' => null, 'scope' => null, 'value' => 'foo']]], 'created' => '2010-06-23T00:00:00+01:00', 'updated' => '2010-06-23T23:00:00+01:00']); }
function it_normalizes_product(SerializerInterface $serializer, ProductInterface $product, FamilyInterface $family, Completeness $completeness) { $serializer->implement('Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface'); $this->setSerializer($serializer); $product->getFamily()->willReturn($family); $product->getGroups()->willReturn([]); $product->getValues()->willReturn([]); $product->getCompletenesses()->willReturn([$completeness]); $product->getCreated()->willReturn(null); $product->getUpdated()->willReturn(null); $product->isEnabled()->willReturn(true); $serializer->normalize($family, 'mongodb_json', [])->willReturn('family normalization'); $serializer->normalize($completeness, 'mongodb_json', [])->willReturn(['completenessCode' => 'completeness normalization']); $this->normalize($product, 'mongodb_json', [])->shouldReturn([ProductNormalizer::FAMILY_FIELD => 'family normalization', ProductNormalizer::COMPLETENESSES_FIELD => array('completenessCode' => 'completeness normalization'), ProductNormalizer::ENABLED_FIELD => true]); }
/** * Asserts that we have more than a minute interval between the product updated date and the argument * * @Then /^the (product "([^"]+)") updated date should not be close to "([^"]+)"$/ */ public function theProductUpdatedDateShouldNotBeCloseTo(ProductInterface $product, $identifier, $expected) { assertGreaterThan(60, abs(strtotime($expected) - $product->getUpdated()->getTimestamp())); }