diff --git a/admin/starter/tests/unit/HealthTest.php b/admin/starter/tests/unit/HealthTest.php index 1df24df823a7..bae45560b788 100644 --- a/admin/starter/tests/unit/HealthTest.php +++ b/admin/starter/tests/unit/HealthTest.php @@ -11,7 +11,7 @@ final class HealthTest extends CIUnitTestCase { public function testIsDefinedAppPath(): void { - $this->assertTrue(defined('APPPATH')); + $this->assertDirectoryExists(APPPATH); } public function testBaseUrlHasBeenSet(): void diff --git a/tests/system/CLI/CLITest.php b/tests/system/CLI/CLITest.php index 9391eae05d27..083f8792e31a 100644 --- a/tests/system/CLI/CLITest.php +++ b/tests/system/CLI/CLITest.php @@ -292,7 +292,10 @@ public function testColorSupportOnHyperTerminals(): void public function testStreamSupports(): void { $this->assertTrue(CLI::streamSupports('stream_isatty', STDOUT)); - $this->assertIsBool(CLI::streamSupports('sapi_windows_vt100_support', STDOUT)); + $this->assertSame( + function_exists('sapi_windows_vt100_support'), + CLI::streamSupports('sapi_windows_vt100_support', STDOUT), + ); } public function testColor(): void @@ -587,12 +590,12 @@ public function testWindow(): void $height = new ReflectionProperty(CLI::class, 'height'); $height->setValue(null, null); - $this->assertIsInt(CLI::getHeight()); + $this->assertGreaterThan(0, CLI::getHeight()); $width = new ReflectionProperty(CLI::class, 'width'); $width->setValue(null, null); - $this->assertIsInt(CLI::getWidth()); + $this->assertGreaterThan(0, CLI::getWidth()); } #[RequiresOperatingSystem('Darwin|Linux')] diff --git a/tests/system/CodeIgniterTest.php b/tests/system/CodeIgniterTest.php index e5d371bfb941..2d621f3b8703 100644 --- a/tests/system/CodeIgniterTest.php +++ b/tests/system/CodeIgniterTest.php @@ -984,7 +984,7 @@ public function testStartControllerPermitsInvoke(): void $startController(); // No PageNotFoundException - $this->assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testRouteAttributeCacheIntegration(): void diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index 83750c220bc4..3f970d72a154 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -773,7 +773,6 @@ public static function provideCleanPathActuallyCleaningThePaths(): iterable public function testIsCli(): void { - $this->assertIsBool(is_cli()); $this->assertTrue(is_cli()); } diff --git a/tests/system/Config/FactoriesTest.php b/tests/system/Config/FactoriesTest.php index 37077c41b1a5..eafde84857e6 100644 --- a/tests/system/Config/FactoriesTest.php +++ b/tests/system/Config/FactoriesTest.php @@ -439,7 +439,6 @@ public function testGetComponentInstances(): array $data = Factories::getComponentInstances('config'); - $this->assertIsArray($data); $this->assertArrayHasKey('aliases', $data); $this->assertArrayHasKey('instances', $data); @@ -469,7 +468,6 @@ public function testSetComponentInstances(array $data): array $data = Factories::getComponentInstances('config'); - $this->assertIsArray($data); $this->assertArrayHasKey('aliases', $data); $this->assertArrayHasKey('instances', $data); diff --git a/tests/system/Database/Live/UpdateTest.php b/tests/system/Database/Live/UpdateTest.php index e1fed75e660e..7f9ce90944ae 100644 --- a/tests/system/Database/Live/UpdateTest.php +++ b/tests/system/Database/Live/UpdateTest.php @@ -75,7 +75,7 @@ public function testUpdateSetsAllWithoutWhereAndLimit(): void } catch (DatabaseException) { // This DB doesn't support Where and Limit together // but we don't want it called a "Risky" test. - $this->assertTrue(true); + $this->expectNotToPerformAssertions(); } } @@ -110,7 +110,7 @@ public function testUpdateWithWhereAndLimit(): void } catch (DatabaseException) { // This DB doesn't support Where and Limit together // but we don't want it called a "Risky" test. - $this->assertTrue(true); + $this->expectNotToPerformAssertions(); } } diff --git a/tests/system/HTTP/CLIRequestTest.php b/tests/system/HTTP/CLIRequestTest.php index d12889448a30..91155e445f86 100644 --- a/tests/system/HTTP/CLIRequestTest.php +++ b/tests/system/HTTP/CLIRequestTest.php @@ -431,7 +431,6 @@ public function testFetchGlobalReturnsArrayValues(): void $result = $this->request->fetchGlobal('post'); $this->assertSame($post, $result); - $this->assertIsArray($result['ANNOUNCEMENTS']); $this->assertCount(2, $result['ANNOUNCEMENTS']); } diff --git a/tests/system/HTTP/RequestTest.php b/tests/system/HTTP/RequestTest.php index eb15506e6fdf..e1f70bdd272f 100644 --- a/tests/system/HTTP/RequestTest.php +++ b/tests/system/HTTP/RequestTest.php @@ -195,7 +195,6 @@ public function testFetchGlobalReturnsArrayValues(): void $result = $this->request->fetchGlobal('post'); $this->assertSame($post, $result); - $this->assertIsArray($result['ANNOUNCEMENTS']); $this->assertCount(2, $result['ANNOUNCEMENTS']); } diff --git a/tests/system/HTTP/URITest.php b/tests/system/HTTP/URITest.php index c449d13af65c..8f2941af82c5 100644 --- a/tests/system/HTTP/URITest.php +++ b/tests/system/HTTP/URITest.php @@ -1192,7 +1192,7 @@ public function testSetURISilent(): void $uri->setSilent()->setURI($url); - $this->assertTrue(true); + $this->expectNotToPerformAssertions(); } public function testCreateURIStringNoArguments(): void diff --git a/tests/system/Helpers/TextHelperTest.php b/tests/system/Helpers/TextHelperTest.php index a14c722816ae..212f2797bacf 100644 --- a/tests/system/Helpers/TextHelperTest.php +++ b/tests/system/Helpers/TextHelperTest.php @@ -130,8 +130,7 @@ public function testRandomString(): void $this->assertSame(16, strlen(random_string('numeric', 16))); $this->assertSame(8, strlen(random_string('numeric'))); - $this->assertSame(16, strlen($random = random_string('crypto', 16))); - $this->assertIsString($random); + $this->assertSame(16, strlen(random_string('crypto', 16))); } /** diff --git a/tests/system/HotReloader/DirectoryHasherTest.php b/tests/system/HotReloader/DirectoryHasherTest.php index a8a112ffe84b..8a0428465cea 100644 --- a/tests/system/HotReloader/DirectoryHasherTest.php +++ b/tests/system/HotReloader/DirectoryHasherTest.php @@ -62,7 +62,6 @@ public function testHashApp(): void $results = $this->hasher->hashApp(); - $this->assertIsArray($results); $this->assertArrayHasKey($this->fixtureDirectory, $results); } diff --git a/tests/system/Publisher/PublisherSupportTest.php b/tests/system/Publisher/PublisherSupportTest.php index 7e6e21e430d4..e432f9d21d6c 100644 --- a/tests/system/Publisher/PublisherSupportTest.php +++ b/tests/system/Publisher/PublisherSupportTest.php @@ -106,7 +106,6 @@ public function testGetScratch(): void $scratch = $publisher->getScratch(); - $this->assertIsString($scratch); $this->assertDirectoryExists($scratch); $this->assertDirectoryIsWritable($scratch); $this->assertNotNull($this->getPrivateProperty($publisher, 'scratch')); diff --git a/tests/system/Security/SecurityTest.php b/tests/system/Security/SecurityTest.php index 932dfc0df2c0..db80d91cbd92 100644 --- a/tests/system/Security/SecurityTest.php +++ b/tests/system/Security/SecurityTest.php @@ -350,11 +350,11 @@ public function testGetters(): void { $security = $this->createMockSecurity(); - $this->assertIsString($security->getHash()); - $this->assertIsString($security->getTokenName()); - $this->assertIsString($security->getHeaderName()); - $this->assertIsString($security->getCookieName()); - $this->assertIsBool($security->shouldRedirect()); + $this->assertSame(32, strlen($security->getHash())); + $this->assertSame('csrf_test_name', $security->getTokenName()); + $this->assertSame('X-CSRF-TOKEN', $security->getHeaderName()); + $this->assertSame('csrf_cookie_name', $security->getCookieName()); + $this->assertFalse($security->shouldRedirect()); } public function testGetPostedTokenReturnsTokenFromPost(): void diff --git a/tests/system/Test/FabricatorTest.php b/tests/system/Test/FabricatorTest.php index 46ab9441dd74..1c3609f29b14 100644 --- a/tests/system/Test/FabricatorTest.php +++ b/tests/system/Test/FabricatorTest.php @@ -128,8 +128,10 @@ public function testGetFakerReturnsUsableGenerator(): void $fabricator = new Fabricator(UserModel::class); $faker = $fabricator->getFaker(); + $digit = $faker->randomDigit(); - $this->assertIsNumeric($faker->randomDigit()); + $this->assertGreaterThanOrEqual(0, $digit); + $this->assertLessThanOrEqual(9, $digit); } public function testSetFormattersChangesFormatters(): void diff --git a/tests/system/Test/FilterTestTraitTest.php b/tests/system/Test/FilterTestTraitTest.php index ff74e029be31..3343be2e47a1 100644 --- a/tests/system/Test/FilterTestTraitTest.php +++ b/tests/system/Test/FilterTestTraitTest.php @@ -13,6 +13,7 @@ namespace CodeIgniter\Test; +use Closure; use CodeIgniter\HTTP\RequestInterface; use PHPUnit\Framework\Attributes\Group; use Tests\Support\Filters\Customfilter; @@ -53,8 +54,7 @@ public function testGetCallerReturnsClosure(): void { $caller = $this->getFilterCaller('test-customfilter', 'before'); - $this->assertIsCallable($caller); - $this->assertInstanceOf('Closure', $caller); + $this->assertInstanceOf(Closure::class, $caller); } public function testGetCallerInvalidPosition(): void diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 32ad4dacc2f5..c856a7ad19ee 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 1808 errors +# total 1786 errors includes: - argument.type.neon @@ -8,7 +8,6 @@ includes: - deadCode.unreachable.neon - empty.notAllowed.neon - function.resultUnused.neon - - method.alreadyNarrowedType.neon - method.childParameterType.neon - method.childReturnType.neon - method.notFound.neon diff --git a/utils/phpstan-baseline/method.alreadyNarrowedType.neon b/utils/phpstan-baseline/method.alreadyNarrowedType.neon deleted file mode 100644 index f3c373da1f4a..000000000000 --- a/utils/phpstan-baseline/method.alreadyNarrowedType.neon +++ /dev/null @@ -1,88 +0,0 @@ -# total 22 errors - -parameters: - ignoreErrors: - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with bool will always evaluate to true\.$#' - count: 1 - path: ../../admin/starter/tests/unit/HealthTest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsBool\(\) with bool will always evaluate to true\.$#' - count: 1 - path: ../../tests/system/CLI/CLITest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsInt\(\) with int will always evaluate to true\.$#' - count: 2 - path: ../../tests/system/CLI/CLITest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' - count: 1 - path: ../../tests/system/CodeIgniterTest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsBool\(\) with bool will always evaluate to true\.$#' - count: 1 - path: ../../tests/system/CommonFunctionsTest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array will always evaluate to true\.$#' - count: 2 - path: ../../tests/system/Config/FactoriesTest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' - count: 2 - path: ../../tests/system/Database/Live/UpdateTest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array\{1\: array\{DETAIL\: ''asdf''\}, 2\: array\{DETAIL\: ''sdfg''\}\} will always evaluate to true\.$#' - count: 1 - path: ../../tests/system/HTTP/CLIRequestTest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array\{1\: array\{DETAIL\: ''asdf''\}, 2\: array\{DETAIL\: ''sdfg''\}\} will always evaluate to true\.$#' - count: 1 - path: ../../tests/system/HTTP/RequestTest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' - count: 1 - path: ../../tests/system/HTTP/URITest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsString\(\) with string will always evaluate to true\.$#' - count: 1 - path: ../../tests/system/Helpers/TextHelperTest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array will always evaluate to true\.$#' - count: 1 - path: ../../tests/system/HotReloader/DirectoryHasherTest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsString\(\) with string will always evaluate to true\.$#' - count: 1 - path: ../../tests/system/Publisher/PublisherSupportTest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsBool\(\) with bool will always evaluate to true\.$#' - count: 1 - path: ../../tests/system/Security/SecurityTest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsString\(\) with string will always evaluate to true\.$#' - count: 3 - path: ../../tests/system/Security/SecurityTest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsNumeric\(\) with int will always evaluate to true\.$#' - count: 1 - path: ../../tests/system/Test/FabricatorTest.php - - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertIsCallable\(\) with Closure will always evaluate to true\.$#' - count: 1 - path: ../../tests/system/Test/FilterTestTraitTest.php