aboutsummaryrefslogtreecommitdiff
path: root/tests/app/Models/SearchTest.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-04-17 08:30:21 +0200
committerGravatar GitHub <noreply@github.com> 2023-04-17 08:30:21 +0200
commitf3760f138dcbaf7a2190336a0378cf1b2190c9f5 (patch)
tree6fac8fbf9efd7aa74a8e3970ab70ccf85287b2cd /tests/app/Models/SearchTest.php
parent41fa4e746df8c2e2399ed753b4994ca85cb21358 (diff)
Complete PHPStan Level 6 (#5305)
* Complete PHPStan Level 6 Fix https://github.com/FreshRSS/FreshRSS/issues/4112 And initiate PHPStan Level 7 * PHPStan Level 6 for tests * Use phpstan/phpstan-phpunit * Update to PHPStan version 1.10 * Fix mixed bug * Fix mixed return bug * Fix paginator bug * Fix FreshRSS_UserConfiguration * A couple more Minz_Configuration bug fixes * A few trivial PHPStan Level 7 fixes * A few more simple PHPStan Level 7 * More files passing PHPStan Level 7 Add interface to replace removed class from https://github.com/FreshRSS/FreshRSS/pull/5251 * A few more PHPStan Level 7 preparations * A few last details
Diffstat (limited to 'tests/app/Models/SearchTest.php')
-rw-r--r--tests/app/Models/SearchTest.php117
1 files changed, 52 insertions, 65 deletions
diff --git a/tests/app/Models/SearchTest.php b/tests/app/Models/SearchTest.php
index 52c10244d..2b2501589 100644
--- a/tests/app/Models/SearchTest.php
+++ b/tests/app/Models/SearchTest.php
@@ -6,9 +6,8 @@ class SearchTest extends PHPUnit\Framework\TestCase {
/**
* @dataProvider provideEmptyInput
- * @param string|null $input
*/
- public function test__construct_whenInputIsEmpty_getsOnlyNullValues($input) {
+ public function test__construct_whenInputIsEmpty_getsOnlyNullValues(?string $input): void {
$search = new FreshRSS_Search($input);
$this->assertEquals('', $search->getRawInput());
$this->assertNull($search->getIntitle());
@@ -24,9 +23,9 @@ class SearchTest extends PHPUnit\Framework\TestCase {
/**
* Return an array of values for the search object.
* Here is the description of the values
- * @return array
+ * @return array{array{''},array{null}}
*/
- public function provideEmptyInput() {
+ public function provideEmptyInput(): array {
return array(
array(''),
array(null),
@@ -35,20 +34,19 @@ class SearchTest extends PHPUnit\Framework\TestCase {
/**
* @dataProvider provideIntitleSearch
- * @param string $input
- * @param string $intitle_value
- * @param string|null $search_value
+ * @param array<string>|null $intitle_value
+ * @param array<string>|null $search_value
*/
- public function test__construct_whenInputContainsIntitle_setsIntitleProperty($input, $intitle_value, $search_value) {
+ public function test__construct_whenInputContainsIntitle_setsIntitleProperty(string $input, ?array $intitle_value, ?array $search_value): void {
$search = new FreshRSS_Search($input);
$this->assertEquals($intitle_value, $search->getIntitle());
$this->assertEquals($search_value, $search->getSearch());
}
/**
- * @return array
+ * @return array<array<mixed>>
*/
- public function provideIntitleSearch() {
+ public function provideIntitleSearch(): array {
return array(
array('intitle:word1', array('word1'), null),
array('intitle:word1-word2', array('word1-word2'), null),
@@ -73,20 +71,19 @@ class SearchTest extends PHPUnit\Framework\TestCase {
/**
* @dataProvider provideAuthorSearch
- * @param string $input
- * @param string $author_value
- * @param string|null $search_value
+ * @param array<string>|null $author_value
+ * @param array<string>|null $search_value
*/
- public function test__construct_whenInputContainsAuthor_setsAuthorValue($input, $author_value, $search_value) {
+ public function test__construct_whenInputContainsAuthor_setsAuthorValue(string $input, ?array $author_value, ?array $search_value): void {
$search = new FreshRSS_Search($input);
$this->assertEquals($author_value, $search->getAuthor());
$this->assertEquals($search_value, $search->getSearch());
}
/**
- * @return array
+ * @return array<array<mixed>>
*/
- public function provideAuthorSearch() {
+ public function provideAuthorSearch(): array {
return array(
array('author:word1', array('word1'), null),
array('author:word1-word2', array('word1-word2'), null),
@@ -111,20 +108,19 @@ class SearchTest extends PHPUnit\Framework\TestCase {
/**
* @dataProvider provideInurlSearch
- * @param string $input
- * @param string $inurl_value
- * @param string|null $search_value
+ * @param array<string>|null $inurl_value
+ * @param array<string>|null $search_value
*/
- public function test__construct_whenInputContainsInurl_setsInurlValue($input, $inurl_value, $search_value) {
+ public function test__construct_whenInputContainsInurl_setsInurlValue(string $input, ?array $inurl_value, ?array $search_value): void {
$search = new FreshRSS_Search($input);
$this->assertEquals($inurl_value, $search->getInurl());
$this->assertEquals($search_value, $search->getSearch());
}
/**
- * @return array
+ * @return array<array<mixed>>
*/
- public function provideInurlSearch() {
+ public function provideInurlSearch(): array {
return array(
array('inurl:word1', array('word1'), null),
array('inurl: word1', array(), array('word1')),
@@ -139,72 +135,65 @@ class SearchTest extends PHPUnit\Framework\TestCase {
/**
* @dataProvider provideDateSearch
- * @param string $input
- * @param string $min_date_value
- * @param string $max_date_value
*/
- public function test__construct_whenInputContainsDate_setsDateValues($input, $min_date_value, $max_date_value) {
+ public function test__construct_whenInputContainsDate_setsDateValues(string $input, ?int $min_date_value, ?int $max_date_value): void {
$search = new FreshRSS_Search($input);
$this->assertEquals($min_date_value, $search->getMinDate());
$this->assertEquals($max_date_value, $search->getMaxDate());
}
/**
- * @return array
+ * @return array<array<mixed>>
*/
- public function provideDateSearch() {
+ public 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'),
- array('date:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', '1172754001', '1210519800'),
+ array('date:2007-03-01T13:00:00Z/2008-05-11T15:30:00Z', 1172754000, 1210519800),
+ array('date:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', 1172754000, 1210519799),
+ array('date:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', 1172754001, 1210519800),
array('date:2007-03-01/2008-05-11', strtotime('2007-03-01'), strtotime('2008-05-12') - 1),
- array('date:2007-03-01/', strtotime('2007-03-01'), ''),
- array('date:/2008-05-11', '', strtotime('2008-05-12') - 1),
+ array('date:2007-03-01/', strtotime('2007-03-01'), null),
+ array('date:/2008-05-11', null, strtotime('2008-05-12') - 1),
);
}
/**
* @dataProvider providePubdateSearch
- * @param string $input
- * @param string $min_pubdate_value
- * @param string $max_pubdate_value
*/
- public function test__construct_whenInputContainsPubdate_setsPubdateValues($input, $min_pubdate_value, $max_pubdate_value) {
+ public function test__construct_whenInputContainsPubdate_setsPubdateValues(string $input, ?int $min_pubdate_value, ?int $max_pubdate_value): void {
$search = new FreshRSS_Search($input);
$this->assertEquals($min_pubdate_value, $search->getMinPubdate());
$this->assertEquals($max_pubdate_value, $search->getMaxPubdate());
}
/**
- * @return array
+ * @return array<array<mixed>>
*/
- public function providePubdateSearch() {
+ public 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'),
- array('pubdate:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', '1172754001', '1210519800'),
+ array('pubdate:2007-03-01T13:00:00Z/2008-05-11T15:30:00Z', 1172754000, 1210519800),
+ array('pubdate:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', 1172754000, 1210519799),
+ array('pubdate:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', 1172754001, 1210519800),
array('pubdate:2007-03-01/2008-05-11', strtotime('2007-03-01'), strtotime('2008-05-12') - 1),
- array('pubdate:2007-03-01/', strtotime('2007-03-01'), ''),
- array('pubdate:/2008-05-11', '', strtotime('2008-05-12') - 1),
+ array('pubdate:2007-03-01/', strtotime('2007-03-01'), null),
+ array('pubdate:/2008-05-11', null, strtotime('2008-05-12') - 1),
);
}
/**
* @dataProvider provideTagsSearch
- * @param string $input
- * @param string $tags_value
- * @param string|null $search_value
+ * @param array<string>|null $tags_value
+ * @param array<string>|null $search_value
*/
- public function test__construct_whenInputContainsTags_setsTagsValue($input, $tags_value, $search_value) {
+ public function test__construct_whenInputContainsTags_setsTagsValue(string $input, ?array $tags_value, ?array $search_value): void {
$search = new FreshRSS_Search($input);
$this->assertEquals($tags_value, $search->getTags());
$this->assertEquals($search_value, $search->getSearch());
}
/**
- * @return array
+ * @return array<array<string|array<string>|null>>
*/
- public function provideTagsSearch() {
+ public function provideTagsSearch(): array {
return array(
array('#word1', array('word1'), null),
array('# word1', array(), array('#', 'word1')),
@@ -219,19 +208,15 @@ class SearchTest extends PHPUnit\Framework\TestCase {
/**
* @dataProvider provideMultipleSearch
- * @param string $input
- * @param string $author_value
- * @param string $min_date_value
- * @param string $max_date_value
- * @param string $intitle_value
- * @param string $inurl_value
- * @param string $min_pubdate_value
- * @param string $max_pubdate_value
- * @param array $tags_value
- * @param string|null $search_value
+ * @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($input, $author_value, $min_date_value,
- $max_date_value, $intitle_value, $inurl_value, $min_pubdate_value, $max_pubdate_value, $tags_value, $search_value) {
+ public 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);
$this->assertEquals($author_value, $search->getAuthor());
$this->assertEquals($min_date_value, $search->getMinDate());
@@ -245,7 +230,8 @@ class SearchTest extends PHPUnit\Framework\TestCase {
$this->assertEquals($input, $search->getRawInput());
}
- public function provideMultipleSearch() {
+ /** @return array<array<mixed>> */
+ public 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',
@@ -302,13 +288,14 @@ class SearchTest extends PHPUnit\Framework\TestCase {
* @dataProvider provideParentheses
* @param array<string> $values
*/
- public function test__construct_parentheses(string $input, string $sql, $values) {
+ public function test__construct_parentheses(string $input, string $sql, array $values): void {
list($filterValues, $filterSearch) = FreshRSS_EntryDAOPGSQL::sqlBooleanSearch('e.', new FreshRSS_BooleanSearch($input));
$this->assertEquals($sql, $filterSearch);
$this->assertEquals($values, $filterValues);
}
- public function provideParentheses() {
+ /** @return array<array<mixed>> */
+ public function provideParentheses(): array {
return [
[
'f:1 (f:2 OR f:3 OR f:4) (f:5 OR (f:6 OR f:7))',