Skip to content

Detect risky PHPUnit test #264

@theofidry

Description

@theofidry

Feature request

In the following scenario:

function test_exception_state(): void {
  $myService = new MyService();

  try {
    $myService->doSomethingWrong();

    // missing: $this->fail();
  } catch (MyException $exception) {
    $this->assertSame('Custom message', $exception->getMessage());
    $this->assertSame('Another property', $exception->smthNotTypicalOfException);
  }
}

Essentially, a case where we want to do an explicit try/catch because expectExceptionObject() doesn't cut it (want to catch a Throwable instead of test some state of the exception besides message/code), it is easy to forget a fail() statement and leading to a risky test.

Maybe it leading as a risky is fine... But maybe it's a kinda of issue that PHPStan could detect & report. Just an idea.

Did PHPStan help you today? Did it make you happy in any way?

Today it did not help, but I didn't run it either so cannot blame it :) I like PHPStan otherwise!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions