示例#1
0
 /**
  * @covers SphinxSearch\Indexer::delete
  * @covers SphinxSearch\Indexer::deleteWith
  */
 public function testDelete()
 {
     $mockDelete = $this->mockSql->delete('foo');
     $mockDelete->expects($this->once())->method('where')->with($this->equalTo('id = 2'));
     $affectedRows = $this->indexer->delete('foo', 'id = 2');
     $this->assertEquals(5, $affectedRows);
     // Where with closure
     $mockDelete = $this->mockSql->delete('foo');
     $this->indexer->delete('foo', function ($delete) use($mockDelete) {
         IndexerTest::assertSame($mockDelete, $delete);
     });
 }
 /**
  * @covers  SphinxSearch\AbstractComponent::executeSqlObject
  * @depends testExecuteSqlObject
  */
 public function testExecuteSqlObjectWithSecondArg()
 {
     $sqlObj = new Select('foo');
     $this->component->setQueryMode(AbstractComponent::QUERY_MODE_EXECUTE);
     $this->mockSql->expects($this->at(0))->method('prepareStatementForSqlObject')->with($this->equalTo($sqlObj));
     $result = $this->component->executeSqlObject($sqlObj, true);
     //force prepared, ignoring query mode
     $this->assertInstanceOf('\\Zend\\Db\\Adapter\\Driver\\ResultInterface', $result);
     $this->component->setQueryMode(AbstractComponent::QUERY_MODE_PREPARED);
     $this->mockSql->expects($this->at(0))->method('getSqlStringForSqlObject')->with($this->equalTo($sqlObj));
     $this->mockConnection->expects($this->at(0))->method('execute')->with($this->equalTo('SQL STRING'));
     $result = $this->component->executeSqlObject($sqlObj, false);
     //force execute, ignoring query mode
     $this->assertInstanceOf('\\Zend\\Db\\Adapter\\Driver\\ResultInterface', $result);
 }
示例#3
0
 /**
  * @covers SphinxSearch\Search::showStatus
  * @covers SphinxSearch\Search::show
  */
 public function testShowStatus()
 {
     $mockShow = $this->mockSql->show();
     $mockShow->expects($this->once())->method('show')->with($this->equalTo(Show::SHOW_STATUS));
     $mockShow->expects($this->once())->method('like')->with($this->equalTo('up%'));
     // Assumes prepared statement
     $this->mockResult->expects($this->at(0))->method('rewind')->will($this->returnValue(true));
     $this->mockResult->expects($this->at(1))->method('valid')->will($this->returnValue(true));
     $this->mockResult->expects($this->at(2))->method('current')->will($this->returnValue(['Counter' => 'uptime', 'Value' => '1392']));
     $this->mockResult->expects($this->at(3))->method('next');
     $this->mockResult->expects($this->at(4))->method('valid')->will($this->returnValue(false));
     $result = $this->search->showStatus('up%');
     $this->assertInternalType('array', $result);
     $this->assertCount(1, $result);
     $this->assertArrayHasKey('uptime', $result);
     $this->assertEquals('1392', $result['uptime']);
 }
示例#4
0
 /**
  * @covers SphinxSearch\Db\Sql\Sql::show
  */
 public function testShow()
 {
     $show = $this->sql->show();
     $this->assertInstanceOf('\\SphinxSearch\\Db\\Sql\\Show', $show);
 }
 public function testDocUseCase1()
 {
     $adapter = $this->adapter;
     $adapter->query('TRUNCATE RTINDEX foo', $adapter::QUERY_MODE_EXECUTE);
     $indexer = new Indexer($adapter);
     $indexer->insert('foo', ['id' => 11, 'short' => 'hello world', 'text' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', 'c1' => 10, 'c2' => 100, 'c3' => 1000, 'f1' => pi()], true);
     $search = new Search($adapter);
     $rowset = $search->search('foo', new Match('ipsum dolor'));
     $current = $rowset->current();
     $this->assertEquals(11, $current['id']);
     $search = new Search($adapter);
     $rowset = $search->search('foo', function (Select $select) {
         $select->where(new Match('ipsum dolor'))->where(['c1 > ?' => 5])->limit(1);
     });
     $this->assertEquals(1, $rowset->count());
     $current = $rowset->current();
     $this->assertEquals(11, $current['id']);
     $expr = new QueryExpression('? ?', ['ipsum', 'dolor']);
     /** @var $select Select */
     $select = new Select('foo');
     $select->where(new Match($expr));
     $sql = new Sql($adapter);
     $query = $sql->getSqlStringForSqlObject($select);
     $results = $adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
     $current = $results->current();
     $this->assertEquals(11, $current['id']);
     $adapter->query('TRUNCATE RTINDEX foo', $adapter::QUERY_MODE_EXECUTE);
 }