Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add psalm and PHP 8.3 to CI #9

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
- "8.0"
- "8.1"
- "8.2"
- "8.3"

steps:
- name: "Checkout"
Expand Down Expand Up @@ -52,5 +53,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"
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
21 changes: 21 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedCode="true"
findUnusedBaselineEntry="true"
>
<projectFiles>
<directory name="src" />
<directory name="tests" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
</psalm>
11 changes: 6 additions & 5 deletions src/ConsecutiveParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

trait ConsecutiveParams
{
/** @return list<Callback> */
/** @return \Generator<int, Callback> */
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 = [];
Expand All @@ -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);
Expand Down
9 changes: 1 addition & 8 deletions tests/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading