Exemplo n.º 1
0
 public function setUp()
 {
     $config = new Configuration();
     $config->setProxyDir(__DIR__ . '/Proxies');
     $config->setProxyNamespace('Proxies');
     $reader = new AnnotationReader();
     $reader->setDefaultAnnotationNamespace('Doctrine\\ODM\\MongoDB\\Mapping\\');
     $config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents'));
     $this->dm = DocumentManager::create(new Mongo(), $config);
     $currencies = array('USD' => 1, 'EURO' => 1.7, 'JPN' => 0.0125);
     foreach ($currencies as $name => &$multiplier) {
         $multiplier = new Currency($name, $multiplier);
         $this->dm->persist($multiplier);
     }
     $product = new ConfigurableProduct('T-Shirt');
     $product->addOption(new Option('small', new Money(12.99, $currencies['USD']), new StockItem('T-shirt Size S', new Money(9.99, $currencies['USD']), 15)));
     $product->addOption(new Option('medium', new Money(14.99, $currencies['USD']), new StockItem('T-shirt Size M', new Money(11.99, $currencies['USD']), 15)));
     $product->addOption(new Option('large', new Money(17.99, $currencies['USD']), new StockItem('T-shirt Size L', new Money(13.99, $currencies['USD']), 15)));
     $this->dm->persist($product);
     $this->dm->flush();
     foreach ($currencies as $currency) {
         $this->dm->detach($currency);
     }
     $this->dm->detach($product);
     unset($currencies, $product);
 }
Exemplo n.º 2
0
 public function testDetach()
 {
     $document = new ConfigurableProduct('foo bar');
     //option 1
     $document->addOption(new Option('foo option', new Money(10.0, new Currency('EURO')), new StockItem('foo item')));
     //option 2
     $document->addOption(new Option('bar option', new Money(20.0, new Currency('EURO')), new StockItem('bar item')));
     //persist document
     $this->dm->persist($document);
     //check the count of uow (Persist operation of money is cascaded)
     $this->assertEquals(9, $this->uow->size());
     //detach the document
     $this->dm->detach($document);
     //should be 0 now
     $this->assertEquals(0, $this->uow->size());
 }
Exemplo n.º 3
0
 public function setUp()
 {
     parent::setUp();
     $currencies = array('USD' => 1, 'EURO' => 1.7, 'JPN' => 0.0125);
     foreach ($currencies as $name => &$multiplier) {
         $multiplier = new Currency($name, $multiplier);
         $this->dm->persist($multiplier);
     }
     $product = new ConfigurableProduct('T-Shirt');
     $product->addOption(new Option('small', new Money(12.99, $currencies['USD']), new StockItem('T-shirt Size S', new Money(9.99, $currencies['USD']), 15)));
     $product->addOption(new Option('medium', new Money(14.99, $currencies['USD']), new StockItem('T-shirt Size M', new Money(11.99, $currencies['USD']), 15)));
     $product->addOption(new Option('large', new Money(17.99, $currencies['USD']), new StockItem('T-shirt Size L', new Money(13.99, $currencies['USD']), 15)));
     $this->dm->persist($product);
     $this->dm->flush();
     foreach ($currencies as $currency) {
         $this->dm->detach($currency);
     }
     $this->dm->detach($product);
     unset($currencies, $product);
 }
Exemplo n.º 4
0
 public function testPrimeEmbeddedReferenceTwoLevelsDeep()
 {
     $product = new ConfigurableProduct('Bundle');
     $product->addOption(new Option('Lens1', new Money(75.0, new Currency('USD', 1)), new StockItem('Filter1', new Money(50.0, new Currency('USD', 1)), 1)));
     $product->addOption(new Option('Lens2', new Money(120.0, new Currency('USD', 1)), new StockItem('Filter2', new Money(100.0, new Currency('USD', 1)), 1)));
     $product->addOption(new Option('Lens3', new Money(180.0, new Currency('USD', 1)), new StockItem('Filter3', new Money(0.01, new Currency('USD', 1)), 1)));
     $this->dm->persist($product);
     $this->dm->flush();
     $this->dm->clear();
     $qb = $this->dm->createQueryBuilder('Documents\\Ecommerce\\ConfigurableProduct')->field('name')->equals('Bundle')->field('options.money.currency')->prime(true);
     /** @var Query $query */
     $query = $qb->getQuery();
     /** @var ConfigurableProduct $product */
     $product = $query->getSingleResult();
     /** @var Option $option */
     $option = $product->getOption('Lens2');
     /** @var Money $money */
     $money = $option->getPrice(true);
     /** @var Currency $currency */
     $currency = $money->getCurrency();
     $this->assertInstanceOf('Doctrine\\ODM\\MongoDB\\Proxy\\Proxy', $currency);
     $this->assertTrue($currency->__isInitialized());
 }