From 2148818b2c87391bb3c2235b44344d3fbf0cb500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Mon, 18 Dec 2023 12:54:04 +0100 Subject: [PATCH] Add psalm to CI --- .github/workflows/ci.yml | 3 +++ composer.json | 4 +++- psalm.xml | 21 +++++++++++++++++++++ src/ConsecutiveParams.php | 11 ++++++----- tests/BaseTest.php | 9 +-------- 5 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 psalm.xml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d49920c..a4bdb3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,5 +52,8 @@ jobs: - name: "PhpStan for tests" run: "vendor/bin/phpstan analyse --error-format=checkstyle tests --level=6 | cs2pr" + - name: "Psalm" + run: "vendor/bin/psalm --output-format=github --php-version=${{ matrix.php-version }}" + - name: "PHPUnit Test" run: "vendor/bin/phpunit tests/BaseTest.php" diff --git a/composer.json b/composer.json index cef47ef..d6a251b 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,9 @@ "require-dev": { "phpstan/phpstan": "^1.10", "symplify/easy-coding-standard": "^11.3", - "phpunit/phpunit": "^9|^10" + "phpunit/phpunit": "^9|^10", + "vimeo/psalm": "^5.18", + "psalm/plugin-phpunit": "^0.18" }, "autoload": { "psr-4": { diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..6cf4c00 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + diff --git a/src/ConsecutiveParams.php b/src/ConsecutiveParams.php index 9d8ae6e..083fbe9 100644 --- a/src/ConsecutiveParams.php +++ b/src/ConsecutiveParams.php @@ -12,14 +12,14 @@ trait ConsecutiveParams { - /** @return list */ + /** @return \Generator */ public static function withConsecutive(array $firstCallArguments, array ...$consecutiveCallsArguments): iterable { foreach ($consecutiveCallsArguments as $consecutiveCallArguments) { TestCase::assertSameSize($firstCallArguments, $consecutiveCallArguments, 'Each expected arguments list need to have the same size.'); } - $allConsecutiveCallsArguments = [$firstCallArguments, ...$consecutiveCallsArguments]; + $allConsecutiveCallsArguments = [$firstCallArguments, ...array_values($consecutiveCallsArguments)]; $numberOfArguments = count($firstCallArguments); $argumentList = []; @@ -29,10 +29,11 @@ public static function withConsecutive(array $firstCallArguments, array ...$cons $mockedMethodCall = 0; $callbackCall = 0; - foreach ($argumentList as $index => $argument) { + foreach ($argumentList as $argument) { yield new Callback( - static function ($actualArgument) use ($argumentList, &$mockedMethodCall, &$callbackCall, $index, $numberOfArguments): bool { - $expected = $argumentList[$index][$mockedMethodCall] ?? null; + static function ($actualArgument) use (&$mockedMethodCall, &$callbackCall, $argument, $numberOfArguments): bool { + /** @var mixed $expected */ + $expected = $argument[$mockedMethodCall] ?? null; ++$callbackCall; $mockedMethodCall = (int) ($callbackCall / $numberOfArguments); diff --git a/tests/BaseTest.php b/tests/BaseTest.php index bf1d718..007ee43 100644 --- a/tests/BaseTest.php +++ b/tests/BaseTest.php @@ -9,20 +9,13 @@ final class TestableClass { - public function foo(object $testClass): void + public function foo(InputInterface $testClass): void { $testClass->setSomething(1); $testClass->setSomething(2); } } -final class InputClass implements InputInterface -{ - public function setSomething(int $i): void - { - } -} - interface InputInterface { public function setSomething(int $i): void;