diff options
Diffstat (limited to 'tests/app/Models/SearchTest.php')
| -rw-r--r-- | tests/app/Models/SearchTest.php | 77 |
1 files changed, 35 insertions, 42 deletions
diff --git a/tests/app/Models/SearchTest.php b/tests/app/Models/SearchTest.php index e01830314..27943cdb2 100644 --- a/tests/app/Models/SearchTest.php +++ b/tests/app/Models/SearchTest.php @@ -1,13 +1,14 @@ <?php declare(strict_types=1); + +use PHPUnit\Framework\Attributes\DataProvider; + require_once(LIB_PATH . '/lib_date.php'); class SearchTest extends PHPUnit\Framework\TestCase { - /** - * @dataProvider provideEmptyInput - */ - public function test__construct_whenInputIsEmpty_getsOnlyNullValues(string $input): void { + #[DataProvider('provideEmptyInput')] + public static function test__construct_whenInputIsEmpty_getsOnlyNullValues(string $input): void { $search = new FreshRSS_Search($input); self::assertEquals('', $search->getRawInput()); self::assertNull($search->getIntitle()); @@ -25,7 +26,7 @@ class SearchTest extends PHPUnit\Framework\TestCase { * Here is the description of the values * @return array{array{''},array{' '}} */ - public function provideEmptyInput(): array { + public static function provideEmptyInput(): array { return [ [''], [' '], @@ -33,11 +34,11 @@ class SearchTest extends PHPUnit\Framework\TestCase { } /** - * @dataProvider provideIntitleSearch * @param array<string>|null $intitle_value * @param array<string>|null $search_value */ - public function test__construct_whenInputContainsIntitle_setsIntitleProperty(string $input, ?array $intitle_value, ?array $search_value): void { + #[DataProvider('provideIntitleSearch')] + public static function test__construct_whenInputContainsIntitle_setsIntitleProperty(string $input, ?array $intitle_value, ?array $search_value): void { $search = new FreshRSS_Search($input); self::assertEquals($intitle_value, $search->getIntitle()); self::assertEquals($search_value, $search->getSearch()); @@ -46,7 +47,7 @@ class SearchTest extends PHPUnit\Framework\TestCase { /** * @return array<array<mixed>> */ - public function provideIntitleSearch(): array { + public static function provideIntitleSearch(): array { return [ ['intitle:word1', ['word1'], null], ['intitle:word1-word2', ['word1-word2'], null], @@ -70,11 +71,11 @@ class SearchTest extends PHPUnit\Framework\TestCase { } /** - * @dataProvider provideAuthorSearch * @param array<string>|null $author_value * @param array<string>|null $search_value */ - public function test__construct_whenInputContainsAuthor_setsAuthorValue(string $input, ?array $author_value, ?array $search_value): void { + #[DataProvider('provideAuthorSearch')] + public static function test__construct_whenInputContainsAuthor_setsAuthorValue(string $input, ?array $author_value, ?array $search_value): void { $search = new FreshRSS_Search($input); self::assertEquals($author_value, $search->getAuthor()); self::assertEquals($search_value, $search->getSearch()); @@ -83,7 +84,7 @@ class SearchTest extends PHPUnit\Framework\TestCase { /** * @return array<array<mixed>> */ - public function provideAuthorSearch(): array { + public static function provideAuthorSearch(): array { return [ ['author:word1', ['word1'], null], ['author:word1-word2', ['word1-word2'], null], @@ -107,11 +108,11 @@ class SearchTest extends PHPUnit\Framework\TestCase { } /** - * @dataProvider provideInurlSearch * @param array<string>|null $inurl_value * @param array<string>|null $search_value */ - public function test__construct_whenInputContainsInurl_setsInurlValue(string $input, ?array $inurl_value, ?array $search_value): void { + #[DataProvider('provideInurlSearch')] + public static function test__construct_whenInputContainsInurl_setsInurlValue(string $input, ?array $inurl_value, ?array $search_value): void { $search = new FreshRSS_Search($input); self::assertEquals($inurl_value, $search->getInurl()); self::assertEquals($search_value, $search->getSearch()); @@ -120,7 +121,7 @@ class SearchTest extends PHPUnit\Framework\TestCase { /** * @return array<array<mixed>> */ - public function provideInurlSearch(): array { + public static function provideInurlSearch(): array { return [ ['inurl:word1', ['word1'], null], ['inurl: word1', [], ['word1']], @@ -133,10 +134,8 @@ class SearchTest extends PHPUnit\Framework\TestCase { ]; } - /** - * @dataProvider provideDateSearch - */ - public function test__construct_whenInputContainsDate_setsDateValues(string $input, ?int $min_date_value, ?int $max_date_value): void { + #[DataProvider('provideDateSearch')] + public static function test__construct_whenInputContainsDate_setsDateValues(string $input, ?int $min_date_value, ?int $max_date_value): void { $search = new FreshRSS_Search($input); self::assertEquals($min_date_value, $search->getMinDate()); self::assertEquals($max_date_value, $search->getMaxDate()); @@ -145,7 +144,7 @@ class SearchTest extends PHPUnit\Framework\TestCase { /** * @return array<array<mixed>> */ - public function provideDateSearch(): array { + public static function provideDateSearch(): array { return array( array('date:2007-03-01T13:00:00Z/2008-05-11T15:30:00Z', 1172754000, 1210519800), array('date:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', 1172754000, 1210519799), @@ -156,10 +155,8 @@ class SearchTest extends PHPUnit\Framework\TestCase { ); } - /** - * @dataProvider providePubdateSearch - */ - public function test__construct_whenInputContainsPubdate_setsPubdateValues(string $input, ?int $min_pubdate_value, ?int $max_pubdate_value): void { + #[DataProvider('providePubdateSearch')] + public static function test__construct_whenInputContainsPubdate_setsPubdateValues(string $input, ?int $min_pubdate_value, ?int $max_pubdate_value): void { $search = new FreshRSS_Search($input); self::assertEquals($min_pubdate_value, $search->getMinPubdate()); self::assertEquals($max_pubdate_value, $search->getMaxPubdate()); @@ -168,7 +165,7 @@ class SearchTest extends PHPUnit\Framework\TestCase { /** * @return array<array<mixed>> */ - public function providePubdateSearch(): array { + public static function providePubdateSearch(): array { return array( array('pubdate:2007-03-01T13:00:00Z/2008-05-11T15:30:00Z', 1172754000, 1210519800), array('pubdate:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', 1172754000, 1210519799), @@ -180,11 +177,11 @@ class SearchTest extends PHPUnit\Framework\TestCase { } /** - * @dataProvider provideTagsSearch * @param array<string>|null $tags_value * @param array<string>|null $search_value */ - public function test__construct_whenInputContainsTags_setsTagsValue(string $input, ?array $tags_value, ?array $search_value): void { + #[DataProvider('provideTagsSearch')] + public static function test__construct_whenInputContainsTags_setsTagsValue(string $input, ?array $tags_value, ?array $search_value): void { $search = new FreshRSS_Search($input); self::assertEquals($tags_value, $search->getTags()); self::assertEquals($search_value, $search->getSearch()); @@ -193,7 +190,7 @@ class SearchTest extends PHPUnit\Framework\TestCase { /** * @return array<array<string|array<string>|null>> */ - public function provideTagsSearch(): array { + public static function provideTagsSearch(): array { return [ ['#word1', ['word1'], null], ['# word1', null, ['#', 'word1']], @@ -207,14 +204,14 @@ class SearchTest extends PHPUnit\Framework\TestCase { } /** - * @dataProvider provideMultipleSearch * @param array<string>|null $author_value * @param array<string> $intitle_value * @param array<string>|null $inurl_value * @param array<string>|null $tags_value * @param array<string>|null $search_value */ - public function test__construct_whenInputContainsMultipleKeywords_setsValues(string $input, ?array $author_value, ?int $min_date_value, + #[DataProvider('provideMultipleSearch')] + public static function test__construct_whenInputContainsMultipleKeywords_setsValues(string $input, ?array $author_value, ?int $min_date_value, ?int $max_date_value, ?array $intitle_value, ?array $inurl_value, ?int $min_pubdate_value, ?int $max_pubdate_value, ?array $tags_value, ?array $search_value): void { $search = new FreshRSS_Search($input); @@ -231,7 +228,7 @@ class SearchTest extends PHPUnit\Framework\TestCase { } /** @return array<array<mixed>> */ - public function provideMultipleSearch(): array { + public static function provideMultipleSearch(): array { return array( array( 'author:word1 date:2007-03-01/2008-05-11 intitle:word2 inurl:word3 pubdate:2007-03-01/2008-05-11 #word4 #word5', @@ -284,15 +281,13 @@ class SearchTest extends PHPUnit\Framework\TestCase { ); } - /** - * @dataProvider provideAddOrParentheses - */ - public function test__addOrParentheses(string $input, string $output): void { + #[DataProvider('provideAddOrParentheses')] + public static function test__addOrParentheses(string $input, string $output): void { self::assertEquals($output, FreshRSS_BooleanSearch::addOrParentheses($input)); } /** @return array<array{string,string}> */ - public function provideAddOrParentheses(): array { + public static function provideAddOrParentheses(): array { return [ ['ab', 'ab'], ['ab cd', 'ab cd'], @@ -304,15 +299,13 @@ class SearchTest extends PHPUnit\Framework\TestCase { ]; } - /** - * @dataProvider provideconsistentOrParentheses - */ - public function test__consistentOrParentheses(string $input, string $output): void { + #[DataProvider('provideconsistentOrParentheses')] + public static function test__consistentOrParentheses(string $input, string $output): void { self::assertEquals($output, FreshRSS_BooleanSearch::consistentOrParentheses($input)); } /** @return array<array{string,string}> */ - public function provideconsistentOrParentheses(): array { + public static function provideconsistentOrParentheses(): array { return [ ['ab cd ef', 'ab cd ef'], ['(ab cd ef)', '(ab cd ef)'], @@ -332,9 +325,9 @@ class SearchTest extends PHPUnit\Framework\TestCase { } /** - * @dataProvider provideParentheses * @param array<string> $values */ + #[DataProvider('provideParentheses')] public function test__parentheses(string $input, string $sql, array $values): void { [$filterValues, $filterSearch] = FreshRSS_EntryDAOPGSQL::sqlBooleanSearch('e.', new FreshRSS_BooleanSearch($input)); self::assertEquals(trim($sql), trim($filterSearch)); @@ -342,7 +335,7 @@ class SearchTest extends PHPUnit\Framework\TestCase { } /** @return array<array<mixed>> */ - public function provideParentheses(): array { + public static function provideParentheses(): array { return [ [ 'f:1 (f:2 OR f:3 OR f:4) (f:5 OR (f:6 OR f:7))', |
