_plugin = new Solarium_Plugin_PrefetchIterator(); $this->_client = new Solarium_Client(); $this->_query = $this->_client->createSelect(); } public function testSetAndGetPrefetch() { $this->_plugin->setPrefetch(120); $this->assertEquals(120, $this->_plugin->getPrefetch()); } public function testSetAndGetQuery() { $this->_plugin->setQuery($this->_query); $this->assertEquals($this->_query, $this->_plugin->getQuery()); } public function testCount() { $result = $this->_getResult(); $mockClient = $this->getMock('Solarium_Client', array('execute')); $mockClient->expects($this->exactly(1))->method('execute')->will($this->returnValue($result)); $this->_plugin->init($mockClient, array()); $this->_plugin->setQuery($this->_query); $this->assertEquals(5, count($this->_plugin)); } public function testIteratorAndRewind() { $result = $this->_getResult(); $mockClient = $this->getMock('Solarium_Client', array('execute')); $mockClient->expects($this->exactly(1))->method('execute')->will($this->returnValue($result)); $this->_plugin->init($mockClient, array()); $this->_plugin->setQuery($this->_query); $results1 = array(); foreach($this->_plugin as $doc) { $results1[] = $doc; } // the second foreach will trigger a rewind, this time include keys $results2 = array(); foreach($this->_plugin as $key => $doc) { $results2[$key] = $doc; } $this->assertEquals($result->getDocuments(), $results1); $this->assertEquals($result->getDocuments(), $results2); } public function _getResult() { $numFound = 5; $docs = array( new Solarium_Document_ReadOnly(array('id'=>1,'title'=>'doc1')), new Solarium_Document_ReadOnly(array('id'=>2,'title'=>'doc2')), new Solarium_Document_ReadOnly(array('id'=>3,'title'=>'doc3')), new Solarium_Document_ReadOnly(array('id'=>4,'title'=>'doc4')), new Solarium_Document_ReadOnly(array('id'=>5,'title'=>'doc5')), ); return new Solarium_Result_SelectDummy(1, 12, $numFound, $docs, array()); } }