Exemplo n.º 1
0
 public function setCategory(Category $category)
 {
     $this->category = $category;
     $this->categoryId = $category->getId();
 }
 public function testShouldPopulateReferenceManyEmbedWithLazyCollectionInstance()
 {
     $tvCategory = new Category();
     $tvCategory->setName("Television");
     $this->em->persist($tvCategory);
     $cellPhoneCategory = new Category();
     $cellPhoneCategory->setName("CellPhone");
     $this->em->persist($cellPhoneCategory);
     $this->em->clear();
     $tvMetadata = new Metadata($tvCategory);
     $appleTV = new Product();
     $appleTV->setName('Apple TV');
     $this->dm->persist($appleTV);
     $this->dm->clear();
     $samsungTV = new Product();
     $samsungTV->setName('Samsung TV');
     $this->dm->persist($samsungTV);
     $this->dm->flush();
     $iPhone = new Product();
     $iPhone->setName('iPhone');
     $this->dm->persist($iPhone);
     $this->dm->flush();
     $appleTV->addMetadata($tvMetadata);
     $samsungTV->addMetadata($tvMetadata);
     $this->dm->persist($samsungTV);
     $this->dm->persist($appleTV);
     $this->dm->flush();
     $this->assertEquals($appleTV->getMetadatas()->first(), $tvMetadata);
     $this->assertEquals($samsungTV->getMetadatas()->first(), $tvMetadata);
     $tvs = $tvCategory->getProducts();
     $this->assertNotNull($tvs);
     $first = $tvs->first();
     $last = $tvs->last();
     $this->assertInstanceOf(get_class($appleTV), $first);
     $this->assertEquals('Apple TV', $first->getName());
     $this->assertInstanceOf(get_class($samsungTV), $last);
     $this->assertEquals('Samsung TV', $last->getName());
 }