public function setCustomer(ECommerceCustomer $customer)
 {
     if ($this->customer !== $customer) {
         $this->customer = $customer;
         $customer->setCart($this);
     }
 }
 public function testAcceptsForeignKeysAsCriteria()
 {
     $customer = new ECommerceCustomer();
     $customer->setName('John Doe');
     $cart = new ECommerceCart();
     $cart->setPayment('Credit card');
     $customer->setCart($cart);
     $this->_em->persist($customer);
     $this->_em->flush();
     $this->_em->clear();
     unset($cart);
     $class = $this->_em->getClassMetadata('Doctrine\\Tests\\Models\\ECommerce\\ECommerceCart');
     $persister = $this->_em->getUnitOfWork()->getEntityPersister('Doctrine\\Tests\\Models\\ECommerce\\ECommerceCart');
     $newCart = new ECommerceCart();
     $persister->load(array('customer_id' => $customer->getId()), $newCart, $class->associationMappings['customer']);
     $this->assertEquals('Credit card', $newCart->getPayment());
 }
Beispiel #3
0
 /**
  * @group DDC-736
  * @group DDC-925
  * @group DDC-915
  */
 public function testDqlTreeWalkerReordering()
 {
     $cust = new ECommerceCustomer();
     $cust->setName('roman');
     $cart = new ECommerceCart();
     $cart->setPayment('cash');
     $cart->setCustomer($cust);
     $this->_em->persist($cust);
     $this->_em->persist($cart);
     $this->_em->flush();
     $this->_em->clear();
     $dql = "select c, c.name, ca, ca.payment from Doctrine\\Tests\\Models\\ECommerce\\ECommerceCart ca join ca.customer c";
     $result = $this->_em->createQuery($dql)->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\\Tests\\ORM\\Functional\\Ticket\\DisableFetchJoinTreeWalker'))->getResult();
     /* @var $cart2 Doctrine\Tests\Models\ECommerce\ECommerceCart */
     $cart2 = $result[0][0];
     $this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $cart2->getCustomer());
 }
Beispiel #4
0
 /**
  * @group DDC-736
  */
 public function testFetchJoinInitializesPreviouslyUninitializedCollectionOfManagedEntity()
 {
     $cust = new ECommerceCustomer();
     $cust->setName('roman');
     $cart = new ECommerceCart();
     $cart->setPayment('cash');
     $cart->setCustomer($cust);
     $this->_em->persist($cust);
     $this->_em->persist($cart);
     $this->_em->flush();
     $this->_em->clear();
     $result = $this->_em->createQuery("select c, c.name, ca, ca.payment from Doctrine\\Tests\\Models\\ECommerce\\ECommerceCart ca join ca.customer c")->getSingleResult();
     $cart2 = $result[0];
     unset($result[0]);
     $this->assertInstanceOf('Doctrine\\Tests\\Models\\ECommerce\\ECommerceCart', $cart2);
     $this->assertNotInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $cart2->getCustomer());
     $this->assertInstanceOf('Doctrine\\Tests\\Models\\ECommerce\\ECommerceCustomer', $cart2->getCustomer());
     $this->assertEquals(array('name' => 'roman', 'payment' => 'cash'), $result);
 }
 private function _createFixture()
 {
     $customer = new ECommerceCustomer();
     $customer->setName('Luke Skywalker');
     $mentor = new ECommerceCustomer();
     $mentor->setName('Obi-wan Kenobi');
     $customer->setMentor($mentor);
     $this->_em->persist($customer);
     $this->_em->flush();
     $this->_em->clear();
 }
 protected function _createFixture()
 {
     $customer = new ECommerceCustomer();
     $customer->setName('Giorgio');
     $cart = new ECommerceCart();
     $cart->setPayment('paypal');
     $customer->setCart($cart);
     $this->_em->persist($customer);
     $this->_em->flush();
     $this->_em->clear();
 }