diff options
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Suggest/TermTest.php')
-rw-r--r-- | vendor/ruflin/elastica/test/lib/Elastica/Test/Suggest/TermTest.php | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Suggest/TermTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Suggest/TermTest.php index 7765f1bb..f1250e6f 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Suggest/TermTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Suggest/TermTest.php @@ -1,44 +1,37 @@ <?php - namespace Elastica\Test\Suggest; +use Elastica\Document; +use Elastica\Index; use Elastica\Suggest; use Elastica\Suggest\Term; use Elastica\Test\Base as BaseTest; -use Elastica\Query; -use Elastica\Document; -use Elastica\Index; class TermTest extends BaseTest { - const TEST_TYPE = 'testSuggestType'; - /** - * @var Index + * @return Index */ - protected $_index; - - protected function setUp() + protected function _getIndexForTest() { - parent::setUp(); - $this->_index = $this->_createIndex('test_suggest'); - $docs = array(); - $docs[] = new Document(1, array('id' => 1, 'text' => 'GitHub')); - $docs[] = new Document(2, array('id' => 1, 'text' => 'Elastic')); - $docs[] = new Document(3, array('id' => 1, 'text' => 'Search')); - $docs[] = new Document(4, array('id' => 1, 'text' => 'Food')); - $docs[] = new Document(5, array('id' => 1, 'text' => 'Flood')); - $docs[] = new Document(6, array('id' => 1, 'text' => 'Folks')); - $type = $this->_index->getType(self::TEST_TYPE); - $type->addDocuments($docs); - $this->_index->refresh(); - } - - protected function tearDown() - { - $this->_index->delete(); + $index = $this->_createIndex(); + $type = $index->getType('testSuggestType'); + $type->addDocuments(array( + new Document(1, array('id' => 1, 'text' => 'GitHub')), + new Document(2, array('id' => 1, 'text' => 'Elastic')), + new Document(3, array('id' => 1, 'text' => 'Search')), + new Document(4, array('id' => 1, 'text' => 'Food')), + new Document(5, array('id' => 1, 'text' => 'Flood')), + new Document(6, array('id' => 1, 'text' => 'Folks')), + )); + $index->refresh(); + + return $index; } + /** + * @group unit + */ public function testToArray() { $suggest = new Suggest(); @@ -51,22 +44,25 @@ class TermTest extends BaseTest 'suggest' => array( 'suggest1' => array( 'term' => array( - 'field' => '_all' + 'field' => '_all', ), - 'text' => 'Foor' + 'text' => 'Foor', ), 'suggest2' => array( 'term' => array( - 'field' => '_all' + 'field' => '_all', ), - 'text' => 'Girhub' - ) - ) + 'text' => 'Girhub', + ), + ), ); $this->assertEquals($expected, $suggest->toArray()); } + /** + * @group functional + */ public function testSuggestResults() { $suggest = new Suggest(); @@ -75,7 +71,8 @@ class TermTest extends BaseTest $suggest2 = new Term('suggest2', '_all'); $suggest->addSuggestion($suggest2->setText('Girhub')); - $result = $this->_index->search($suggest); + $index = $this->_getIndexForTest(); + $result = $index->search($suggest); $this->assertEquals(2, $result->countSuggests()); @@ -88,12 +85,16 @@ class TermTest extends BaseTest $this->assertEquals('food', $suggests['suggest1'][0]['options'][0]['text']); } + /** + * @group functional + */ public function testSuggestNoResults() { $termSuggest = new Term('suggest1', '_all'); $termSuggest->setText('Foobar')->setSize(4); - $result = $this->_index->search($termSuggest); + $index = $this->_getIndexForTest(); + $result = $index->search($termSuggest); $this->assertEquals(1, $result->countSuggests()); |