Skip to content

Commit 589820c

Browse files
authored
Cover tests with Psalm and fix errors (#183)
* Cover tests with Psalm and fix errors * Allow missing files * Fix UnusedProperty * Actual fix plus no-cache
1 parent dfa0e8d commit 589820c

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"scripts": {
2424
"phpcs": "phpcs",
2525
"phpcs-fix": "phpcbf",
26-
"psalm": "psalm.phar",
26+
"psalm": "psalm.phar --no-cache",
2727
"test": "phpunit",
2828
"test-coverage": "phpunit --coverage-clover ./coverage/phpunit/clover.xml"
2929
},

psalm.xml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,26 @@
1111
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
1212
>
1313
<projectFiles>
14-
<file name="functions.php"/>
15-
<file name="remote-data-blocks.php"/>
16-
<directory name="inc/"/>
14+
<file name="*.php"/>
15+
<directory name="*"/>
16+
<ignoreFiles allowMissingFiles="true">
17+
<directory name="build/"/>
18+
<directory name="example/"/>
19+
<directory name="node_modules/"/>
20+
<directory name="vendor/"/>
21+
</ignoreFiles>
1722
</projectFiles>
1823
<issueHandlers>
1924
<PossiblyUnusedReturnValue errorLevel="suppress"/>
2025
<PossiblyUnusedMethod errorLevel="suppress"/>
26+
<UnusedClass>
27+
<errorLevel type="suppress">
28+
<directory name="tests/" />
29+
</errorLevel>
30+
</UnusedClass>
2131
</issueHandlers>
2232
<stubs>
2333
<file name="vendor/php-stubs/wordpress-stubs/wordpress-stubs.php"/>
2434
<file name="remote-data-blocks.php"/>
2535
</stubs>
26-
</psalm>
36+
</psalm>

tests/inc/Config/QueryRunnerTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,6 @@ public function testExecuteSuccessfulResponseWithObjectResponseData() {
358358
$response_body = $this->createMock( \Psr\Http\Message\StreamInterface::class );
359359
$response = new Response( 200, [], $response_body );
360360

361-
$response = new Response( 200, [], $response_body );
362-
363361
$this->http_client->method( 'request' )->willReturn( $response );
364362

365363
$response_data = new \stdClass();

tests/inc/Mocks/MockValidator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
use WP_Error;
77

88
class MockValidator implements ValidatorInterface {
9+
/**
10+
* @psalm-suppress UnusedProperty
11+
*/
912
private array $schema;
13+
1014
private bool $should_pass;
1115

1216
/**
1317
* Constructor.
14-
*
15-
* @param array $schema
18+
*
19+
* @param array $schema Validation schema.
1620
* @param bool $should_pass Whether the validation should pass or fail.
1721
*/
1822
public function __construct( array $schema = [], bool $should_pass = true ) {

tests/inc/stubs.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function esc_html( string $text ): string {
1717
return $text;
1818
}
1919

20-
function register_block_pattern( string $name, array $options ): void {
20+
function register_block_pattern( string $_name, array $_options ): void {
2121
// Do nothing
2222
}
2323

@@ -99,7 +99,7 @@ function get_page_by_path( string $path ): string {
9999
return $path ?? 'fake WP_Post';
100100
}
101101

102-
function add_rewrite_rule( string $regex, string $target, string $position ): void {
102+
function add_rewrite_rule( string $_regex, string $_target, string $_position ): void {
103103
// Do nothing
104104
}
105105

@@ -181,7 +181,7 @@ public function get_error_messages( $code = '' ) {
181181
// Return all messages if no code specified.
182182
if ( empty( $code ) ) {
183183
$all_messages = array();
184-
foreach ( (array) $this->errors as $code => $messages ) {
184+
foreach ( (array) $this->errors as $_code => $messages ) {
185185
$all_messages = array_merge( $all_messages, $messages );
186186
}
187187

0 commit comments

Comments
 (0)