diff --git a/composer.json b/composer.json index 08d7ebc..afbd963 100644 --- a/composer.json +++ b/composer.json @@ -28,9 +28,9 @@ "mikey179/vfsstream": "^1.6", "opis/closure": "^3.6", "phpmd/phpmd": "^2.13", - "phpstan/phpstan": "^1.10", + "phpstan/phpstan": "^2", "phpunit/phpunit": "^11", - "rector/rector": "^1.0.0" + "rector/rector": "^2" }, "minimum-stability": "stable", "prefer-stable": true, diff --git a/tests/phpunit/Traits/ArrayTrait.php b/tests/phpunit/Traits/ArrayTrait.php index 293fd49..4834bda 100644 --- a/tests/phpunit/Traits/ArrayTrait.php +++ b/tests/phpunit/Traits/ArrayTrait.php @@ -8,6 +8,8 @@ * Trait ArrayTrait. * * Provides methods for working with arrays. + * + * @phpstan-ignore trait.unused */ trait ArrayTrait { diff --git a/tests/phpunit/Traits/AssertTrait.php b/tests/phpunit/Traits/AssertTrait.php index 2a214f9..072fb60 100644 --- a/tests/phpunit/Traits/AssertTrait.php +++ b/tests/phpunit/Traits/AssertTrait.php @@ -8,6 +8,8 @@ * Trait AssertTrait. * * Provides custom assertions. + * + * @phpstan-ignore trait.unused */ trait AssertTrait { diff --git a/tests/phpunit/Traits/ClosureWrapperTrait.php b/tests/phpunit/Traits/ClosureWrapperTrait.php index 1a5b491..f7e3f16 100644 --- a/tests/phpunit/Traits/ClosureWrapperTrait.php +++ b/tests/phpunit/Traits/ClosureWrapperTrait.php @@ -18,6 +18,8 @@ * fnw() stands for "function wrap" and fnu() stands for "function unwrap". * * @see https://github.com/sebastianbergmann/phpunit/issues/2739 + * + * @phpstan-ignore trait.unused */ trait ClosureWrapperTrait { diff --git a/tests/phpunit/Traits/EnvTrait.php b/tests/phpunit/Traits/EnvTrait.php index a150389..055dcb9 100644 --- a/tests/phpunit/Traits/EnvTrait.php +++ b/tests/phpunit/Traits/EnvTrait.php @@ -8,6 +8,8 @@ * Trait EnvTrait. * * Trait for managing environment variables. + * + * @phpstan-ignore trait.unused */ trait EnvTrait { diff --git a/tests/phpunit/Traits/MockTrait.php b/tests/phpunit/Traits/MockTrait.php index d1c974b..8e0e1c8 100644 --- a/tests/phpunit/Traits/MockTrait.php +++ b/tests/phpunit/Traits/MockTrait.php @@ -10,6 +10,8 @@ * Trait MockTrait. * * This trait provides a method to prepare class mock. + * + * @phpstan-ignore trait.unused */ trait MockTrait { @@ -32,7 +34,7 @@ trait MockTrait { * @SuppressWarnings("PHPMD.CyclomaticComplexity") */ protected function prepareMock(string $class, array $methods = [], array|bool $args = []): MockObject { - $methods = array_filter($methods, fn($value, $key): bool => is_string($key), ARRAY_FILTER_USE_BOTH); + $methods = array_filter($methods, fn($value, $key): bool => !is_numeric($key), ARRAY_FILTER_USE_BOTH); if (!class_exists($class)) { throw new \InvalidArgumentException(sprintf('Class %s does not exist', $class)); @@ -47,8 +49,11 @@ protected function prepareMock(string $class, array $methods = [], array|bool $a $builder->disableOriginalConstructor(); } - $method_names = array_filter(array_keys($methods), fn($method): bool => is_string($method) && !empty($method)); - $mock = $builder->onlyMethods($method_names)->getMock(); + $method_names = array_values(array_filter(array_keys($methods), fn($method): bool => !empty($method))); + if (!empty($method_names)) { + $builder->onlyMethods($method_names); + } + $mock = $builder->getMock(); foreach ($methods as $method => $value) { // Handle callback value differently based on its type. diff --git a/tests/phpunit/Traits/ReflectionTrait.php b/tests/phpunit/Traits/ReflectionTrait.php index 44e51c9..77dfffb 100644 --- a/tests/phpunit/Traits/ReflectionTrait.php +++ b/tests/phpunit/Traits/ReflectionTrait.php @@ -8,6 +8,8 @@ * Trait ReflectionTrait. * * Provides methods to work with class reflection. + * + * @phpstan-ignore trait.unused */ trait ReflectionTrait { diff --git a/tests/phpunit/Traits/VfsTrait.php b/tests/phpunit/Traits/VfsTrait.php index 58ed27a..250d4ed 100644 --- a/tests/phpunit/Traits/VfsTrait.php +++ b/tests/phpunit/Traits/VfsTrait.php @@ -10,6 +10,8 @@ * Trait VfsTrait. * * Provides methods for working with the virtual file system. + * + * @phpstan-ignore trait.unused */ trait VfsTrait { diff --git a/tests/phpunit/Unit/Command/JokeCommandTest.php b/tests/phpunit/Unit/Command/JokeCommandTest.php index 15101bc..ee83a90 100644 --- a/tests/phpunit/Unit/Command/JokeCommandTest.php +++ b/tests/phpunit/Unit/Command/JokeCommandTest.php @@ -24,6 +24,7 @@ class JokeCommandTest extends CommandTestCase { #[DataProvider('dataProviderExecute')] public function testExecute(string $content, int $expected_code, array|string $expected_output = []): void { /** @var \YourNamespace\App\Command\JokeCommand $mock */ + // @phpstan-ignore varTag.nativeType $mock = $this->prepareMock(JokeCommand::class, [ 'getContent' => $content, ]);