An assertion follows the call that is expected to throw, so it never runs
What it finds
An assertion follows the call that is expected to throw, so it never runs
<?phpclass OrderTest extends TestCase{ public function testRejectsNegativeAmount(): void { $this->expectException(InvalidArgumentException::class); $order = $this->factory->make(-1); $this->assertNull($order);tx0 reports: this assertion never runs $this->assertSame(0, $this->factory->count()); } public function testThrowsInsideAssertion(): void { $this->expectException(InvalidArgumentException::class); $this->assertNull($this->factory->make(-1)); } public function testChecksBefore(): void { $this->assertSame(0, $this->factory->count()); $this->expectException(InvalidArgumentException::class); $this->factory->make(-1); } public function testFailingAssertion(): void { $this->expectException(AssertionFailedError::class); $value = compute(); $this->assertTrue($value); } public function testWithTry(): void { $this->expectException(InvalidArgumentException::class); try { $this->factory->make(-1); } finally { $this->cleaned = true; } $this->assertTrue($this->cleaned); }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/php:assertion-after-expected-exception" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/php:assertion-after-expected-exception] reason="..."tx0 explain tx0/php:assertion-after-expected-exception shows the same in the terminal. Found a false positive? Report it.