Skip to content

Commit

Permalink
Cover tests with Psalm and fix errors (#183)
Browse files Browse the repository at this point in the history
* Cover tests with Psalm and fix errors

* Allow missing files

* Fix UnusedProperty

* Actual fix plus no-cache
  • Loading branch information
chriszarate authored Oct 28, 2024
1 parent dfa0e8d commit 589820c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"scripts": {
"phpcs": "phpcs",
"phpcs-fix": "phpcbf",
"psalm": "psalm.phar",
"psalm": "psalm.phar --no-cache",
"test": "phpunit",
"test-coverage": "phpunit --coverage-clover ./coverage/phpunit/clover.xml"
},
Expand Down
18 changes: 14 additions & 4 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,26 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<file name="functions.php"/>
<file name="remote-data-blocks.php"/>
<directory name="inc/"/>
<file name="*.php"/>
<directory name="*"/>
<ignoreFiles allowMissingFiles="true">
<directory name="build/"/>
<directory name="example/"/>
<directory name="node_modules/"/>
<directory name="vendor/"/>
</ignoreFiles>
</projectFiles>
<issueHandlers>
<PossiblyUnusedReturnValue errorLevel="suppress"/>
<PossiblyUnusedMethod errorLevel="suppress"/>
<UnusedClass>
<errorLevel type="suppress">
<directory name="tests/" />
</errorLevel>
</UnusedClass>
</issueHandlers>
<stubs>
<file name="vendor/php-stubs/wordpress-stubs/wordpress-stubs.php"/>
<file name="remote-data-blocks.php"/>
</stubs>
</psalm>
</psalm>
2 changes: 0 additions & 2 deletions tests/inc/Config/QueryRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,6 @@ public function testExecuteSuccessfulResponseWithObjectResponseData() {
$response_body = $this->createMock( \Psr\Http\Message\StreamInterface::class );
$response = new Response( 200, [], $response_body );

$response = new Response( 200, [], $response_body );

$this->http_client->method( 'request' )->willReturn( $response );

$response_data = new \stdClass();
Expand Down
8 changes: 6 additions & 2 deletions tests/inc/Mocks/MockValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
use WP_Error;

class MockValidator implements ValidatorInterface {
/**
* @psalm-suppress UnusedProperty
*/
private array $schema;

private bool $should_pass;

/**
* Constructor.
*
* @param array $schema
*
* @param array $schema Validation schema.
* @param bool $should_pass Whether the validation should pass or fail.
*/
public function __construct( array $schema = [], bool $should_pass = true ) {
Expand Down
6 changes: 3 additions & 3 deletions tests/inc/stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function esc_html( string $text ): string {
return $text;
}

function register_block_pattern( string $name, array $options ): void {
function register_block_pattern( string $_name, array $_options ): void {
// Do nothing
}

Expand Down Expand Up @@ -99,7 +99,7 @@ function get_page_by_path( string $path ): string {
return $path ?? 'fake WP_Post';
}

function add_rewrite_rule( string $regex, string $target, string $position ): void {
function add_rewrite_rule( string $_regex, string $_target, string $_position ): void {
// Do nothing
}

Expand Down Expand Up @@ -181,7 +181,7 @@ public function get_error_messages( $code = '' ) {
// Return all messages if no code specified.
if ( empty( $code ) ) {
$all_messages = array();
foreach ( (array) $this->errors as $code => $messages ) {
foreach ( (array) $this->errors as $_code => $messages ) {
$all_messages = array_merge( $all_messages, $messages );
}

Expand Down

0 comments on commit 589820c

Please sign in to comment.