diff --git a/src/Suggest/Suggest.php b/src/Suggest/Suggest.php index bd2e55f35c84bc8bf1b4ecd02d6178d7831c0031..f7951308806db011a8ccfa81dd723561303c56d7 100644 --- a/src/Suggest/Suggest.php +++ b/src/Suggest/Suggest.php @@ -19,11 +19,6 @@ class Suggest implements BuilderInterface { use ParametersTrait; - const TERM = 'term'; - const COMPLETION = 'completion'; - const PHRASE = 'phrase'; - const CONTEXT = 'completion'; - /** * @var string */ @@ -37,31 +32,48 @@ class Suggest implements BuilderInterface /** * @var string */ - private $field; + private $text; /** * @var string */ - private $text; + private $field; /** * TermSuggest constructor. * @param string $name - * @param string $field * @param string $type * @param string $text + * @param string $field * @param array $parameters */ - public function __construct($name, $field, $type, $text, $parameters = []) + public function __construct($name, $type, $text, $field, $parameters = []) { $this->setName($name); - $this->validateType($type); - $this->setField($field); $this->setType($type); $this->setText($text); + $this->setField($field); $this->setParameters($parameters); } + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Returns suggest name + * + * @return string + */ + public function getName() + { + return $this->name; + } + /** * Returns element type. * @@ -112,48 +124,6 @@ class Suggest implements BuilderInterface $this->field = $field; } - /** - * @param string $name - */ - public function setName($name) - { - $this->name = $name; - } - - /** - * Returns suggest name - * - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Checks if the type is valid - * - * @param string $type - * - * @return bool - * - * @throws InvalidArgumentException - */ - private function validateType($type) - { - if (in_array($type, [ - self::COMPLETION, - self::CONTEXT, - self::PHRASE, - self::TERM - ])) { - return true; - } - throw new InvalidArgumentException( - 'You must provide a valid type to the Suggest()' - ); - } - /** * {@inheritdoc} */ diff --git a/tests/Suggest/SuggestTest.php b/tests/Suggest/SuggestTest.php index 7e0e102fcdf2968b4c6d2c4af6ffe1a89254e6e7..e7482239291ff61c3dba180adfae19dca8d73261 100644 --- a/tests/Suggest/SuggestTest.php +++ b/tests/Suggest/SuggestTest.php @@ -20,7 +20,7 @@ class SuggestTest extends \PHPUnit_Framework_TestCase */ public function testSuggestGetType() { - $suggest = new Suggest('foo', 'bar', Suggest::TERM, 'acme'); + $suggest = new Suggest('foo', 'term', 'acme', 'bar'); $this->assertEquals('term', $suggest->getType()); } @@ -35,56 +35,53 @@ class SuggestTest extends \PHPUnit_Framework_TestCase [ 'suggest' => new Suggest( 'foo', - 'acme', - Suggest::PHRASE, + 'term', 'bar', - ['max_errors' => 0.5] + 'acme', + ['size' => 5] ), 'expected' => [ 'foo' => [ 'text' => 'bar', - 'phrase' => [ + 'term' => [ 'field' => 'acme', - 'max_errors' => 0.5, - ], + 'size' => 5 + ] ] ] ], [ 'suggest' => new Suggest( 'foo', - 'acme', - Suggest::CONTEXT, + 'phrase', 'bar', - ['context' => ['color' => 'red'], 'size' => 3] + 'acme', + ['max_errors' => 0.5] ), 'expected' => [ 'foo' => [ 'text' => 'bar', - 'completion' => [ + 'phrase' => [ 'field' => 'acme', - 'size' => 3, - 'context' => [ - 'color' => 'red' - ] - ] + 'max_errors' => 0.5, + ], ] ] ], [ 'suggest' => new Suggest( 'foo', - 'acme', - Suggest::TERM, + 'completion', 'bar', - ['size' => 5] + 'acme', + ['fuzziness' => 2] ), 'expected' => [ 'foo' => [ 'text' => 'bar', - 'term' => [ + 'completion' => [ 'field' => 'acme', - 'size' => 5 + 'fuzziness' => 2 ] ] ] @@ -92,15 +89,20 @@ class SuggestTest extends \PHPUnit_Framework_TestCase [ 'suggest' => new Suggest( 'foo', + 'completion', + 'bar', 'acme', - Suggest::COMPLETION, - 'bar' + ['context' => ['color' => 'red'], 'size' => 3] ), 'expected' => [ 'foo' => [ 'text' => 'bar', 'completion' => [ - 'field' => 'acme' + 'field' => 'acme', + 'size' => 3, + 'context' => [ + 'color' => 'red' + ] ] ] ] @@ -118,14 +120,4 @@ class SuggestTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($expected, $suggest->toArray()); } - - /** - * Tests exception that is thrown when wrong type is provided - * - * @expectedException \InvalidArgumentException - */ - public function testValidateTypeException() - { - new Suggest('foo', 'bar', 'wrong-type', 'acme'); - } }