From f53513c32ffd4d47783294423dfc92a8870d69c6 Mon Sep 17 00:00:00 2001 From: Andrius Bil <andrius.bilinevicius@nfq.lt> Date: Wed, 4 Mar 2015 10:51:20 +0200 Subject: [PATCH] Tests for Completion setters/getters and Completion::toArray exception --- Suggester/CompletionTest.php | 64 +++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/Suggester/CompletionTest.php b/Suggester/CompletionTest.php index cbe6e4d..be16697 100644 --- a/Suggester/CompletionTest.php +++ b/Suggester/CompletionTest.php @@ -12,8 +12,16 @@ namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Suggester; use ONGR\ElasticsearchBundle\DSL\Suggester\Completion; +use ONGR\ElasticsearchBundle\Tests\app\fixture\AbstractEntityTest; -class CompletionTest extends \PHPUnit_Framework_TestCase +/** + * Test for Completion. + * + * Class CompletionTest + * + * @package ONGR\ElasticsearchBundle\Tests\Unit\DSL\Suggester + */ +class CompletionTest extends AbstractEntityTest { /** * @return array @@ -90,12 +98,60 @@ class CompletionTest extends \PHPUnit_Framework_TestCase * Tests toArray method. * * @param array $expected - * @param Completion $phrase + * @param Completion $completion * * @dataProvider getTestToArrayData */ - public function testToArray($expected, $phrase) + public function testToArray($expected, $completion) + { + $this->assertEquals($expected, $completion->toArray()); + } + + /** + * Tests if toArray method throws Logic Exception. + * + * @expectedException \LogicException + */ + public function testToArrayException() + { + $completion = new Completion('foo', 'bar'); + $completion->setField(null); + $completion->setText(null); + $completion->toArray(); + } + + /** + * Tests useFuzzy property. + */ + public function testUseFuzzy() { - $this->assertEquals($expected, $phrase->toArray()); + $completion = new Completion('foo', 'bar'); + $completion->useFuzzy(true); + $this->assertEquals(true, $completion->isFuzzy()); + } + + /** + * @return string + */ + public function getClassName() + { + $this->setStub(new Completion('foo', 'bar')); + $this->addIgnoredField('useFuzzy'); + + return 'ONGR\ElasticsearchBundle\DSL\Suggester\Completion'; + } + + /** + * @return array + */ + public function getFieldsData() + { + return [ + ['fuzziness'], + ['transpositions', 'boolean'], + ['minLength'], + ['prefixLength'], + ['unicodeAware'], + ]; } } -- GitLab