diff --git a/Suggester/CompletionTest.php b/Suggester/CompletionTest.php index 1fc76119b20c7b5f12a9b16ae513d59c9b0db91d..973d8e0b468b91e94873b450d480580fcc607b9c 100644 --- a/Suggester/CompletionTest.php +++ b/Suggester/CompletionTest.php @@ -14,13 +14,6 @@ namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Suggester; use ONGR\ElasticsearchBundle\DSL\Suggester\Completion; use ONGR\ElasticsearchBundle\Test\EncapsulationTestAwareTrait; -/** - * Test for Completion. - * - * Class CompletionTest - * - * @package ONGR\ElasticsearchBundle\Tests\Unit\DSL\Suggester - */ class CompletionTest extends \PHPUnit_Framework_TestCase { use EncapsulationTestAwareTrait; @@ -149,6 +142,7 @@ class CompletionTest extends \PHPUnit_Framework_TestCase public function getFieldsData() { return [ + ['name'], ['fuzziness'], ['transpositions', 'boolean'], ['minLength'], diff --git a/Suggester/Context/CategoryContextTest.php b/Suggester/Context/CategoryContextTest.php new file mode 100644 index 0000000000000000000000000000000000000000..e5567cd2ed04c45fa63efc80cce8090fa88cfd9b --- /dev/null +++ b/Suggester/Context/CategoryContextTest.php @@ -0,0 +1,41 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Suggester\Context; + +use ONGR\ElasticsearchBundle\DSL\Suggester\Context\CategoryContext; +use ONGR\ElasticsearchBundle\Test\EncapsulationTestAwareTrait; + +class CategoryContextTest extends \PHPUnit_Framework_TestCase +{ + use EncapsulationTestAwareTrait; + + /** + * @return string + */ + public function getClassName() + { + $this->setStub(new CategoryContext('foo', 'bar')); + + return 'ONGR\ElasticsearchBundle\DSL\Suggester\Context\CategoryContext'; + } + + /** + * @return array + */ + public function getFieldsData() + { + return [ + ['name'], + ['value'], + ]; + } +} diff --git a/Suggester/Context/GeoContextTest.php b/Suggester/Context/GeoContextTest.php new file mode 100644 index 0000000000000000000000000000000000000000..8a8a918319237cdf5de24ee9b7021999da9699af --- /dev/null +++ b/Suggester/Context/GeoContextTest.php @@ -0,0 +1,43 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Suggester\Context; + +use ONGR\ElasticsearchBundle\DSL\Suggester\Context\CategoryContext; +use ONGR\ElasticsearchBundle\DSL\Suggester\Context\GeoContext; +use ONGR\ElasticsearchBundle\Test\EncapsulationTestAwareTrait; + +class GeoContextTest extends \PHPUnit_Framework_TestCase +{ + use EncapsulationTestAwareTrait; + + /** + * @return string + */ + public function getClassName() + { + $this->setStub(new GeoContext('foo', 'bar')); + + return 'ONGR\ElasticsearchBundle\DSL\Suggester\Context\GeoContext'; + } + + /** + * @return array + */ + public function getFieldsData() + { + return [ + ['precision'], + ['name'], + ['value'], + ]; + } +} diff --git a/Suggester/ContextTest.php b/Suggester/ContextTest.php index 1b53eb37654b52d8a65fb5fad9b411655cf0288c..601ac2df1e9c3e43ea5592316606570510101dfc 100644 --- a/Suggester/ContextTest.php +++ b/Suggester/ContextTest.php @@ -14,9 +14,12 @@ namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Suggester; use ONGR\ElasticsearchBundle\DSL\Suggester\Completion; use ONGR\ElasticsearchBundle\DSL\Suggester\Context; use ONGR\ElasticsearchBundle\DSL\Suggester\Phrase; +use ONGR\ElasticsearchBundle\Test\EncapsulationTestAwareTrait; class ContextTest extends \PHPUnit_Framework_TestCase { + use EncapsulationTestAwareTrait; + /** * Tests toArray method when $this->getSize() !== null. */ @@ -40,4 +43,29 @@ class ContextTest extends \PHPUnit_Framework_TestCase $this->assertEquals($completion['size'], 123); } + + /** + * Returns list of fields to test. Works as data provider. + * + * @return array + */ + public function getFieldsData() + { + return [ + ['context'], + ['size'], + ]; + } + + /** + * Returns entity class name. + * + * @return string + */ + public function getClassName() + { + $this->setStub(new Context('foo', 'bar')); + + return 'ONGR\ElasticsearchBundle\DSL\Suggester\Context'; + } } diff --git a/Suggester/PhraseTest.php b/Suggester/PhraseTest.php index eb6380584ebf668d15ea5524eeb44ddbe9efafce..623f7a09abdd9dfc29d423c7a3f1e82b625b1a89 100644 --- a/Suggester/PhraseTest.php +++ b/Suggester/PhraseTest.php @@ -12,9 +12,12 @@ namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Suggester; use ONGR\ElasticsearchBundle\DSL\Suggester\Phrase; +use ONGR\ElasticsearchBundle\Test\EncapsulationTestAwareTrait; class PhraseTest extends \PHPUnit_Framework_TestCase { + use EncapsulationTestAwareTrait; + /** * @return array */ @@ -95,5 +98,36 @@ class PhraseTest extends \PHPUnit_Framework_TestCase { $phrase = new Phrase('', ''); $phrase->toArray(); + + $this->getFieldsData(); + } + + /** + * @return string + */ + public function getClassName() + { + $this->setStub(new Phrase('foo', 'bar')); + + + return 'ONGR\ElasticsearchBundle\DSL\Suggester\Phrase'; + } + + /** + * Returns list of fields to test. Works as data provider. + * + * @return array + */ + public function getFieldsData() + { + return [ + ['analyzer'], + ['gramSize'], + ['realWordErrorLikelihood'], + ['confidence'], + ['maxErrors'], + ['highlight'], + ['size'], + ]; } -} +} \ No newline at end of file diff --git a/Suggester/TermTest.php b/Suggester/TermTest.php index 74b6e2387f2b50aa51ead4b20021526110cd5a87..c0ec281975d0ddaf6d1b73ad6b55ac4c1086c3de 100644 --- a/Suggester/TermTest.php +++ b/Suggester/TermTest.php @@ -12,9 +12,12 @@ namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Suggester; use ONGR\ElasticsearchBundle\DSL\Suggester\Term; +use ONGR\ElasticsearchBundle\Test\EncapsulationTestAwareTrait; class TermTest extends \PHPUnit_Framework_TestCase { + use EncapsulationTestAwareTrait; + /** * @return array */ @@ -87,4 +90,67 @@ class TermTest extends \PHPUnit_Framework_TestCase $term = new Term('', ''); $term->toArray(); } + + /** + * Tests setSort method. + */ + public function testSetSort() + { + $term = new Term('foo', 'bar'); + + $term->setSort(Term::SORT_BY_FREQ); + $this->assertEquals(Term::SORT_BY_FREQ, $term->getSort()); + + $term->setSort(Term::SORT_BY_SCORE); + $this->assertEquals(Term::SORT_BY_SCORE, $term->getSort()); + + $initValue = $term->getSort(); + $term->setSort('wrongSort'); + $this->assertEquals($initValue, $term->getSort()); + } + + /** + * Tests setSuggestMode method. + */ + public function testSetSuggestMode() + { + $term = new Term('foo', 'bar'); + + $term->setSuggestMode(Term::SUGGEST_MODE_ALWAYS); + $this->assertEquals(Term::SUGGEST_MODE_ALWAYS, $term->getSuggestMode()); + + $term->setSuggestMode(Term::SUGGEST_MODE_MISSING); + $this->assertEquals(Term::SUGGEST_MODE_MISSING, $term->getSuggestMode()); + + $initValue = $term->getSuggestMode(); + $term->setSuggestMode('wrongMode'); + $this->assertEquals($initValue, $term->getSuggestMode()); + } + + /** + * Returns list of fields to test. Works as data provider. + * + * @return array + */ + public function getFieldsData() + { + return [ + ['analyzer'], + ['size'], + ]; + } + + /** + * Returns entity class name. + * + * @return string + */ + public function getClassName() + { + $this->setStub(new Term('foo', 'bar')); + $this->addIgnoredField('sort'); + $this->addIgnoredField('suggestMode'); + + return 'ONGR\ElasticsearchBundle\DSL\Suggester\Term'; + } }