2018-02-15 19:19:53 +03:00
|
|
|
<?php
|
2018-09-02 13:44:21 +03:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-02-15 19:19:53 +03:00
|
|
|
namespace GraphQL\Tests\Utils;
|
|
|
|
|
|
|
|
use GraphQL\Utils\Utils;
|
2018-07-29 18:43:10 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2018-02-15 19:19:53 +03:00
|
|
|
|
2018-07-29 18:43:10 +03:00
|
|
|
class SuggestionListTest extends TestCase
|
2018-02-15 19:19:53 +03:00
|
|
|
{
|
|
|
|
// DESCRIBE: suggestionList
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('Returns results when input is empty')
|
2018-02-15 19:19:53 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testResturnsResultsWhenInputIsEmpty() : void
|
2018-02-15 19:19:53 +03:00
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
Utils::suggestionList('', ['a']),
|
|
|
|
['a']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('Returns empty array when there are no options')
|
2018-02-15 19:19:53 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testReturnsEmptyArrayWhenThereAreNoOptions() : void
|
2018-02-15 19:19:53 +03:00
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
Utils::suggestionList('input', []),
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('Returns options sorted based on similarity')
|
2018-02-15 19:19:53 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testReturnsOptionsSortedBasedOnSimilarity() : void
|
2018-02-15 19:19:53 +03:00
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
Utils::suggestionList('abc', ['a', 'ab', 'abc']),
|
|
|
|
['abc', 'ab']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|