diff --git a/Suggester/CompletionTest.php b/Suggester/CompletionTest.php index cbe6e4d66a44193a9627d09bbff1b3c35ed8f506..b84c1b78c371542d278bbcf8248685f14b4ee79b 100644 --- a/Suggester/CompletionTest.php +++ b/Suggester/CompletionTest.php @@ -98,4 +98,15 @@ class CompletionTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($expected, $phrase->toArray()); } + + /** + * Tests toArray method exception. + * + * @expectedException \LogicException + */ + public function testToArrayException() + { + $completion = new Completion('', ''); + $completion->toArray(); + } } diff --git a/Suggester/ContextTest.php b/Suggester/ContextTest.php new file mode 100644 index 0000000000000000000000000000000000000000..7a87a97c35aed090a9bb1e9783bd0ed0010f1125 --- /dev/null +++ b/Suggester/ContextTest.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; + +use ONGR\ElasticsearchBundle\DSL\Suggester\Completion; +use ONGR\ElasticsearchBundle\DSL\Suggester\Context; +use ONGR\ElasticsearchBundle\DSL\Suggester\Phrase; + +class ContextTest extends \PHPUnit_Framework_TestCase +{ + /** + * Tests toArray method when $this->getSize() !== null. + */ + public function testToArrayNotNull() + { + $name = 'testName'; + + $context = new Context('', '', $name); + $context->setSize(123); + $context->setContext(new Phrase('', '', 'test')); + + $result = $context->toArray(); + + $this->assertArrayHasKey($name, $result); + + $data = $result[$name]; + $this->assertArrayHasKey('completion', $data); + + $completion = $data['completion']; + $this->assertArrayHasKey('size', $completion); + + $this->assertEquals($completion['size'], 123); + } +} diff --git a/Suggester/PhraseTest.php b/Suggester/PhraseTest.php index eac16ae48df93220779ece32562eb33ecc8b681b..eb6380584ebf668d15ea5524eeb44ddbe9efafce 100644 --- a/Suggester/PhraseTest.php +++ b/Suggester/PhraseTest.php @@ -85,4 +85,15 @@ class PhraseTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($expected, $phrase->toArray()); } + + /** + * Tests toArray method exception. + * + * @expectedException \LogicException + */ + public function testToArrayException() + { + $phrase = new Phrase('', ''); + $phrase->toArray(); + } } diff --git a/Suggester/TermTest.php b/Suggester/TermTest.php index 4851cde1b64a1652debce303d81701cf9c734806..74b6e2387f2b50aa51ead4b20021526110cd5a87 100644 --- a/Suggester/TermTest.php +++ b/Suggester/TermTest.php @@ -76,4 +76,15 @@ class TermTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($expected, $suggester->toArray()); } + + /** + * Tests toArray method exception. + * + * @expectedException \LogicException + */ + public function testToArrayException() + { + $term = new Term('', ''); + $term->toArray(); + } }