protected function setUp() { if (!interface_exists('Doctrine\\Common\\Persistence\\ObjectManager')) { $this->markTestSkipped('Doctrine Common has to be installed for this test to run.'); } $this->om = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager'); $this->repository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository'); $this->om->expects($this->any())->method('getRepository')->with($this->equalTo('OroTestBundle:test'))->will($this->returnValue($this->repository)); $this->product = new Product(); $this->product->setName('test product'); $this->repository->expects($this->any())->method('find')->will($this->returnValue($this->product)); $items[] = new Item($this->om, 'OroTestBundle:test', 1, 'test title', 'http://example.com', 'test text', array('alias' => 'test_product', 'label' => 'test product', 'fields' => array(array('name' => 'name', 'target_type' => 'text')))); $items[] = new Item($this->om, 'OroTestBundle:test', 2, 'test title 2', 'http://example.com', 'test text', array('alias' => 'test_product', 'label' => 'test product', 'fields' => array(array('name' => 'name', 'target_type' => 'text')))); $items[] = new Item($this->om, 'OroTestBundle:test', 3, 'test title 3', 'http://example.com', 'test text', array('alias' => 'test_product', 'label' => 'test product', 'fields' => array(array('name' => 'name', 'target_type' => 'text')))); $query = new Query(); $query->createQuery(Query::SELECT)->from(array('OroTestBundle:test', 'OroTestBundle:product'))->andWhere('name', Query::OPERATOR_CONTAINS, 'test string', Query::TYPE_TEXT); $this->result = new Result($query, $items, 3); $this->result1 = new Result($query, array(), 0); }
public function testDoSearch() { $query = new Query(); $query->createQuery(Query::SELECT)->from('test')->andWhere('name', '~', 'test value', Query::TYPE_TEXT); $searchRepo = $this->getMockBuilder('Oro\\Bundle\\SearchBundle\\Entity\\Repository\\SearchIndexRepository')->disableOriginalConstructor()->getMock(); $this->om->expects($this->once())->method('getRepository')->with($this->equalTo('OroSearchBundle:Item'))->will($this->returnValue($searchRepo)); $this->om->expects($this->once())->method('persist'); $this->om->expects($this->once())->method('flush'); $this->container->expects($this->once())->method('getParameter')->with($this->equalTo('oro_search.engine_orm'))->will($this->returnValue('test_orm')); $searchRepo->expects($this->once())->method('setDriversClasses'); $result = $this->orm->search($query); $this->assertEquals(0, $result->getRecordsCount()); $searchOptions = $result->getQuery()->getOptions(); $this->assertEquals('name', $searchOptions[0]['fieldName']); $this->assertEquals(Query::OPERATOR_CONTAINS, $searchOptions[0]['condition']); $this->assertEquals('test value', $searchOptions[0]['fieldValue']); $this->assertEquals(Query::TYPE_TEXT, $searchOptions[0]['fieldType']); $this->assertEquals(Query::KEYWORD_AND, $searchOptions[0]['type']); }