Skip to content
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
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
psalm:
name: Static analysis
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:

phpcs:
name: Code style
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -100,12 +100,16 @@ jobs:

tests:
name: Test on ${{matrix.php}} - ${{matrix.deps}} deps
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
continue-on-error: ${{matrix.php == '8.0'}}
strategy:
matrix:
php: ['7.4', '8.0', '8.1']
php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
deps: ['high', 'low', 'stable']
exclude:
# the lowest Psalm versions crash on PHP 8.4
- php: '8.4'
deps: 'low'
fail-fast: false
steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.4",
"vimeo/psalm": "^4.17.0 || dev-master || ^5.0.0 || ^6.0.0 || dev-master",
"phpunit/phpunit": "^9.5.20",
"vimeo/psalm": "^4.17.0 || ^5.0.0 || ^6.0.0 || ^7.0.0-rc1 || dev-master",
"phpunit/phpunit": "^9.5.20 || ^10.5 || ^11.5 || ^12.0",
"codeception/codeception": "^4.1.31 || ^5.0.0-rc3"
},
"scripts": {
Expand Down
35 changes: 12 additions & 23 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use PHPUnit\Framework\Assert;
use Behat\Gherkin\Node\TableNode;
use OutOfBoundsException;
use PHPUnit\Framework\SkippedTestError;
use RuntimeException;

use function is_array;
Expand Down Expand Up @@ -172,31 +171,27 @@ public function seeExitCode($exitCode): void

$exitCode = (int) $exitCode;

if ($this->exitCode === $exitCode) {
return;
}

Assert::fail("Expected exit code {$exitCode}, got {$this->exitCode}");
Assert::assertSame($exitCode, $this->exitCode, "Expected exit code {$exitCode}, got {$this->exitCode}");
}

public function seeThisError(string $type, string $message): void
{
$this->parseErrors();
if (empty($this->errors)) {
Assert::fail("No errors");
}
Assert::assertNotEmpty($this->errors, "No errors");

$matching = null;
foreach ($this->errors as $i => $error) {
if (
$this->matches($type, $error['type'])
&& $this->matches($message, $error['message'])
) {
unset($this->errors[$i]);
return;
$matching = $i;
break;
}
}

Assert::fail("Didn't see [ $type $message ] in: \n" . $this->remainingErrors());
Assert::assertNotNull($matching, "Didn't see [ $type $message ] in: \n" . $this->remainingErrors());
unset($this->errors[$matching]);
}

private function matches(string $expected, string $actual): bool
Expand All @@ -222,9 +217,7 @@ private function matches(string $expected, string $actual): bool
public function seeNoErrors(): void
{
$this->parseErrors();
if (!empty($this->errors)) {
Assert::fail("There were errors: \n" . $this->remainingErrors());
}
Assert::assertEmpty($this->errors, "There were errors: \n" . $this->remainingErrors());
}

private function packageSatisfiesVersionConstraint(string $package, string $versionConstraint): bool
Expand Down Expand Up @@ -304,8 +297,7 @@ public function seePsalmHasTaintAnalysis(): bool
public function havePsalmWithTaintAnalysis(): void
{
if (!$this->seePsalmHasTaintAnalysis()) {
/** @psalm-suppress InternalClass,InternalMethod */
throw new SkippedTestError("This scenario requires Psalm with taint analysis (3.10+)");
Assert::markTestSkipped("This scenario requires Psalm with taint analysis (3.10+)");
}
}

Expand Down Expand Up @@ -376,8 +368,7 @@ public function haveTheFollowingCode($code): void
*/
public function haveSomeFuturePsalmThatSupportsThisFeature(string $ref): void
{
/** @psalm-suppress InternalClass,InternalMethod */
throw new SkippedTestError("Future functionality that Psalm has yet to support: $ref");
Assert::markTestSkipped("Future functionality that Psalm has yet to support: $ref");
}

/**
Expand All @@ -396,8 +387,7 @@ public function havePsalmOfACertainVersionRangeBecauseOf(string $operator, strin
$op = (string) self::VERSION_OPERATORS[$operator];

if (!$this->packageSatisfiesVersionConstraint('vimeo/psalm', $op . $version)) {
/** @psalm-suppress InternalClass,InternalMethod */
throw new SkippedTestError("This scenario requires Psalm $op $version because of $reason");
Assert::markTestSkipped("This scenario requires Psalm $op $version because of $reason");
}
}

Expand Down Expand Up @@ -482,8 +472,7 @@ public function haveADependencySatisfied(string $package, string $versionConstra
return;
}

/** @psalm-suppress InternalClass,InternalMethod */
throw new SkippedTestError("This scenario requires $package to match $versionConstraint");
Assert::markTestSkipped("This scenario requires $package to match $versionConstraint");
}

/** @return non-empty-string */
Expand Down
6 changes: 3 additions & 3 deletions tests/acceptance/PsalmModule.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Feature: Psalm module
Given I have the following code preamble
"""
<?php
function takesFloat(float $_f): void {}
function takesFloat(float $f): void { echo $f; }
"""
# Psalm enables cache when there's a composer.lock file
And I have empty composer.lock
Expand Down Expand Up @@ -71,9 +71,9 @@ Feature: Psalm module
Scenario: Running Psalm with dead code detection
Given I have the following code
"""
class CD {
final class CD {
/** @return void */
private function m(int $p) {}
private function m(int $p) { echo "m"; }
}
"""
When I run Psalm with dead code detection
Expand Down
Loading