From 87ea292764c82475f8104ce108dc910310afb5f6 Mon Sep 17 00:00:00 2001 From: Vagrant User <vagrant@ongr.dev> Date: Fri, 6 Mar 2015 09:52:39 +0000 Subject: [PATCH] Few tests --- Suggester/CompletionTest.php | 11 +++++++++ Suggester/ContextTest.php | 43 ++++++++++++++++++++++++++++++++++++ Suggester/PhraseTest.php | 11 +++++++++ Suggester/TermTest.php | 11 +++++++++ 4 files changed, 76 insertions(+) create mode 100644 Suggester/ContextTest.php diff --git a/Suggester/CompletionTest.php b/Suggester/CompletionTest.php index cbe6e4d..b84c1b7 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 0000000..7a87a97 --- /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 eac16ae..eb63805 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 4851cde..74b6e23 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(); + } } -- GitLab