Skip to content

Treat assertNotWPError() and assertWPError() as type-narrowing functions #30

@johnbillion

Description

@johnbillion

In the WordPress core test suite the following assertion methods are available:

  • $this->assertNotWPError()
  • $this->assertWPError()

It would be great if this extension treated these methods as type-narrowing functions, so the following code would not throw an error in PHPStan:

$terms = wp_get_post_terms( $post_id, $taxonomy );
$this->assertNotWPError( $terms );
$this->assertCount( 0, $terms );

Currently this triggers the following error because $terms is assumed to be array|WP_Error on the last line.

[phpstan] Parameter #2 $haystack of method PHPUnit\Framework\Assert::assertCount() expects Countable|iterable, array|WP_Error given.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions