From b849df080fc69e3e8e529f8dcc7be7999c723c1d Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Wed, 15 Nov 2023 11:31:11 +0800 Subject: [PATCH] refactor: Restructure test fixtures --- composer.json | 6 +++--- phpstan.neon.dist | 4 +--- tests/Rules/Classes/CacheHandlerInstantiationRuleTest.php | 2 +- .../Classes/FrameworkExceptionInstantiationRuleTest.php | 2 +- .../Classes => Rules/Classes/data}/cache-handler.php | 0 .../Classes/data}/framework-exception.php | 0 .../Functions/FactoriesFunctionArgumentTypeRuleTest.php | 6 +++--- .../NoClassConstFetchOnFactoriesFunctionsTest.php | 8 ++++---- .../Functions/ServicesFunctionArgumentTypeRuleTest.php | 2 +- .../Rules/Functions => Rules/Functions/data}/bug-8.php | 0 .../Rules/Functions => Rules/Functions/data}/bug-9.php | 0 tests/Rules/Superglobals/SuperglobalAccessRuleTest.php | 2 +- tests/Rules/Superglobals/SuperglobalAssignRuleTest.php | 2 +- .../Superglobals/data}/superglobal-access-cases.php | 0 .../Superglobals/data}/superglobal-assign-cases.php | 0 tests/Type/DynamicFunctionReturnTypeExtensionTest.php | 8 ++++---- tests/Type/DynamicMethodReturnTypeExtensionTest.php | 2 +- tests/{Fixtures/Type => Type/data}/BarModel.php | 0 tests/{Fixtures/Type => Type/data}/OtherServices.php | 0 tests/{Fixtures/Type => Type/data}/config.php | 0 tests/{Fixtures/Type => Type/data}/factories-in-tests.php | 0 tests/{Fixtures/Type => Type/data}/fake.php | 0 tests/{Fixtures/Type => Type/data}/model-find.php | 0 tests/{Fixtures/Type => Type/data}/model.php | 0 tests/{Fixtures/Type => Type/data}/services.php | 0 25 files changed, 21 insertions(+), 23 deletions(-) rename tests/{Fixtures/Rules/Classes => Rules/Classes/data}/cache-handler.php (100%) rename tests/{Fixtures/Rules/Classes => Rules/Classes/data}/framework-exception.php (100%) rename tests/{Fixtures/Rules/Functions => Rules/Functions/data}/bug-8.php (100%) rename tests/{Fixtures/Rules/Functions => Rules/Functions/data}/bug-9.php (100%) rename tests/{Fixtures/Rules/Superglobals => Rules/Superglobals/data}/superglobal-access-cases.php (100%) rename tests/{Fixtures/Rules/Superglobals => Rules/Superglobals/data}/superglobal-assign-cases.php (100%) rename tests/{Fixtures/Type => Type/data}/BarModel.php (100%) rename tests/{Fixtures/Type => Type/data}/OtherServices.php (100%) rename tests/{Fixtures/Type => Type/data}/config.php (100%) rename tests/{Fixtures/Type => Type/data}/factories-in-tests.php (100%) rename tests/{Fixtures/Type => Type/data}/fake.php (100%) rename tests/{Fixtures/Type => Type/data}/model-find.php (100%) rename tests/{Fixtures/Type => Type/data}/model.php (100%) rename tests/{Fixtures/Type => Type/data}/services.php (100%) diff --git a/composer.json b/composer.json index f96860f..e255300 100644 --- a/composer.json +++ b/composer.json @@ -46,9 +46,9 @@ } }, "autoload-dev": { - "psr-4": { - "CodeIgniter\\PHPStan\\Tests\\": "tests/" - } + "classmap": [ + "tests/" + ] }, "config": { "allow-plugins": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index dc6e02a..64f97f9 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -12,12 +12,10 @@ parameters: analyseAndScan: - src/ComposerJsonRewriter.php - src/ComposerScripts.php - - tests/Fixtures + - tests/*/data/* tmpDir: build/phpstan bootstrapFiles: - vendor/codeigniter4/framework/system/Test/bootstrap.php - scanDirectories: - - vendor/codeigniter4/framework/system/Helpers codeigniter: additionalModelNamespaces: - CodeIgniter\PHPStan\Tests\Fixtures\Type diff --git a/tests/Rules/Classes/CacheHandlerInstantiationRuleTest.php b/tests/Rules/Classes/CacheHandlerInstantiationRuleTest.php index a5a58bc..fb4e89c 100644 --- a/tests/Rules/Classes/CacheHandlerInstantiationRuleTest.php +++ b/tests/Rules/Classes/CacheHandlerInstantiationRuleTest.php @@ -36,7 +36,7 @@ protected function getRule(): Rule public function testRule(): void { - $this->analyse([__DIR__ . '/../../Fixtures/Rules/Classes/cache-handler.php'], [ + $this->analyse([__DIR__ . '/data/cache-handler.php'], [ [ 'Calling new FileHandler() directly is incomplete to get the cache instance.', 19, diff --git a/tests/Rules/Classes/FrameworkExceptionInstantiationRuleTest.php b/tests/Rules/Classes/FrameworkExceptionInstantiationRuleTest.php index 070239c..7c0e0a3 100644 --- a/tests/Rules/Classes/FrameworkExceptionInstantiationRuleTest.php +++ b/tests/Rules/Classes/FrameworkExceptionInstantiationRuleTest.php @@ -35,7 +35,7 @@ protected function getRule(): Rule public function testRule(): void { - $this->analyse([__DIR__ . '/../../Fixtures/Rules/Classes/framework-exception.php'], [ + $this->analyse([__DIR__ . '/data/framework-exception.php'], [ [ 'Instantiating FrameworkException using new is not allowed. Use one of its named constructors instead.', 17, diff --git a/tests/Fixtures/Rules/Classes/cache-handler.php b/tests/Rules/Classes/data/cache-handler.php similarity index 100% rename from tests/Fixtures/Rules/Classes/cache-handler.php rename to tests/Rules/Classes/data/cache-handler.php diff --git a/tests/Fixtures/Rules/Classes/framework-exception.php b/tests/Rules/Classes/data/framework-exception.php similarity index 100% rename from tests/Fixtures/Rules/Classes/framework-exception.php rename to tests/Rules/Classes/data/framework-exception.php diff --git a/tests/Rules/Functions/FactoriesFunctionArgumentTypeRuleTest.php b/tests/Rules/Functions/FactoriesFunctionArgumentTypeRuleTest.php index 10ca60e..7d2d232 100644 --- a/tests/Rules/Functions/FactoriesFunctionArgumentTypeRuleTest.php +++ b/tests/Rules/Functions/FactoriesFunctionArgumentTypeRuleTest.php @@ -54,8 +54,8 @@ protected function getRule(): Rule public function testRule(): void { $this->analyse([ - __DIR__ . '/../../Fixtures/Type/config.php', - __DIR__ . '/../../Fixtures/Type/model.php', + __DIR__ . '/../../Type/data/config.php', + __DIR__ . '/../../Type/data/model.php', ], [ [ 'Parameter #1 $name of function config expects a valid class string, \'bar\' given.', @@ -107,6 +107,6 @@ public function testRule(): void public function testAllowNonModelClassesOnModelCall(): void { $this->checkArgumentTypeOfModel = false; - $this->analyse([__DIR__ . '/../../Fixtures/Rules/Functions/bug-8.php'], []); + $this->analyse([__DIR__ . '/data/bug-8.php'], []); } } diff --git a/tests/Rules/Functions/NoClassConstFetchOnFactoriesFunctionsTest.php b/tests/Rules/Functions/NoClassConstFetchOnFactoriesFunctionsTest.php index cc5cbb6..9b4f022 100644 --- a/tests/Rules/Functions/NoClassConstFetchOnFactoriesFunctionsTest.php +++ b/tests/Rules/Functions/NoClassConstFetchOnFactoriesFunctionsTest.php @@ -41,9 +41,9 @@ protected function getRule(): Rule public function testRule(): void { $this->analyse([ - __DIR__ . '/../../Fixtures/Type/config.php', - __DIR__ . '/../../Fixtures/Type/factories-in-tests.php', - __DIR__ . '/../../Fixtures/Type/model.php', + __DIR__ . '/../../Type/data/config.php', + __DIR__ . '/../../Type/data/factories-in-tests.php', + __DIR__ . '/../../Type/data/model.php', ], [ [ 'Call to function config with CodeIgniter\Shield\Config\AuthJWT::class is discouraged.', @@ -65,6 +65,6 @@ public function testRule(): void public function testOnAppNamespaceWithNonAppCall(): void { - $this->analyse([__DIR__ . '/../../Fixtures/Rules/Functions/bug-9.php'], []); + $this->analyse([__DIR__ . '/data/bug-9.php'], []); } } diff --git a/tests/Rules/Functions/ServicesFunctionArgumentTypeRuleTest.php b/tests/Rules/Functions/ServicesFunctionArgumentTypeRuleTest.php index 17b9c33..43751ca 100644 --- a/tests/Rules/Functions/ServicesFunctionArgumentTypeRuleTest.php +++ b/tests/Rules/Functions/ServicesFunctionArgumentTypeRuleTest.php @@ -39,7 +39,7 @@ protected function getRule(): Rule public function testRule(): void { - $this->analyse([__DIR__ . '/../../Fixtures/Type/services.php'], [ + $this->analyse([__DIR__ . '/../../Type/data/services.php'], [ [ 'The method \'createRequest\' is reserved for service location internals and cannot be used as a service method.', 51, diff --git a/tests/Fixtures/Rules/Functions/bug-8.php b/tests/Rules/Functions/data/bug-8.php similarity index 100% rename from tests/Fixtures/Rules/Functions/bug-8.php rename to tests/Rules/Functions/data/bug-8.php diff --git a/tests/Fixtures/Rules/Functions/bug-9.php b/tests/Rules/Functions/data/bug-9.php similarity index 100% rename from tests/Fixtures/Rules/Functions/bug-9.php rename to tests/Rules/Functions/data/bug-9.php diff --git a/tests/Rules/Superglobals/SuperglobalAccessRuleTest.php b/tests/Rules/Superglobals/SuperglobalAccessRuleTest.php index 77dc1c2..bfc0801 100644 --- a/tests/Rules/Superglobals/SuperglobalAccessRuleTest.php +++ b/tests/Rules/Superglobals/SuperglobalAccessRuleTest.php @@ -37,7 +37,7 @@ protected function getRule(): Rule public function testRule(): void { - $this->analyse([__DIR__ . '/../../Fixtures/Rules/Superglobals/superglobal-access-cases.php'], [ + $this->analyse([__DIR__ . '/data/superglobal-access-cases.php'], [ [ 'Accessing offset \'foo\' directly on $_SERVER is discouraged.', 21, diff --git a/tests/Rules/Superglobals/SuperglobalAssignRuleTest.php b/tests/Rules/Superglobals/SuperglobalAssignRuleTest.php index 2e62ca6..957682c 100644 --- a/tests/Rules/Superglobals/SuperglobalAssignRuleTest.php +++ b/tests/Rules/Superglobals/SuperglobalAssignRuleTest.php @@ -37,7 +37,7 @@ protected function getRule(): Rule public function testRule(): void { - $this->analyse([__DIR__ . '/../../Fixtures/Rules/Superglobals/superglobal-assign-cases.php'], [ + $this->analyse([__DIR__ . '/data/superglobal-assign-cases.php'], [ [ 'Assigning \'https://localhost\' directly on offset \'HTTP_HOST\' of $_SERVER is discouraged.', 18, diff --git a/tests/Fixtures/Rules/Superglobals/superglobal-access-cases.php b/tests/Rules/Superglobals/data/superglobal-access-cases.php similarity index 100% rename from tests/Fixtures/Rules/Superglobals/superglobal-access-cases.php rename to tests/Rules/Superglobals/data/superglobal-access-cases.php diff --git a/tests/Fixtures/Rules/Superglobals/superglobal-assign-cases.php b/tests/Rules/Superglobals/data/superglobal-assign-cases.php similarity index 100% rename from tests/Fixtures/Rules/Superglobals/superglobal-assign-cases.php rename to tests/Rules/Superglobals/data/superglobal-assign-cases.php diff --git a/tests/Type/DynamicFunctionReturnTypeExtensionTest.php b/tests/Type/DynamicFunctionReturnTypeExtensionTest.php index 86ba30b..fc19615 100644 --- a/tests/Type/DynamicFunctionReturnTypeExtensionTest.php +++ b/tests/Type/DynamicFunctionReturnTypeExtensionTest.php @@ -37,12 +37,12 @@ public function testFileAsserts(string $assertType, string $file, mixed ...$args */ public static function provideFileAssertsCases(): iterable { - yield from self::gatherAssertTypes(__DIR__ . '/../Fixtures/Type/config.php'); + yield from self::gatherAssertTypes(__DIR__ . '/data/config.php'); - yield from self::gatherAssertTypes(__DIR__ . '/../Fixtures/Type/fake.php'); + yield from self::gatherAssertTypes(__DIR__ . '/data/fake.php'); - yield from self::gatherAssertTypes(__DIR__ . '/../Fixtures/Type/model.php'); + yield from self::gatherAssertTypes(__DIR__ . '/data/model.php'); - yield from self::gatherAssertTypes(__DIR__ . '/../Fixtures/Type/services.php'); + yield from self::gatherAssertTypes(__DIR__ . '/data/services.php'); } } diff --git a/tests/Type/DynamicMethodReturnTypeExtensionTest.php b/tests/Type/DynamicMethodReturnTypeExtensionTest.php index 62d4e91..deaa10c 100644 --- a/tests/Type/DynamicMethodReturnTypeExtensionTest.php +++ b/tests/Type/DynamicMethodReturnTypeExtensionTest.php @@ -37,6 +37,6 @@ public function testFileAsserts(string $assertType, string $file, mixed ...$args */ public static function provideFileAssertsCases(): iterable { - yield from self::gatherAssertTypes(__DIR__ . '/../Fixtures/Type/model-find.php'); + yield from self::gatherAssertTypes(__DIR__ . '/data/model-find.php'); } } diff --git a/tests/Fixtures/Type/BarModel.php b/tests/Type/data/BarModel.php similarity index 100% rename from tests/Fixtures/Type/BarModel.php rename to tests/Type/data/BarModel.php diff --git a/tests/Fixtures/Type/OtherServices.php b/tests/Type/data/OtherServices.php similarity index 100% rename from tests/Fixtures/Type/OtherServices.php rename to tests/Type/data/OtherServices.php diff --git a/tests/Fixtures/Type/config.php b/tests/Type/data/config.php similarity index 100% rename from tests/Fixtures/Type/config.php rename to tests/Type/data/config.php diff --git a/tests/Fixtures/Type/factories-in-tests.php b/tests/Type/data/factories-in-tests.php similarity index 100% rename from tests/Fixtures/Type/factories-in-tests.php rename to tests/Type/data/factories-in-tests.php diff --git a/tests/Fixtures/Type/fake.php b/tests/Type/data/fake.php similarity index 100% rename from tests/Fixtures/Type/fake.php rename to tests/Type/data/fake.php diff --git a/tests/Fixtures/Type/model-find.php b/tests/Type/data/model-find.php similarity index 100% rename from tests/Fixtures/Type/model-find.php rename to tests/Type/data/model-find.php diff --git a/tests/Fixtures/Type/model.php b/tests/Type/data/model.php similarity index 100% rename from tests/Fixtures/Type/model.php rename to tests/Type/data/model.php diff --git a/tests/Fixtures/Type/services.php b/tests/Type/data/services.php similarity index 100% rename from tests/Fixtures/Type/services.php rename to tests/Type/data/services.php