コード例 #1
0
ファイル: SearchTest.php プロジェクト: ripaclub/sphinxsearch
 public function setUp()
 {
     // mock the adapter, driver, and parts
     $this->mockResult = $this->getMock('\\Zend\\Db\\Adapter\\Driver\\ResultInterface');
     $mockStatement = $this->getMock('\\Zend\\Db\\Adapter\\Driver\\StatementInterface');
     $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($this->mockResult));
     $mockConnection = $this->getMock('\\Zend\\Db\\Adapter\\Driver\\ConnectionInterface');
     $mockConnection->expects($this->any())->method('execute')->will($this->returnValue($this->mockResult));
     $mockDriver = $this->getMock('\\Zend\\Db\\Adapter\\Driver\\DriverInterface');
     $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));
     $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection));
     // setup mock adapter
     $this->mockAdapter = $this->getMock('\\Zend\\Db\\Adapter\\Adapter', null, [$mockDriver, new TrustedSphinxQL()]);
     $this->mockSql = $this->getMock('\\SphinxSearch\\Db\\Sql\\Sql', ['select', 'show'], [$this->mockAdapter, 'foo']);
     $this->mockSql->expects($this->any())->method('select')->will($this->returnValue($this->getMock('\\SphinxSearch\\Db\\Sql\\Select', ['where', 'getRawSate'], ['foo'])));
     $mockShow = $this->getMock('\\SphinxSearch\\Db\\Sql\\Show');
     $mockShow->expects($this->any())->method('show')->will($this->returnSelf());
     $mockShow->expects($this->any())->method('like')->will($this->returnSelf());
     $this->mockSql->expects($this->any())->method('show')->will($this->returnValue($mockShow));
     // setup the search object
     $this->search = new Search($this->mockAdapter, null, $this->mockSql);
 }
コード例 #2
0
ファイル: IndexerTest.php プロジェクト: ripaclub/sphinxsearch
 public function setUp()
 {
     // Mock the adapter, driver, and parts
     $mockResult = $this->getMock('\\Zend\\Db\\Adapter\\Driver\\ResultInterface');
     $mockResult->expects($this->any())->method('getAffectedRows')->will($this->returnValue(5));
     $mockStatement = $this->getMock('\\Zend\\Db\\Adapter\\Driver\\StatementInterface');
     $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult));
     $mockConnection = $this->getMock('\\Zend\\Db\\Adapter\\Driver\\ConnectionInterface');
     $mockConnection->expects($this->any())->method('beginTransaction');
     $mockConnection->expects($this->any())->method('commit');
     $mockConnection->expects($this->any())->method('rollback');
     $mockDriver = $this->getMock('\\Zend\\Db\\Adapter\\Driver\\DriverInterface');
     $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));
     $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection));
     // Setup mock adapter
     $this->mockAdapter = $this->getMock('\\Zend\\Db\\Adapter\\Adapter', null, [$mockDriver, new TrustedSphinxQL()]);
     $this->mockSql = $this->getMock('\\SphinxSearch\\Db\\Sql\\Sql', ['insert', 'replace', 'update', 'delete'], [$this->mockAdapter]);
     $this->mockSql->expects($this->any())->method('insert')->will($this->returnValue($this->getMock('\\Zend\\Db\\Sql\\Insert', ['prepareStatement', 'values'])))->with($this->equalTo('foo'));
     $this->mockSql->expects($this->any())->method('replace')->will($this->returnValue($this->getMock('\\SphinxSearch\\Db\\Sql\\Replace', ['prepareStatement', 'values'])))->with($this->equalTo('foo'));
     $this->mockSql->expects($this->any())->method('update')->will($this->returnValue($this->getMock('\\SphinxSearch\\Db\\Sql\\Update', ['where'])))->with($this->equalTo('foo'));
     $this->mockSql->expects($this->any())->method('delete')->will($this->returnValue($this->getMock('\\Zend\\Db\\Sql\\Delete', ['where'])))->with($this->equalTo('foo'));
     // Setup the indexer object
     $this->indexer = new Indexer($this->mockAdapter, $this->mockSql);
 }
コード例 #3
0
 /**
  * @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);
 }