/** * Ticket #2478 from Damon Jones (dljones) */ public function testAddPersistRetrieve() { $f1 = new ECommerceFeature; $f1->setDescription('AC-3'); $f2 = new ECommerceFeature; $f2->setDescription('DTS'); $p = new ECommerceProduct; $p->addFeature($f1); $p->addfeature($f2); $this->_em->persist($p); $this->_em->flush(); $this->assertEquals(2, count($p->getFeatures())); $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $p->getFeatures()); $q = $this->_em->createQuery( 'SELECT p, f FROM Doctrine\Tests\Models\ECommerce\ECommerceProduct p JOIN p.features f' ); $res = $q->getResult(); $this->assertEquals(2, count($p->getFeatures())); $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $p->getFeatures()); // Check that the features are the same instances still foreach ($p->getFeatures() as $feature) { if ($feature->getDescription() == 'AC-3') { $this->assertTrue($feature === $f1); } else { $this->assertTrue($feature === $f2); } } // Now we test how Hydrator affects IdentityMap // (change from ArrayCollection to PersistentCollection) $f3 = new ECommerceFeature(); $f3->setDescription('XVID'); $p->addFeature($f3); // Now we persist the Feature #3 $this->_em->persist($p); $this->_em->flush(); $q = $this->_em->createQuery( 'SELECT p, f FROM Doctrine\Tests\Models\ECommerce\ECommerceProduct p JOIN p.features f' ); $res = $q->getResult(); // Persisted Product now must have 3 Feature items $this->assertEquals(3, count($res[0]->getFeatures())); }
public function createProduct() { $product = new ECommerceProduct(); $product->setName('Doctrine Cookbook'); $this->_em->persist($product); $this->_em->flush(); $this->_em->clear(); return $product->getId(); }
protected function _createFixture() { $product = new ECommerceProduct(); $product->setName('Php manual'); $shipping = new ECommerceShipping(); $shipping->setDays('1'); $product->setShipping($shipping); $this->_em->persist($product); $this->_em->flush(); $this->_em->clear(); }
public function testLazyLoadsFieldValuesFromDatabase() { $product = new ECommerceProduct(); $product->setName('Doctrine Cookbook'); $this->_em->persist($product); $this->_em->flush(); $this->_em->clear(); $id = $product->getId(); $productProxy = $this->_factory->getProxy('Doctrine\\Tests\\Models\\ECommerce\\ECommerceProduct', array('id' => $id)); $this->assertEquals('Doctrine Cookbook', $productProxy->getName()); }
public function testSavingClonedPersistentCollection() { $product = new ECommerceProduct(); $category = new ECommerceCategory(); $category->setName('foo'); $product->addCategory($category); $this->_em->persist($product); $this->_em->persist($category); $this->_em->flush(); $newProduct = clone $product; $this->_em->persist($newProduct); $this->_em->flush(); $this->_em->clear(); $product1 = $this->_em->find('Doctrine\\Tests\\Models\\ECommerce\\ECommerceProduct', $product->getId()); $product2 = $this->_em->find('Doctrine\\Tests\\Models\\ECommerce\\ECommerceProduct', $newProduct->getId()); $this->assertCount(1, $product1->getCategories()); $this->assertCount(1, $product2->getCategories()); $this->assertSame($product1->getCategories()->get(0), $product2->getCategories()->get(0)); }
public function testDoNotInitializeProxyOnGettingTheIdentifierAndReturnTheRightType() { $product = new ECommerceProduct(); $product->setName('Doctrine Cookbook'); $shipping = new ECommerceShipping(); $shipping->setDays(1); $product->setShipping($shipping); $this->_em->persist($product); $this->_em->flush(); $this->_em->clear(); $id = $shipping->getId(); $product = $this->_em->getRepository('Doctrine\\Tests\\Models\\ECommerce\\ECommerceProduct')->find($product->getId()); $entity = $product->getShipping(); $this->assertFalse($entity->__isInitialized__, "Pre-Condition: Object is unitialized proxy."); $this->assertEquals($id, $entity->getId()); $this->assertSame($id, $entity->getId(), "Check that the id's are the same value, and type."); $this->assertFalse($entity->__isInitialized__, "Getting the identifier doesn't initialize the proxy."); }
/** * @group DDC-762 */ public function testNullForeignKey() { $product = new ECommerceProduct(); $product->setName('Doctrine 2 Manual'); $this->_em->persist($product); $this->_em->flush(); $product = $this->_em->find(get_class($product), $product->getId()); $this->assertNull($product->getShipping()); }