public function testMapObject()
 {
     $mapping = $this->mapper->mapObject($this->product);
     $this->assertEquals('test product ', $mapping['text']['name']);
     $this->assertEquals(150, $mapping['decimal']['price']);
     $this->assertEquals(10, $mapping['integer']['count']);
     $manufacturer = new Manufacturer();
     $manufacturer->setName('reebok');
     $manufacturer->addProduct($this->product);
     $this->mapper->mapObject($manufacturer);
 }
示例#2
0
 protected function setUp()
 {
     $this->manufacturer = new Manufacturer();
     $this->manufacturer->setName('adidas');
     $this->product = new Product();
     $this->product->setName('test product')->setCount(self::TEST_COUNT)->setPrice(self::TEST_PRICE)->setManufacturer($this->manufacturer)->setDescription('description')->setCreateDate(new \DateTime());
     foreach ($this->categories as $categoryName) {
         $category = new Category();
         $category->setName($categoryName)->addProduct($this->product);
         $this->product->addCategory($category);
         if (!$this->category) {
             $this->category = $category;
         }
     }
     $this->manufacturer->addProduct($this->product);
     $eventDispatcher = $this->getMockBuilder('Symfony\\Component\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock();
     $mapperProvider = new SearchMappingProvider($eventDispatcher);
     $mapperProvider->setMappingConfig($this->mappingConfig);
     $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->mapper = new ObjectMapper($this->dispatcher, $this->mappingConfig);
     $this->mapper->setMappingProvider($mapperProvider);
 }
示例#3
0
 public function testMapObject()
 {
     $productName = $this->product->getName();
     $productDescription = $this->product->getDescription();
     $manufacturerName = $this->product->getManufacturer()->getName();
     $allTextData = sprintf('%s %s %s', $productName, $productDescription, $manufacturerName);
     $productMapping = array('text' => array('name' => $productName, 'description' => $productDescription, 'manufacturer' => $manufacturerName, 'all_data' => $allTextData, Indexer::TEXT_ALL_DATA_FIELD => $allTextData), 'decimal' => array('price' => $this->product->getPrice()), 'integer' => array('count' => $this->product->getCount()));
     $this->assertEquals($productMapping, $this->mapper->mapObject($this->product));
     $manufacturer = new Manufacturer();
     $manufacturer->setName('reebok');
     $manufacturer->addProduct($this->product);
     $manufacturerMapping = array('text' => array('products' => $productName, Indexer::TEXT_ALL_DATA_FIELD => $productName));
     $this->assertEquals($manufacturerMapping, $this->mapper->mapObject($manufacturer));
 }
示例#4
0
 public function testSave()
 {
     $query = $this->getMock('Doctrine\\ORM\\AbstractQuery', array('getSQL', 'setMaxResults', 'getOneOrNullResult', 'setParameter', '_doExecute'), array(), '', false);
     $this->mapper->expects($this->any())->method('mapObject')->will($this->returnValue(array(array())));
     $this->om->expects($this->once())->method('createQuery')->will($this->returnValue($query));
     $query->expects($this->any())->method('setParameter')->will($this->returnValue($query));
     $query->expects($this->once())->method('setMaxResults')->will($this->returnValue($query));
     $query->expects($this->once())->method('getOneOrNullResult')->will($this->returnValue(0));
     $searchRepo = $this->getMockBuilder('Oro\\Bundle\\SearchBundle\\Entity\\Repository\\SearchIndexRepository')->disableOriginalConstructor()->getMock();
     $this->om->expects($this->any())->method('getRepository')->with($this->equalTo('OroSearchBundle:Item'))->will($this->returnValue($searchRepo));
     $this->container->expects($this->any())->method('getParameter')->with($this->equalTo('oro_search.engine_orm'))->will($this->returnValue('test_orm'));
     $searchRepo->expects($this->any())->method('setDriversClasses');
     $meta = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $reflectionProperty = $this->getMockBuilder('\\ReflectionProperty')->disableOriginalConstructor()->getMock();
     $meta->expects($this->any())->method('getReflectionProperty')->will($this->returnValue($reflectionProperty));
     $this->om->expects($this->any())->method('getClassMetadata')->will($this->returnValue($meta));
     $meta->expects($this->any())->method('getSingleIdentifierFieldName')->will($this->returnValue('id'));
     $reflectionProperty->expects($this->any())->method('getValue')->will($this->returnValue(1));
     $uow = $this->getMockBuilder('Doctrine\\ORM\\UnitOfWork')->disableOriginalConstructor()->getMock();
     $this->om->expects($this->any())->method('getUnitOfWork')->will($this->returnValue($uow));
     $uow->expects($this->any())->method('computeFields');
     $this->orm->save($this->product, true, true);
     $this->orm->save($this->product, false);
     $this->mapper->expects($this->once())->method('getEntityConfig')->will($this->returnValue(array('alias' => 'test')));
     $manufacturer = new Manufacturer();
     $manufacturer->setName('reebok');
     $manufacturer->addProduct($this->product);
     $this->orm->save($manufacturer, true);
 }