aboutsummaryrefslogtreecommitdiff
path: root/tests/app
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2024-09-06 09:06:46 +0200
committerGravatar GitHub <noreply@github.com> 2024-09-06 09:06:46 +0200
commita81656c3ed5b8fe0f31794a4fbe0d1a907fca8e8 (patch)
tree8bf49bd876aaebc985a9fb1214863190a799cbee /tests/app
parent8f7c3473a76809efc88814253722c76f0cc8eb04 (diff)
Upgrade to PHP 8.1 (#6711)
* Upgrade to PHP 8.1 As discussed in https://github.com/FreshRSS/FreshRSS/discussions/5474 https://www.php.net/releases/8.0/en.php https://www.php.net/releases/8.1/en.php Upgrade to available native type declarations https://php.net/language.types.declarations Upgrade to https://phpunit.de/announcements/phpunit-10.html which requires PHP 8.1+ (good timing, as version 9 was not maintained anymore) Upgrade `:oldest` Docker dev image to oldest Alpine version supporting PHP 8.1: Alpine 3.16, which includes PHP 8.1.22. * Include 6736 https://github.com/FreshRSS/FreshRSS/pull/6736
Diffstat (limited to 'tests/app')
-rw-r--r--tests/app/Models/CategoryTest.php12
-rw-r--r--tests/app/Models/FeedDAOTest.php2
-rw-r--r--tests/app/Models/SearchTest.php77
-rw-r--r--tests/app/Models/UserQueryTest.php36
-rw-r--r--tests/app/Utils/dotNotationUtilTest.php8
5 files changed, 65 insertions, 70 deletions
diff --git a/tests/app/Models/CategoryTest.php b/tests/app/Models/CategoryTest.php
index c9e88a32d..f9aa1a280 100644
--- a/tests/app/Models/CategoryTest.php
+++ b/tests/app/Models/CategoryTest.php
@@ -1,24 +1,24 @@
<?php
declare(strict_types=1);
+use PHPUnit\Framework\Attributes\DataProvider;
+
class CategoryTest extends PHPUnit\Framework\TestCase {
- public function test__construct_whenNoParameters_createsObjectWithDefaultValues(): void {
+ public static function test__construct_whenNoParameters_createsObjectWithDefaultValues(): void {
$category = new FreshRSS_Category();
self::assertEquals(0, $category->id());
self::assertEquals('', $category->name());
}
- /**
- * @dataProvider provideValidNames
- */
- public function test_name_whenValidValue_storesModifiedValue(string $input, string $expected): void {
+ #[DataProvider('provideValidNames')]
+ public static function test_name_whenValidValue_storesModifiedValue(string $input, string $expected): void {
$category = new FreshRSS_Category($input);
self::assertEquals($expected, $category->name());
}
/** @return array<array{string,string}> */
- public function provideValidNames(): array {
+ public static function provideValidNames(): array {
return [
['', ''],
['this string does not need trimming', 'this string does not need trimming'],
diff --git a/tests/app/Models/FeedDAOTest.php b/tests/app/Models/FeedDAOTest.php
index cd197bf9e..31cfc57f9 100644
--- a/tests/app/Models/FeedDAOTest.php
+++ b/tests/app/Models/FeedDAOTest.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
class FeedDAOTest extends PHPUnit\Framework\TestCase {
- public function test_ttl_min(): void {
+ public static function test_ttl_min(): void {
$feed = new FreshRSS_Feed('https://example.net/', false);
$feed->_ttl(-5);
self::assertEquals(-5, $feed->ttl(true));
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))',
diff --git a/tests/app/Models/UserQueryTest.php b/tests/app/Models/UserQueryTest.php
index 828bd4276..f9577e49b 100644
--- a/tests/app/Models/UserQueryTest.php
+++ b/tests/app/Models/UserQueryTest.php
@@ -6,13 +6,13 @@ declare(strict_types=1);
*/
class UserQueryTest extends PHPUnit\Framework\TestCase {
- public function test__construct_whenAllQuery_storesAllParameters(): void {
+ public static function test__construct_whenAllQuery_storesAllParameters(): void {
$query = array('get' => 'a');
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertEquals('all', $user_query->getGetType());
}
- public function test__construct_whenFavoriteQuery_storesFavoriteParameters(): void {
+ public static function test__construct_whenFavoriteQuery_storesFavoriteParameters(): void {
$query = array('get' => 's');
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertEquals('favorite', $user_query->getGetType());
@@ -56,47 +56,47 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {
self::assertEquals('feed', $user_query->getGetType());
}
- public function test__construct_whenUnknownQuery_doesStoreParameters(): void {
+ public static function test__construct_whenUnknownQuery_doesStoreParameters(): void {
$query = array('get' => 'q');
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertEmpty($user_query->getGetName());
self::assertEmpty($user_query->getGetType());
}
- public function test__construct_whenName_storesName(): void {
+ public static function test__construct_whenName_storesName(): void {
$name = 'some name';
$query = array('name' => $name);
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertEquals($name, $user_query->getName());
}
- public function test__construct_whenOrder_storesOrder(): void {
+ public static function test__construct_whenOrder_storesOrder(): void {
$order = 'some order';
$query = array('order' => $order);
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertEquals($order, $user_query->getOrder());
}
- public function test__construct_whenState_storesState(): void {
+ public static function test__construct_whenState_storesState(): void {
$state = FreshRSS_Entry::STATE_NOT_READ | FreshRSS_Entry::STATE_FAVORITE;
$query = array('state' => $state);
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertEquals($state, $user_query->getState());
}
- public function test__construct_whenUrl_storesUrl(): void {
+ public static function test__construct_whenUrl_storesUrl(): void {
$url = 'some url';
$query = array('url' => $url);
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertEquals($url, $user_query->getUrl());
}
- public function testToArray_whenNoData_returnsEmptyArray(): void {
+ public static function testToArray_whenNoData_returnsEmptyArray(): void {
$user_query = new FreshRSS_UserQuery([], [], []);
self::assertCount(0, $user_query->toArray());
}
- public function testToArray_whenData_returnsArray(): void {
+ public static function testToArray_whenData_returnsArray(): void {
$query = array(
'get' => 's',
'name' => 'some name',
@@ -110,7 +110,7 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {
self::assertEquals($query, $user_query->toArray());
}
- public function testHasSearch_whenSearch_returnsTrue(): void {
+ public static function testHasSearch_whenSearch_returnsTrue(): void {
$query = array(
'search' => 'some search',
);
@@ -118,24 +118,24 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {
self::assertTrue($user_query->hasSearch());
}
- public function testHasSearch_whenNoSearch_returnsFalse(): void {
+ public static function testHasSearch_whenNoSearch_returnsFalse(): void {
$user_query = new FreshRSS_UserQuery([], [], []);
self::assertFalse($user_query->hasSearch());
}
- public function testHasParameters_whenAllQuery_returnsFalse(): void {
+ public static function testHasParameters_whenAllQuery_returnsFalse(): void {
$query = array('get' => 'a');
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertFalse($user_query->hasParameters());
}
- public function testHasParameters_whenNoParameter_returnsFalse(): void {
+ public static function testHasParameters_whenNoParameter_returnsFalse(): void {
$query = array();
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertFalse($user_query->hasParameters());
}
- public function testHasParameters_whenParameter_returnTrue(): void {
+ public static function testHasParameters_whenParameter_returnTrue(): void {
$query = array('get' => 's');
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertTrue($user_query->hasParameters());
@@ -153,7 +153,7 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {
self::assertFalse($user_query->isDeprecated());
}
- public function testIsDeprecated_whenCategoryDoesNotExist_returnTrue(): void {
+ public static function testIsDeprecated_whenCategoryDoesNotExist_returnTrue(): void {
$query = array('get' => 'c_1');
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertTrue($user_query->isDeprecated());
@@ -193,19 +193,19 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {
self::assertTrue($user_query->isDeprecated());
}
- public function testIsDeprecated_whenAllQuery_returnFalse(): void {
+ public static function testIsDeprecated_whenAllQuery_returnFalse(): void {
$query = array('get' => 'a');
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertFalse($user_query->isDeprecated());
}
- public function testIsDeprecated_whenFavoriteQuery_returnFalse(): void {
+ public static function testIsDeprecated_whenFavoriteQuery_returnFalse(): void {
$query = array('get' => 's');
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertFalse($user_query->isDeprecated());
}
- public function testIsDeprecated_whenUnknownQuery_returnFalse(): void {
+ public static function testIsDeprecated_whenUnknownQuery_returnFalse(): void {
$query = array('get' => 'q');
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertFalse($user_query->isDeprecated());
diff --git a/tests/app/Utils/dotNotationUtilTest.php b/tests/app/Utils/dotNotationUtilTest.php
index a04ddba4f..e49220d30 100644
--- a/tests/app/Utils/dotNotationUtilTest.php
+++ b/tests/app/Utils/dotNotationUtilTest.php
@@ -1,12 +1,14 @@
<?php
declare(strict_types=1);
+use PHPUnit\Framework\Attributes\DataProvider;
+
class dotNotationUtilTest extends PHPUnit\Framework\TestCase {
/**
* @return Traversable<array{array<string,mixed>,string,string}>
*/
- public function provideJsonDots(): Traversable {
+ public static function provideJsonDots(): Traversable {
$json = <<<json
{
"hello": "world",
@@ -34,10 +36,10 @@ class dotNotationUtilTest extends PHPUnit\Framework\TestCase {
}
/**
- * @dataProvider provideJsonDots
* @param array<string,mixed> $array
*/
- public function testJsonDots(array $array, string $key, string $expected): void {
+ #[DataProvider('provideJsonDots')]
+ public static function testJsonDots(array $array, string $key, string $expected): void {
$value = FreshRSS_dotNotation_Util::get($array, $key);
self::assertEquals($expected, $value);
}