diff options
| author | 2023-04-17 08:30:21 +0200 | |
|---|---|---|
| committer | 2023-04-17 08:30:21 +0200 | |
| commit | f3760f138dcbaf7a2190336a0378cf1b2190c9f5 (patch) | |
| tree | 6fac8fbf9efd7aa74a8e3970ab70ccf85287b2cd /tests | |
| parent | 41fa4e746df8c2e2399ed753b4994ca85cb21358 (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')
| -rw-r--r-- | tests/app/Models/CategoryTest.php | 11 | ||||
| -rw-r--r-- | tests/app/Models/LogDAOTest.php | 2 | ||||
| -rw-r--r-- | tests/app/Models/SearchTest.php | 117 | ||||
| -rw-r--r-- | tests/app/Models/UserQueryTest.php | 64 | ||||
| -rw-r--r-- | tests/app/Utils/passwordUtilTest.php | 6 | ||||
| -rw-r--r-- | tests/cli/i18n/I18nCompletionValidatorTest.php | 13 | ||||
| -rw-r--r-- | tests/cli/i18n/I18nDataTest.php | 68 | ||||
| -rw-r--r-- | tests/cli/i18n/I18nFileTest.php | 5 | ||||
| -rw-r--r-- | tests/cli/i18n/I18nUsageValidatorTest.php | 15 | ||||
| -rw-r--r-- | tests/cli/i18n/I18nValueTest.php | 18 | ||||
| -rw-r--r-- | tests/fixtures/migrations/2019_12_22_FooBar.php | 4 | ||||
| -rw-r--r-- | tests/fixtures/migrations/2019_12_23_Baz.php | 4 | ||||
| -rw-r--r-- | tests/fixtures/migrations_with_failing/2020_01_11_FooBar.php | 4 | ||||
| -rw-r--r-- | tests/fixtures/migrations_with_failing/2020_01_12_Baz.php | 4 | ||||
| -rw-r--r-- | tests/lib/CssXPath/CssXPathTest.php | 2 | ||||
| -rw-r--r-- | tests/lib/Minz/MigratorTest.php | 46 | ||||
| -rw-r--r-- | tests/lib/PHPMailer/PHPMailerTest.php | 2 | ||||
| -rw-r--r-- | tests/phpstan-next.txt | 48 |
18 files changed, 236 insertions, 197 deletions
diff --git a/tests/app/Models/CategoryTest.php b/tests/app/Models/CategoryTest.php index 93fbdbc63..a438afe9e 100644 --- a/tests/app/Models/CategoryTest.php +++ b/tests/app/Models/CategoryTest.php @@ -2,23 +2,22 @@ class CategoryTest extends PHPUnit\Framework\TestCase { - public function test__construct_whenNoParameters_createsObjectWithDefaultValues() { + public function test__construct_whenNoParameters_createsObjectWithDefaultValues(): void { $category = new FreshRSS_Category(); $this->assertEquals(0, $category->id()); $this->assertEquals('', $category->name()); } /** - * @param string $input - * @param string $expected * @dataProvider provideValidNames */ - public function test_name_whenValidValue_storesModifiedValue($input, $expected) { + public function test_name_whenValidValue_storesModifiedValue(string $input, string $expected): void { $category = new FreshRSS_Category($input); $this->assertEquals($expected, $category->name()); } - public function provideValidNames() { + /** @return array<array{string,string}> */ + public function provideValidNames(): array { return array( array('', ''), array('this string does not need trimming', 'this string does not need trimming'), @@ -30,7 +29,7 @@ class CategoryTest extends PHPUnit\Framework\TestCase { ); } - public function test_feedOrdering() { + public function test_feedOrdering(): void { $feed_1 = $this->getMockBuilder(FreshRSS_Feed::class) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/app/Models/LogDAOTest.php b/tests/app/Models/LogDAOTest.php index 18cad4968..abe6c6c1f 100644 --- a/tests/app/Models/LogDAOTest.php +++ b/tests/app/Models/LogDAOTest.php @@ -36,7 +36,7 @@ class LogDAOTest extends TestCase { $this->logDAO::truncate(self::LOG_FILE_TEST); - $this->assertStringContainsString('', file_get_contents($this->logPath)); + $this->assertStringContainsString('', file_get_contents($this->logPath) ?: ''); } protected function tearDown(): void { 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))', diff --git a/tests/app/Models/UserQueryTest.php b/tests/app/Models/UserQueryTest.php index 7b1e88907..d8610a81b 100644 --- a/tests/app/Models/UserQueryTest.php +++ b/tests/app/Models/UserQueryTest.php @@ -5,21 +5,21 @@ */ class UserQueryTest extends PHPUnit\Framework\TestCase { - public function test__construct_whenAllQuery_storesAllParameters() { + public function test__construct_whenAllQuery_storesAllParameters(): void { $query = array('get' => 'a'); $user_query = new FreshRSS_UserQuery($query); $this->assertEquals('all', $user_query->getGetName()); $this->assertEquals('all', $user_query->getGetType()); } - public function test__construct_whenFavoriteQuery_storesFavoriteParameters() { + public function test__construct_whenFavoriteQuery_storesFavoriteParameters(): void { $query = array('get' => 's'); $user_query = new FreshRSS_UserQuery($query); $this->assertEquals('favorite', $user_query->getGetName()); $this->assertEquals('favorite', $user_query->getGetType()); } - public function test__construct_whenCategoryQueryAndNoDao_throwsException() { + public function test__construct_whenCategoryQueryAndNoDao_throwsException(): void { $this->expectException(FreshRSS_DAO_Exception::class); $this->expectExceptionMessage('Category DAO is not loaded in UserQuery'); @@ -27,13 +27,15 @@ class UserQueryTest extends PHPUnit\Framework\TestCase { new FreshRSS_UserQuery($query); } - public function test__construct_whenCategoryQuery_storesCategoryParameters() { + public function test__construct_whenCategoryQuery_storesCategoryParameters(): void { $category_name = 'some category name'; + /** @var FreshRSS_Category&PHPUnit\Framework\MockObject\MockObject */ $cat = $this->createMock('FreshRSS_Category'); $cat->expects($this->atLeastOnce()) ->method('name') ->withAnyParameters() ->willReturn($category_name); + /** @var FreshRSS_CategoryDAO&PHPUnit\Framework\MockObject\MockObject */ $cat_dao = $this->createMock('FreshRSS_CategoryDAO'); $cat_dao->expects($this->atLeastOnce()) ->method('searchById') @@ -45,7 +47,7 @@ class UserQueryTest extends PHPUnit\Framework\TestCase { $this->assertEquals('category', $user_query->getGetType()); } - public function test__construct_whenFeedQueryAndNoDao_throwsException() { + public function test__construct_whenFeedQueryAndNoDao_throwsException(): void { $this->expectException(FreshRSS_DAO_Exception::class); $this->expectExceptionMessage('Feed DAO is not loaded in UserQuery'); @@ -53,13 +55,15 @@ class UserQueryTest extends PHPUnit\Framework\TestCase { new FreshRSS_UserQuery($query); } - public function test__construct_whenFeedQuery_storesFeedParameters() { + public function test__construct_whenFeedQuery_storesFeedParameters(): void { $feed_name = 'some feed name'; - $feed = $this->createMock('FreshRSS_Feed', array(), array('', false)); + /** @var FreshRSS_Feed&PHPUnit\Framework\MockObject\MockObject */ + $feed = $this->createMock('FreshRSS_Feed'); $feed->expects($this->atLeastOnce()) ->method('name') ->withAnyParameters() ->willReturn($feed_name); + /** @var FreshRSS_FeedDAO&PHPUnit\Framework\MockObject\MockObject */ $feed_dao = $this->createMock('FreshRSS_FeedDAO'); $feed_dao->expects($this->atLeastOnce()) ->method('searchById') @@ -71,48 +75,48 @@ class UserQueryTest extends PHPUnit\Framework\TestCase { $this->assertEquals('feed', $user_query->getGetType()); } - public function test__construct_whenUnknownQuery_doesStoreParameters() { + public function test__construct_whenUnknownQuery_doesStoreParameters(): void { $query = array('get' => 'q'); $user_query = new FreshRSS_UserQuery($query); $this->assertEmpty($user_query->getGetName()); $this->assertEmpty($user_query->getGetType()); } - public function test__construct_whenName_storesName() { + public function test__construct_whenName_storesName(): void { $name = 'some name'; $query = array('name' => $name); $user_query = new FreshRSS_UserQuery($query); $this->assertEquals($name, $user_query->getName()); } - public function test__construct_whenOrder_storesOrder() { + public function test__construct_whenOrder_storesOrder(): void { $order = 'some order'; $query = array('order' => $order); $user_query = new FreshRSS_UserQuery($query); $this->assertEquals($order, $user_query->getOrder()); } - public function test__construct_whenState_storesState() { + public function test__construct_whenState_storesState(): void { $state = FreshRSS_Entry::STATE_ALL; $query = array('state' => $state); $user_query = new FreshRSS_UserQuery($query); $this->assertEquals($state, $user_query->getState()); } - public function test__construct_whenUrl_storesUrl() { + public function test__construct_whenUrl_storesUrl(): void { $url = 'some url'; $query = array('url' => $url); $user_query = new FreshRSS_UserQuery($query); $this->assertEquals($url, $user_query->getUrl()); } - public function testToArray_whenNoData_returnsEmptyArray() { + public function testToArray_whenNoData_returnsEmptyArray(): void { $user_query = new FreshRSS_UserQuery(array()); $this->assertIsIterable($user_query->toArray()); $this->assertCount(0, $user_query->toArray()); } - public function testToArray_whenData_returnsArray() { + public function testToArray_whenData_returnsArray(): void { $query = array( 'get' => 's', 'name' => 'some name', @@ -127,7 +131,7 @@ class UserQueryTest extends PHPUnit\Framework\TestCase { $this->assertEquals($query, $user_query->toArray()); } - public function testHasSearch_whenSearch_returnsTrue() { + public function testHasSearch_whenSearch_returnsTrue(): void { $query = array( 'search' => 'some search', ); @@ -135,31 +139,33 @@ class UserQueryTest extends PHPUnit\Framework\TestCase { $this->assertTrue($user_query->hasSearch()); } - public function testHasSearch_whenNoSearch_returnsFalse() { + public function testHasSearch_whenNoSearch_returnsFalse(): void { $user_query = new FreshRSS_UserQuery(array()); $this->assertFalse($user_query->hasSearch()); } - public function testHasParameters_whenAllQuery_returnsFalse() { + public function testHasParameters_whenAllQuery_returnsFalse(): void { $query = array('get' => 'a'); $user_query = new FreshRSS_UserQuery($query); $this->assertFalse($user_query->hasParameters()); } - public function testHasParameters_whenNoParameter_returnsFalse() { + public function testHasParameters_whenNoParameter_returnsFalse(): void { $query = array(); $user_query = new FreshRSS_UserQuery($query); $this->assertFalse($user_query->hasParameters()); } - public function testHasParameters_whenParameter_returnTrue() { + public function testHasParameters_whenParameter_returnTrue(): void { $query = array('get' => 's'); $user_query = new FreshRSS_UserQuery($query); $this->assertTrue($user_query->hasParameters()); } - public function testIsDeprecated_whenCategoryExists_returnFalse() { + public function testIsDeprecated_whenCategoryExists_returnFalse(): void { + /** @var FreshRSS_Category&PHPUnit\Framework\MockObject\MockObject */ $cat = $this->createMock('FreshRSS_Category'); + /** @var FreshRSS_CategoryDAO&PHPUnit\Framework\MockObject\MockObject */ $cat_dao = $this->createMock('FreshRSS_CategoryDAO'); $cat_dao->expects($this->atLeastOnce()) ->method('searchById') @@ -170,7 +176,8 @@ class UserQueryTest extends PHPUnit\Framework\TestCase { $this->assertFalse($user_query->isDeprecated()); } - public function testIsDeprecated_whenCategoryDoesNotExist_returnTrue() { + public function testIsDeprecated_whenCategoryDoesNotExist_returnTrue(): void { + /** @var FreshRSS_CategoryDAO&PHPUnit\Framework\MockObject\MockObject */ $cat_dao = $this->createMock('FreshRSS_CategoryDAO'); $cat_dao->expects($this->atLeastOnce()) ->method('searchById') @@ -181,8 +188,10 @@ class UserQueryTest extends PHPUnit\Framework\TestCase { $this->assertTrue($user_query->isDeprecated()); } - public function testIsDeprecated_whenFeedExists_returnFalse() { - $feed = $this->createMock('FreshRSS_Feed', array(), array('', false)); + public function testIsDeprecated_whenFeedExists_returnFalse(): void { + /** @var FreshRSS_Feed&PHPUnit\Framework\MockObject\MockObject */ + $feed = $this->createMock('FreshRSS_Feed'); + /** @var FreshRSS_FeedDAO&PHPUnit\Framework\MockObject\MockObject */ $feed_dao = $this->createMock('FreshRSS_FeedDAO'); $feed_dao->expects($this->atLeastOnce()) ->method('searchById') @@ -193,7 +202,8 @@ class UserQueryTest extends PHPUnit\Framework\TestCase { $this->assertFalse($user_query->isDeprecated()); } - public function testIsDeprecated_whenFeedDoesNotExist_returnTrue() { + public function testIsDeprecated_whenFeedDoesNotExist_returnTrue(): void { + /** @var FreshRSS_FeedDAO&PHPUnit\Framework\MockObject\MockObject */ $feed_dao = $this->createMock('FreshRSS_FeedDAO'); $feed_dao->expects($this->atLeastOnce()) ->method('searchById') @@ -204,19 +214,19 @@ class UserQueryTest extends PHPUnit\Framework\TestCase { $this->assertTrue($user_query->isDeprecated()); } - public function testIsDeprecated_whenAllQuery_returnFalse() { + public function testIsDeprecated_whenAllQuery_returnFalse(): void { $query = array('get' => 'a'); $user_query = new FreshRSS_UserQuery($query); $this->assertFalse($user_query->isDeprecated()); } - public function testIsDeprecated_whenFavoriteQuery_returnFalse() { + public function testIsDeprecated_whenFavoriteQuery_returnFalse(): void { $query = array('get' => 's'); $user_query = new FreshRSS_UserQuery($query); $this->assertFalse($user_query->isDeprecated()); } - public function testIsDeprecated_whenUnknownQuery_returnFalse() { + public function testIsDeprecated_whenUnknownQuery_returnFalse(): void { $query = array('get' => 'q'); $user_query = new FreshRSS_UserQuery($query); $this->assertFalse($user_query->isDeprecated()); diff --git a/tests/app/Utils/passwordUtilTest.php b/tests/app/Utils/passwordUtilTest.php index ddccb784f..113476c63 100644 --- a/tests/app/Utils/passwordUtilTest.php +++ b/tests/app/Utils/passwordUtilTest.php @@ -1,7 +1,7 @@ <?php class passwordUtilTest extends PHPUnit\Framework\TestCase { - public function testCheck() { + public function testCheck(): void { $password = '1234567'; $ok = FreshRSS_password_Util::check($password); @@ -9,7 +9,7 @@ class passwordUtilTest extends PHPUnit\Framework\TestCase { $this->assertTrue($ok); } - public function testCheckReturnsFalseIfEmpty() { + public function testCheckReturnsFalseIfEmpty(): void { $password = ''; $ok = FreshRSS_password_Util::check($password); @@ -17,7 +17,7 @@ class passwordUtilTest extends PHPUnit\Framework\TestCase { $this->assertFalse($ok); } - public function testCheckReturnsFalseIfLessThan7Characters() { + public function testCheckReturnsFalseIfLessThan7Characters(): void { $password = '123456'; $ok = FreshRSS_password_Util::check($password); diff --git a/tests/cli/i18n/I18nCompletionValidatorTest.php b/tests/cli/i18n/I18nCompletionValidatorTest.php index 1aa871f20..1a361823d 100644 --- a/tests/cli/i18n/I18nCompletionValidatorTest.php +++ b/tests/cli/i18n/I18nCompletionValidatorTest.php @@ -4,6 +4,7 @@ require_once __DIR__ . '/../../../cli/i18n/I18nCompletionValidator.php'; require_once __DIR__ . '/../../../cli/i18n/I18nValue.php'; class I18nCompletionValidatorTest extends PHPUnit\Framework\TestCase { + /** @var I18nValue&PHPUnit\Framework\MockObject\MockObject */ private $value; public function setUp(): void { @@ -12,7 +13,7 @@ class I18nCompletionValidatorTest extends PHPUnit\Framework\TestCase { ->getMock(); } - public function testDisplayReport() { + public function testDisplayReport(): void { $validator = new I18nCompletionValidator([], []); $this->assertEquals("There is no data.\n", $validator->displayReport()); @@ -40,13 +41,13 @@ class I18nCompletionValidatorTest extends PHPUnit\Framework\TestCase { $validator->displayReport(); } - public function testValidateWhenNoData() { + public function testValidateWhenNoData(): void { $validator = new I18nCompletionValidator([], []); $this->assertTrue($validator->validate()); $this->assertEquals('', $validator->displayResult()); } - public function testValidateWhenKeyIsMissing() { + public function testValidateWhenKeyIsMissing(): void { $validator = new I18nCompletionValidator([ 'file1.php' => [ 'file1.l1.l2.k1' => $this->value, @@ -60,7 +61,7 @@ class I18nCompletionValidatorTest extends PHPUnit\Framework\TestCase { $this->assertEquals("Missing key file1.l1.l2.k1\nMissing key file2.l1.l2.k1\n", $validator->displayResult()); } - public function testValidateWhenKeyIsIgnored() { + public function testValidateWhenKeyIsIgnored(): void { $this->value->expects($this->exactly(2)) ->method('isIgnore') ->willReturn(true); @@ -85,7 +86,7 @@ class I18nCompletionValidatorTest extends PHPUnit\Framework\TestCase { $this->assertEquals('', $validator->displayResult()); } - public function testValidateWhenValueIsEqual() { + public function testValidateWhenValueIsEqual(): void { $this->value->expects($this->exactly(2)) ->method('isIgnore') ->willReturn(false); @@ -113,7 +114,7 @@ class I18nCompletionValidatorTest extends PHPUnit\Framework\TestCase { $this->assertEquals("Untranslated key file1.l1.l2.k1 - \nUntranslated key file2.l1.l2.k1 - \n", $validator->displayResult()); } - public function testValidateWhenValueIsDifferent() { + public function testValidateWhenValueIsDifferent(): void { $this->value->expects($this->exactly(2)) ->method('isIgnore') ->willReturn(false); diff --git a/tests/cli/i18n/I18nDataTest.php b/tests/cli/i18n/I18nDataTest.php index b27ad830c..37811c193 100644 --- a/tests/cli/i18n/I18nDataTest.php +++ b/tests/cli/i18n/I18nDataTest.php @@ -4,7 +4,9 @@ require_once __DIR__ . '/../../../cli/i18n/I18nData.php'; require_once __DIR__ . '/../../../cli/i18n/I18nValue.php'; class I18nDataTest extends PHPUnit\Framework\TestCase { + /** @var array<string,array<string,array<string,I18nValue>>> */ private $referenceData; + /** @var I18nValue&PHPUnit\Framework\MockObject\MockObject */ private $value; public function setUp(): void { @@ -31,12 +33,12 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { ]; } - public function testConstructWhenReferenceOnly() { + public function testConstructWhenReferenceOnly(): void { $data = new I18nData($this->referenceData); $this->assertEquals($this->referenceData, $data->getData()); } - public function testConstructorWhenLanguageIsMissingFile() { + public function testConstructorWhenLanguageIsMissingFile(): void { $rawData = array_merge($this->referenceData, [ 'fr' => [ 'file1.php' => [ @@ -79,7 +81,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { ], $data->getData()); } - public function testConstructorWhenLanguageIsMissingKeys() { + public function testConstructorWhenLanguageIsMissingKeys(): void { $rawData = array_merge($this->referenceData, [ 'fr' => [ 'file1.php' => [ @@ -125,7 +127,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { ], $data->getData()); } - public function testConstructorWhenLanguageHasExtraKeys() { + public function testConstructorWhenLanguageHasExtraKeys(): void { $rawData = array_merge($this->referenceData, [ 'fr' => [ 'file1.php' => [ @@ -179,7 +181,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { ], $data->getData()); } - public function testConstructorWhenValueIsIdenticalAndIsMarkedAsIgnore() { + public function testConstructorWhenValueIsIdenticalAndIsMarkedAsIgnore(): void { $value = $this->getMockBuilder(I18nValue::class) ->disableOriginalConstructor() ->getMock(); @@ -204,7 +206,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { new I18nData($rawData); } - public function testConstructorWhenValueIsIdenticalAndIsNotMarkedAsIgnore() { + public function testConstructorWhenValueIsIdenticalAndIsNotMarkedAsIgnore(): void { $value = $this->getMockBuilder(I18nValue::class) ->disableOriginalConstructor() ->getMock(); @@ -229,7 +231,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { new I18nData($rawData); } - public function testConstructorWhenValueIsDifferentAndIsMarkedAsToDo() { + public function testConstructorWhenValueIsDifferentAndIsMarkedAsToDo(): void { $value = $this->getMockBuilder(I18nValue::class) ->disableOriginalConstructor() ->getMock(); @@ -249,7 +251,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { new I18nData($rawData); } - public function testConstructorWhenValueIsDifferentAndIsNotMarkedAsTodo() { + public function testConstructorWhenValueIsDifferentAndIsNotMarkedAsTodo(): void { $value = $this->getMockBuilder(I18nValue::class) ->disableOriginalConstructor() ->getMock(); @@ -269,7 +271,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { new I18nData($rawData); } - public function testGetAvailableLanguagesWhenTheyAreSorted() { + public function testGetAvailableLanguagesWhenTheyAreSorted(): void { $rawData = array_merge($this->referenceData, [ 'fr' => [], 'nl' => [], @@ -282,7 +284,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { ], $data->getAvailableLanguages()); } - public function testGetAvailableLanguagesWhenTheyAreNotSorted() { + public function testGetAvailableLanguagesWhenTheyAreNotSorted(): void { $rawData = array_merge($this->referenceData, [ 'nl' => [], 'fr' => [], @@ -297,14 +299,14 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { ], $data->getAvailableLanguages()); } - public function testAddLanguageWhenLanguageExists() { + public function testAddLanguageWhenLanguageExists(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('The selected language already exist.'); $data = new I18nData($this->referenceData); $data->addLanguage('en'); } - public function testAddLanguageWhenNoReferenceProvided() { + public function testAddLanguageWhenNoReferenceProvided(): void { $data = new I18nData($this->referenceData); $data->addLanguage('fr'); $this->assertEquals([ @@ -341,7 +343,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { ], $data->getData()); } - public function testAddLanguageWhenUnknownReferenceProvided() { + public function testAddLanguageWhenUnknownReferenceProvided(): void { $data = new I18nData($this->referenceData); $data->addLanguage('fr', 'unknown'); $this->assertEquals([ @@ -378,7 +380,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { ], $data->getData()); } - public function testAddLanguageWhenKnownReferenceProvided() { + public function testAddLanguageWhenKnownReferenceProvided(): void { $data = new I18nData($this->referenceData); $data->addLanguage('fr', 'en'); $this->assertEquals([ @@ -415,24 +417,24 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { ], $data->getData()); } - public function testIsKnownWhenKeyExists() { + public function testIsKnownWhenKeyExists(): void { $data = new I18nData($this->referenceData); $this->assertTrue($data->isKnown('file2.l1.l2.k2')); } - public function testIsKnownWhenKeyDoesNotExist() { + public function testIsKnownWhenKeyDoesNotExist(): void { $data = new I18nData($this->referenceData); $this->assertFalse($data->isKnown('file2.l1.l2.k3')); } - public function testAddKeyWhenKeyExists() { + public function testAddKeyWhenKeyExists(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('The selected key already exist.'); $data = new I18nData($this->referenceData); $data->addKey('file2.l1.l2.k1', 'value'); } - public function testAddKeyWhenParentKeyExists() { + public function testAddKeyWhenParentKeyExists(): void { $rawData = array_merge($this->referenceData, [ 'fr' => [], ]); @@ -447,7 +449,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { $this->assertTrue($data->isKnown('file2.l1.l2.k1.sk1')); } - public function testAddKeyWhenKeyIsParent() { + public function testAddKeyWhenKeyIsParent(): void { $rawData = array_merge($this->referenceData, [ 'fr' => [], ]); @@ -462,7 +464,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { $this->assertTrue($data->isKnown('file1.l1.l2.k2')); } - public function testAddKey() { + public function testAddKey(): void { $getTargetedValue = static function (I18nData $data, string $language) { return $data->getData()[$language]['file2.php']['file2.l1.l2.k3']; }; @@ -484,21 +486,21 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { $this->assertEquals($frValue, $enValue); } - public function testAddValueWhenLanguageDoesNotExist() { + public function testAddValueWhenLanguageDoesNotExist(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('The selected language does not exist.'); $data = new I18nData($this->referenceData); $data->addValue('file2.l1.l2.k2', 'new value', 'fr'); } - public function testAddValueWhenKeyDoesNotExist() { + public function testAddValueWhenKeyDoesNotExist(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('The selected key does not exist for the selected language.'); $data = new I18nData($this->referenceData); $data->addValue('unknown key', 'new value', 'en'); } - public function testAddValueWhenLanguageIsReferenceAndValueInOtherLanguageHasNotChange() { + public function testAddValueWhenLanguageIsReferenceAndValueInOtherLanguageHasNotChange(): void { $getTargetedValue = static function (I18nData $data, string $language) { return $data->getData()[$language]['file2.php']['file2.l1.l2.k2']; }; @@ -526,7 +528,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { $this->assertEquals('new value', $afterFrValue->getValue()); } - public function testAddValueWhenLanguageIsReferenceAndValueInOtherLanguageHasChange() { + public function testAddValueWhenLanguageIsReferenceAndValueInOtherLanguageHasChange(): void { $getTargetedValue = static function (I18nData $data, string $language) { return $data->getData()[$language]['file2.php']['file2.l1.l2.k2']; }; @@ -561,7 +563,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { $this->assertEquals($value, $afterFrValue); } - public function testAddValueWhenLanguageIsNotReference() { + public function testAddValueWhenLanguageIsNotReference(): void { $getTargetedValue = static function (I18nData $data, string $language) { return $data->getData()[$language]['file2.php']['file2.l1.l2.k2']; }; @@ -583,21 +585,21 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { $this->assertEquals('new value', $afterFrValue->getValue()); } - public function testRemoveKeyWhenKeyDoesNotExist() { + public function testRemoveKeyWhenKeyDoesNotExist(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('The selected key does not exist.'); $data = new I18nData($this->referenceData); $data->removeKey('Unknown key'); } - public function testRemoveKeyWhenKeyHasNoEmptySibling() { + public function testRemoveKeyWhenKeyHasNoEmptySibling(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('The selected key does not exist.'); $data = new I18nData($this->referenceData); $data->removeKey('file1.l1.l2'); } - public function testRemoveKeyWhenKeyIsEmptySibling() { + public function testRemoveKeyWhenKeyIsEmptySibling(): void { $rawData = array_merge($this->referenceData, [ 'fr' => [], ]); @@ -635,7 +637,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { ], $data->getData()); } - public function testRemoveKeyWhenKeyIsTheOnlyChild() { + public function testRemoveKeyWhenKeyIsTheOnlyChild(): void { $rawData = array_merge($this->referenceData, [ 'fr' => [], ]); @@ -673,7 +675,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { ], $data->getData()); } - public function testIgnore() { + public function testIgnore(): void { $value = $this->getMockBuilder(I18nValue::class) ->disableOriginalConstructor() ->getMock(); @@ -695,7 +697,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { $data->ignore('file1.l1.l2.k1', 'fr', false); } - public function testIgnoreUnmodified() { + public function testIgnoreUnmodified(): void { $value = $this->getMockBuilder(I18nValue::class) ->disableOriginalConstructor() ->getMock(); @@ -722,7 +724,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { $data->ignore_unmodified('fr', false); } - public function testGetLanguage() { + public function testGetLanguage(): void { $rawData = array_merge($this->referenceData, [ 'fr' => [], 'nl' => [], @@ -731,7 +733,7 @@ class I18nDataTest extends PHPUnit\Framework\TestCase { $this->assertEquals($this->referenceData['en'], $data->getLanguage('en')); } - public function testGetReferenceLanguage() { + public function testGetReferenceLanguage(): void { $rawData = array_merge($this->referenceData, [ 'fr' => [], 'nl' => [], diff --git a/tests/cli/i18n/I18nFileTest.php b/tests/cli/i18n/I18nFileTest.php index 26566ddf1..662c14608 100644 --- a/tests/cli/i18n/I18nFileTest.php +++ b/tests/cli/i18n/I18nFileTest.php @@ -3,7 +3,7 @@ require_once __DIR__ . '/../../../cli/i18n/I18nFile.php'; class I18nFileTest extends PHPUnit\Framework\TestCase { - public function test() { + public function test(): void { $before = $this->computeFilesHash(); $file = new I18nFile(); @@ -15,7 +15,8 @@ class I18nFileTest extends PHPUnit\Framework\TestCase { $this->assertEquals($before, $after); } - private function computeFilesHash() { + /** @return array<string,string> */ + private function computeFilesHash(): array { $hashes = []; $dirs = new DirectoryIterator(I18N_PATH); diff --git a/tests/cli/i18n/I18nUsageValidatorTest.php b/tests/cli/i18n/I18nUsageValidatorTest.php index 531e77c5d..fdd75bf64 100644 --- a/tests/cli/i18n/I18nUsageValidatorTest.php +++ b/tests/cli/i18n/I18nUsageValidatorTest.php @@ -4,6 +4,7 @@ require_once __DIR__ . '/../../../cli/i18n/I18nValue.php'; require_once __DIR__ . '/../../../cli/i18n/I18nUsageValidator.php'; class I18nUsageValidatorTest extends PHPUnit\Framework\TestCase { + /** @var I18nValue */ private $value; public function setUp(): void { @@ -12,7 +13,7 @@ class I18nUsageValidatorTest extends PHPUnit\Framework\TestCase { ->getMock(); } - public function testDisplayReport() { + public function testDisplayReport(): void { $validator = new I18nUsageValidator([], []); $this->assertEquals("There is no data.\n", $validator->displayReport()); @@ -40,13 +41,13 @@ class I18nUsageValidatorTest extends PHPUnit\Framework\TestCase { $validator->displayReport(); } - public function testValidateWhenNoData() { + public function testValidateWhenNoData(): void { $validator = new I18nUsageValidator([], []); $this->assertTrue($validator->validate()); $this->assertEquals('', $validator->displayResult()); } - public function testValidateWhenParentKeyExistsWithoutTransformation() { + public function testValidateWhenParentKeyExistsWithoutTransformation(): void { $validator = new I18nUsageValidator([ 'file1' => [ 'file1.l1.l2._' => $this->value, @@ -62,7 +63,7 @@ class I18nUsageValidatorTest extends PHPUnit\Framework\TestCase { $this->assertEquals('', $validator->displayResult()); } - public function testValidateWhenParentKeyExistsWithTransformation() { + public function testValidateWhenParentKeyExistsWithTransformation(): void { $validator = new I18nUsageValidator([ 'file1' => [ 'file1.l1.l2._' => $this->value, @@ -78,7 +79,7 @@ class I18nUsageValidatorTest extends PHPUnit\Framework\TestCase { $this->assertEquals('', $validator->displayResult()); } - public function testValidateWhenParentKeyDoesNotExist() { + public function testValidateWhenParentKeyDoesNotExist(): void { $validator = new I18nUsageValidator([ 'file1' => [ 'file1.l1.l2._' => $this->value, @@ -91,7 +92,7 @@ class I18nUsageValidatorTest extends PHPUnit\Framework\TestCase { $this->assertEquals("Unused key file1.l1.l2._ - \nUnused key file2.l1.l2._ - \n", $validator->displayResult()); } - public function testValidateWhenChildKeyExists() { + public function testValidateWhenChildKeyExists(): void { $validator = new I18nUsageValidator([ 'file1' => [ 'file1.l1.l2.k1' => $this->value, @@ -107,7 +108,7 @@ class I18nUsageValidatorTest extends PHPUnit\Framework\TestCase { $this->assertEquals('', $validator->displayResult()); } - public function testValidateWhenChildKeyDoesNotExist() { + public function testValidateWhenChildKeyDoesNotExist(): void { $validator = new I18nUsageValidator([ 'file1' => [ 'file1.l1.l2.k1' => $this->value, diff --git a/tests/cli/i18n/I18nValueTest.php b/tests/cli/i18n/I18nValueTest.php index cabc8e072..7a1109a20 100644 --- a/tests/cli/i18n/I18nValueTest.php +++ b/tests/cli/i18n/I18nValueTest.php @@ -3,35 +3,35 @@ require_once __DIR__ . '/../../../cli/i18n/I18nValue.php'; class I18nValueTest extends PHPUnit\Framework\TestCase { - public function testConstructorWithoutState() { + public function testConstructorWithoutState(): void { $value = new I18nValue('some value'); $this->assertEquals('some value', $value->getValue()); $this->assertFalse($value->isIgnore()); $this->assertFalse($value->isTodo()); } - public function testConstructorWithUnknownState() { + public function testConstructorWithUnknownState(): void { $value = new I18nValue('some value -> unknown'); $this->assertEquals('some value', $value->getValue()); $this->assertFalse($value->isIgnore()); $this->assertFalse($value->isTodo()); } - public function testConstructorWithTodoState() { + public function testConstructorWithTodoState(): void { $value = new I18nValue('some value -> todo'); $this->assertEquals('some value', $value->getValue()); $this->assertFalse($value->isIgnore()); $this->assertTrue($value->isTodo()); } - public function testConstructorWithIgnoreState() { + public function testConstructorWithIgnoreState(): void { $value = new I18nValue('some value -> ignore'); $this->assertEquals('some value', $value->getValue()); $this->assertTrue($value->isIgnore()); $this->assertFalse($value->isTodo()); } - public function testClone() { + public function testClone(): void { $value = new I18nValue('some value'); $clonedValue = clone $value; $this->assertEquals('some value', $value->getValue()); @@ -42,21 +42,21 @@ class I18nValueTest extends PHPUnit\Framework\TestCase { $this->assertTrue($clonedValue->isTodo()); } - public function testEqualWhenValueIsIdentical() { + public function testEqualWhenValueIsIdentical(): void { $value = new I18nValue('some value'); $clonedValue = clone $value; $this->assertTrue($value->equal($clonedValue)); $this->assertTrue($clonedValue->equal($value)); } - public function testEqualWhenValueIsDifferent() { + public function testEqualWhenValueIsDifferent(): void { $value = new I18nValue('some value'); $otherValue = new I18nValue('some other value'); $this->assertFalse($value->equal($otherValue)); $this->assertFalse($otherValue->equal($value)); } - public function testStates() { + public function testStates(): void { $reflectionProperty = new ReflectionProperty(I18nValue::class, 'state'); $reflectionProperty->setAccessible(true); @@ -74,7 +74,7 @@ class I18nValueTest extends PHPUnit\Framework\TestCase { $this->assertEquals('todo', $reflectionProperty->getValue($value)); } - public function testToString() { + public function testToString(): void { $value = new I18nValue('some value'); $this->assertEquals('some value', $value->__toString()); $value->markAsTodo(); diff --git a/tests/fixtures/migrations/2019_12_22_FooBar.php b/tests/fixtures/migrations/2019_12_22_FooBar.php index 4568ea8c9..21f673213 100644 --- a/tests/fixtures/migrations/2019_12_22_FooBar.php +++ b/tests/fixtures/migrations/2019_12_22_FooBar.php @@ -2,9 +2,9 @@ class FreshRSS_Migration_2019_12_22_FooBar { /** - * @return boolean true if the migration was successful, false otherwise + * @return bool true if the migration was successful, false otherwise */ - public static function migrate() { + public static function migrate(): bool { return true; } } diff --git a/tests/fixtures/migrations/2019_12_23_Baz.php b/tests/fixtures/migrations/2019_12_23_Baz.php index c13b2a814..056b0836c 100644 --- a/tests/fixtures/migrations/2019_12_23_Baz.php +++ b/tests/fixtures/migrations/2019_12_23_Baz.php @@ -2,9 +2,9 @@ class FreshRSS_Migration_2019_12_23_Baz { /** - * @return boolean true if the migration was successful, false otherwise + * @return bool true if the migration was successful, false otherwise */ - public static function migrate() { + public static function migrate(): bool { return true; } } diff --git a/tests/fixtures/migrations_with_failing/2020_01_11_FooBar.php b/tests/fixtures/migrations_with_failing/2020_01_11_FooBar.php index cdc2dd2c8..2edc79964 100644 --- a/tests/fixtures/migrations_with_failing/2020_01_11_FooBar.php +++ b/tests/fixtures/migrations_with_failing/2020_01_11_FooBar.php @@ -2,9 +2,9 @@ class FreshRSS_Migration_2020_01_11_FooBar { /** - * @return boolean true if the migration was successful, false otherwise + * @return bool true if the migration was successful, false otherwise */ - public static function migrate() { + public static function migrate(): bool { return true; } } diff --git a/tests/fixtures/migrations_with_failing/2020_01_12_Baz.php b/tests/fixtures/migrations_with_failing/2020_01_12_Baz.php index cd8ff10f3..75f39f7b5 100644 --- a/tests/fixtures/migrations_with_failing/2020_01_12_Baz.php +++ b/tests/fixtures/migrations_with_failing/2020_01_12_Baz.php @@ -2,9 +2,9 @@ class FreshRSS_Migration_2020_01_12_Baz { /** - * @return boolean true if the migration was successful, false otherwise + * @return bool true if the migration was successful, false otherwise */ - public static function migrate() { + public static function migrate(): bool { return false; } } diff --git a/tests/lib/CssXPath/CssXPathTest.php b/tests/lib/CssXPath/CssXPathTest.php index c6fe24fc8..8d5a943ec 100644 --- a/tests/lib/CssXPath/CssXPathTest.php +++ b/tests/lib/CssXPath/CssXPathTest.php @@ -2,7 +2,7 @@ class CssXPathTest extends PHPUnit\Framework\TestCase { - public function testCssXPathTranslatorClassExists() { + public function testCssXPathTranslatorClassExists(): void { $this->assertTrue(class_exists('Gt\\CssXPath\\Translator')); } } diff --git a/tests/lib/Minz/MigratorTest.php b/tests/lib/Minz/MigratorTest.php index bcee45204..bd30ba87e 100644 --- a/tests/lib/Minz/MigratorTest.php +++ b/tests/lib/Minz/MigratorTest.php @@ -4,7 +4,7 @@ use PHPUnit\Framework\TestCase; class MigratorTest extends TestCase { - public function testAddMigration() { + public function testAddMigration(): void { $migrator = new Minz_Migrator(); $migrator->addMigration('foo', function () { @@ -17,7 +17,7 @@ class MigratorTest extends TestCase $this->assertTrue($result); } - public function testAddMigrationFailsIfUncallableMigration() { + public function testAddMigrationFailsIfUncallableMigration(): void { $this->expectException(BadFunctionCallException::class); $this->expectExceptionMessage('foo migration cannot be called.'); @@ -25,7 +25,7 @@ class MigratorTest extends TestCase $migrator->addMigration('foo', null); } - public function testMigrationsIsSorted() { + public function testMigrationsIsSorted(): void { $migrator = new Minz_Migrator(); $migrator->addMigration('2_foo', function () { return true; @@ -43,7 +43,7 @@ class MigratorTest extends TestCase $this->assertSame($expected_versions, array_keys($migrations)); } - public function testSetAppliedVersions() { + public function testSetAppliedVersions(): void { $migrator = new Minz_Migrator(); $migrator->addMigration('foo', function () { return true; @@ -54,7 +54,7 @@ class MigratorTest extends TestCase $this->assertSame(['foo'], $migrator->appliedVersions()); } - public function testSetAppliedVersionsTrimArgument() { + public function testSetAppliedVersionsTrimArgument(): void { $migrator = new Minz_Migrator(); $migrator->addMigration('foo', function () { return true; @@ -65,7 +65,7 @@ class MigratorTest extends TestCase $this->assertSame(['foo'], $migrator->appliedVersions()); } - public function testSetAppliedVersionsFailsIfMigrationDoesNotExist() { + public function testSetAppliedVersionsFailsIfMigrationDoesNotExist(): void { $this->expectException(DomainException::class); $this->expectExceptionMessage('foo migration does not exist.'); @@ -74,7 +74,7 @@ class MigratorTest extends TestCase $migrator->setAppliedVersions(['foo']); } - public function testVersions() { + public function testVersions(): void { $migrator = new Minz_Migrator(); $migrator->addMigration('foo', function () { return true; @@ -88,7 +88,7 @@ class MigratorTest extends TestCase $this->assertSame(['bar', 'foo'], $versions); } - public function testMigrate() { + public function testMigrate(): void { $migrator = new Minz_Migrator(); $spy = false; $migrator->addMigration('foo', function () use (&$spy) { @@ -106,7 +106,7 @@ class MigratorTest extends TestCase ], $result); } - public function testMigrateCallsMigrationsInSortedOrder() { + public function testMigrateCallsMigrationsInSortedOrder(): void { $migrator = new Minz_Migrator(); $spy_foo_1_is_called = false; $migrator->addMigration('2_foo', function () use (&$spy_foo_1_is_called) { @@ -126,7 +126,7 @@ class MigratorTest extends TestCase ], $result); } - public function testMigrateDoesNotCallAppliedMigrations() { + public function testMigrateDoesNotCallAppliedMigrations(): void { $migrator = new Minz_Migrator(); $spy = false; $migrator->addMigration('1_foo', function () use (&$spy) { @@ -141,7 +141,7 @@ class MigratorTest extends TestCase $this->assertSame([], $result); } - public function testMigrateCallNonAppliedBetweenTwoApplied() { + public function testMigrateCallNonAppliedBetweenTwoApplied(): void { $migrator = new Minz_Migrator(); $migrator->addMigration('1_foo', function () { return true; @@ -162,7 +162,7 @@ class MigratorTest extends TestCase ], $result); } - public function testMigrateWithMigrationReturningFalseDoesNotApplyVersion() { + public function testMigrateWithMigrationReturningFalseDoesNotApplyVersion(): void { $migrator = new Minz_Migrator(); $migrator->addMigration('1_foo', function () { return true; @@ -180,7 +180,7 @@ class MigratorTest extends TestCase ], $result); } - public function testMigrateWithMigrationReturningFalseDoesNotExecuteNextMigrations() { + public function testMigrateWithMigrationReturningFalseDoesNotExecuteNextMigrations(): void { $migrator = new Minz_Migrator(); $migrator->addMigration('1_foo', function () { return false; @@ -200,7 +200,7 @@ class MigratorTest extends TestCase ], $result); } - public function testMigrateWithFailingMigration() { + public function testMigrateWithFailingMigration(): void { $migrator = new Minz_Migrator(); $migrator->addMigration('foo', function () { throw new \Exception('Oops, it failed.'); @@ -214,7 +214,7 @@ class MigratorTest extends TestCase ], $result); } - public function testUpToDate() { + public function testUpToDate(): void { $migrator = new Minz_Migrator(); $migrator->addMigration('foo', function () { return true; @@ -226,7 +226,7 @@ class MigratorTest extends TestCase $this->assertTrue($upToDate); } - public function testUpToDateIfRemainingMigration() { + public function testUpToDateIfRemainingMigration(): void { $migrator = new Minz_Migrator(); $migrator->addMigration('1_foo', function () { return true; @@ -241,7 +241,7 @@ class MigratorTest extends TestCase $this->assertFalse($upToDate); } - public function testUpToDateIfNoMigrations() { + public function testUpToDateIfNoMigrations(): void { $migrator = new Minz_Migrator(); $upToDate = $migrator->upToDate(); @@ -249,7 +249,7 @@ class MigratorTest extends TestCase $this->assertTrue($upToDate); } - public function testConstructorLoadsDirectory() { + public function testConstructorLoadsDirectory(): void { $migrations_path = TESTS_PATH . '/fixtures/migrations/'; $migrator = new Minz_Migrator($migrations_path); $expected_versions = ['2019_12_22_FooBar', '2019_12_23_Baz']; @@ -259,7 +259,7 @@ class MigratorTest extends TestCase $this->assertSame($expected_versions, array_keys($migrations)); } - public function testExecute() { + public function testExecute(): void { $migrations_path = TESTS_PATH . '/fixtures/migrations/'; $applied_migrations_path = tempnam('/tmp', 'applied_migrations.txt'); @@ -271,7 +271,7 @@ class MigratorTest extends TestCase @unlink($applied_migrations_path); } - public function testExecuteWithAlreadyAppliedMigration() { + public function testExecuteWithAlreadyAppliedMigration(): void { $migrations_path = TESTS_PATH . '/fixtures/migrations/'; $applied_migrations_path = tempnam('/tmp', 'applied_migrations.txt'); file_put_contents($applied_migrations_path, '2019_12_22_FooBar'); @@ -284,7 +284,7 @@ class MigratorTest extends TestCase @unlink($applied_migrations_path); } - public function testExecuteWithAppliedMigrationInDifferentOrder() { + public function testExecuteWithAppliedMigrationInDifferentOrder(): void { $migrations_path = TESTS_PATH . '/fixtures/migrations/'; $applied_migrations_path = tempnam('/tmp', 'applied_migrations.txt'); file_put_contents($applied_migrations_path, "2019_12_23_Baz\n2019_12_22_FooBar"); @@ -299,7 +299,7 @@ class MigratorTest extends TestCase @unlink($applied_migrations_path); } - public function testExecuteFailsIfVersionPathDoesNotExist() { + public function testExecuteFailsIfVersionPathDoesNotExist(): void { $migrations_path = TESTS_PATH . '/fixtures/migrations/'; $applied_migrations_path = tempnam('/tmp', 'applied_migrations.txt'); $expected_result = "Cannot open the {$applied_migrations_path} file"; @@ -311,7 +311,7 @@ class MigratorTest extends TestCase @unlink($applied_migrations_path); } - public function testExecuteFailsIfAMigrationIsFailing() { + public function testExecuteFailsIfAMigrationIsFailing(): void { $migrations_path = TESTS_PATH . '/fixtures/migrations_with_failing/'; $applied_migrations_path = tempnam('/tmp', 'applied_migrations.txt'); $expected_result = 'A migration failed to be applied, please see previous logs.'; diff --git a/tests/lib/PHPMailer/PHPMailerTest.php b/tests/lib/PHPMailer/PHPMailerTest.php index 8fc14b815..b39cf2cb0 100644 --- a/tests/lib/PHPMailer/PHPMailerTest.php +++ b/tests/lib/PHPMailer/PHPMailerTest.php @@ -2,7 +2,7 @@ class PHPMailerTest extends PHPUnit\Framework\TestCase { - public function testPHPMailerClassExists() { + public function testPHPMailerClassExists(): void { $this->assertTrue(class_exists('PHPMailer\\PHPMailer\\PHPMailer')); } } diff --git a/tests/phpstan-next.txt b/tests/phpstan-next.txt index 5b5b33e45..e2e081ecf 100644 --- a/tests/phpstan-next.txt +++ b/tests/phpstan-next.txt @@ -1,10 +1,48 @@ -# List of files, which are not yet passing PHPStan level 6 https://phpstan.org/user-guide/rule-levels -# https://github.com/FreshRSS/FreshRSS/issues/4112 +# List of files, which are not yet passing PHPStan level 7 https://phpstan.org/user-guide/rule-levels # Used for automated tests to avoid regressions in files already passing that level. # Can be regenerated with something like: -# find . -type d -name 'vendor' -prune -o -name '*.php' -exec sh -c 'vendor/bin/phpstan analyse --level 6 --memory-limit 512M {} >/dev/null 2>/dev/null || echo {}' \; +# find . -type d -name 'vendor' -prune -o -name '*.php' -exec sh -c 'vendor/bin/phpstan analyse --level 7 --memory-limit 512M {} >/dev/null 2>/dev/null || echo {}' \; -./app/install.php +./app/Controllers/configureController.php +./app/Controllers/feedController.php +./app/Controllers/importExportController.php +./app/Controllers/indexController.php +./app/Controllers/updateController.php +./app/Controllers/userController.php +./app/Models/CategoryDAO.php +./app/Models/Context.php +./app/Models/DatabaseDAO.php +./app/Models/DatabaseDAOPGSQL.php +./app/Models/Entry.php +./app/Models/EntryDAO.php ./app/Models/Feed.php +./app/Models/FeedDAO.php +./app/Models/ReadingMode.php +./app/Models/Search.php +./app/Models/Share.php +./app/Models/StatsDAO.php +./app/Models/TagDAO.php +./app/Models/Themes.php +./app/Models/UserQuery.php +./app/Services/ExportService.php ./app/Services/ImportService.php -./lib/Minz/Paginator.php +./app/views/helpers/logs_pagination.phtml +./app/views/index/reader.phtml +./app/views/stats/index.phtml +./app/views/stats/repartition.phtml +./app/views/user/details.phtml +./cli/check.translation.php +./cli/delete-user.php +./cli/do-install.php +./cli/manipulate.translation.php +./cli/user-info.php +./lib/lib_date.php +./lib/Minz/ActionController.php +./lib/Minz/Error.php +./lib/Minz/Mailer.php +./lib/Minz/Migrator.php +./lib/Minz/ModelPdo.php +./lib/Minz/Request.php +./p/api/greader.php +./tests/cli/i18n/I18nFileTest.php +./tests/lib/Minz/MigratorTest.php |
