Skip to content

Commit 590235e

Browse files
committed
Enable Psalm static code analysis for PHPUnit tests
1 parent b12faec commit 590235e

File tree

7 files changed

+18
-3
lines changed

7 files changed

+18
-3
lines changed

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
"require-dev": {
3535
"php-parallel-lint/php-parallel-lint": "^1.2",
3636
"vimeo/psalm": "^4.5",
37+
"psalm/plugin-phpunit": "^0.15.1",
38+
"psalm/plugin-mockery": "^0.7.0",
3739
"phpunit/phpunit": "^8",
3840
"mockery/mockery": "^1.3",
3941
"symfony/yaml": "^4.4",

psalm.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@
2222
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
2323
>
2424
<projectFiles>
25-
<directory name="src" />
25+
<directory name="src"/>
26+
<directory name="tests"/>
2627
<ignoreFiles>
2728
<directory name="vendor" />
2829
</ignoreFiles>
2930
</projectFiles>
3031
<issueHandlers>
31-
<InternalClass errorLevel="suppress" />
32-
<InternalMethod errorLevel="suppress" />
32+
<InternalClass errorLevel="suppress"/>
33+
<InternalMethod errorLevel="suppress"/>
3334
</issueHandlers>
35+
<plugins>
36+
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
37+
<pluginClass class="Psalm\MockeryPlugin\Plugin"/>
38+
</plugins>
3439
</psalm>

tests/TestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ public function assertCallableThrowsNot(
146146
* method. It e.g. doesn't incorporates a Closure's scope, but works for
147147
* testing `PHPUnitThrowableAsserts`.
148148
*
149+
* @psalm-suppress RedundantCondition
150+
*
149151
* @param callable $callable the Callable to describe
150152
*
151153
* @return string string representation of the Callable

tests/Unit/CachedCallableProxyTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public function testSelfDescribing(
5252
}
5353

5454
/**
55+
* @psalm-suppress NullArgument
56+
*
5557
* @return array
5658
*/
5759
public function dataProviderSelfDescribing(): array

tests/Unit/CallableProxyTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public function testSelfDescribing(
5252
}
5353

5454
/**
55+
* @psalm-suppress NullArgument
56+
*
5557
* @return array
5658
*/
5759
public function dataProviderSelfDescribing(): array

tests/Unit/ThrowableAssertsTraitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public function testAssertCallableThrows(
9898
array $callableExceptionData
9999
): void {
100100
$callable = static function () use ($callableExceptionData) {
101+
/** @psalm-var class-string<Throwable> $className */
101102
$className = array_shift($callableExceptionData);
102103
throw new $className(...$callableExceptionData);
103104
};

tests/Utils/InvocableClass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function __construct(string $throwableClassName = null, ...$throwableArgu
5656
public function __invoke(...$arguments): array
5757
{
5858
if ($this->throwableClassName !== null) {
59+
/** @psalm-var class-string<Throwable> $className */
5960
$className = $this->throwableClassName;
6061
throw new $className(...$this->throwableArguments);
6162
}

0 commit comments

Comments
 (0)