setRelatedDummy() public method

public setRelatedDummy ( RelatedDummy $relatedDummy )
$relatedDummy RelatedDummy
Beispiel #1
0
 /**
  * @Given there is :nb dummy objects with dummyDate and relatedDummy
  */
 public function thereIsDummyObjectsWithDummyDateAndRelatedDummy($nb)
 {
     for ($i = 1; $i <= $nb; ++$i) {
         $date = new \DateTime(sprintf('2015-04-%d', $i), new \DateTimeZone('UTC'));
         $relatedDummy = new RelatedDummy();
         $relatedDummy->setName('RelatedDummy #' . $i);
         $relatedDummy->setDummyDate($date);
         $dummy = new Dummy();
         $dummy->setName('Dummy #' . $i);
         $dummy->setAlias('Alias #' . ($nb - $i));
         $dummy->setRelatedDummy($relatedDummy);
         // Last Dummy has a null date
         if ($nb !== $i) {
             $dummy->setDummyDate($date);
         }
         $this->manager->persist($relatedDummy);
         $this->manager->persist($dummy);
     }
     $this->manager->flush();
 }
 public function testNormalizeReadableLinks()
 {
     $relatedDummy = new RelatedDummy();
     $dummy = new Dummy();
     $dummy->setRelatedDummy($relatedDummy);
     $dummy->relatedDummies->add(new RelatedDummy());
     $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
     $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['relatedDummy', 'relatedDummies']))->shouldBeCalled();
     $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
     $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn(new PropertyMetadata(new Type(Type::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class), '', true, false, true))->shouldBeCalled();
     $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', [])->willReturn(new PropertyMetadata(new Type(Type::BUILTIN_TYPE_OBJECT, false, ArrayCollection::class, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class)), '', true, false, true))->shouldBeCalled();
     $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
     $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
     $propertyAccessorProphecy->getValue($dummy, 'relatedDummy')->willReturn($relatedDummy)->shouldBeCalled();
     $propertyAccessorProphecy->getValue($dummy, 'relatedDummies')->willReturn(new ArrayCollection([$relatedDummy]))->shouldBeCalled();
     $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
     $resourceClassResolverProphecy->getResourceClass($dummy, null, true)->willReturn(Dummy::class)->shouldBeCalled();
     $resourceClassResolverProphecy->isResourceClass(RelatedDummy::class)->willReturn(RelatedDummy::class)->shouldBeCalled();
     $serializerProphecy = $this->prophesize(SerializerInterface::class);
     $serializerProphecy->willImplement(NormalizerInterface::class);
     $serializerProphecy->normalize($relatedDummy, null, Argument::type('array'))->willReturn(['foo' => 'hello'])->shouldBeCalled();
     $serializerProphecy->normalize(['foo' => 'hello'], null, Argument::type('array'))->willReturn(['foo' => 'hello'])->shouldBeCalled();
     $serializerProphecy->normalize([['foo' => 'hello']], null, Argument::type('array'))->willReturn([['foo' => 'hello']])->shouldBeCalled();
     $normalizer = $this->getMockForAbstractClass(AbstractItemNormalizer::class, [$propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal()]);
     $normalizer->setSerializer($serializerProphecy->reveal());
     $this->assertEquals(['relatedDummy' => ['foo' => 'hello'], 'relatedDummies' => [['foo' => 'hello']]], $normalizer->normalize($dummy));
 }