A test calls fail() inside a try whose catch swallows the failure, so the test cannot fail there
What it finds
A test calls fail() inside a try whose catch swallows the failure, so the test cannot fail there
<?phpnamespace App\Tests; use Exception;use PHPUnit\Framework\TestCase; class ParserTest extends TestCase{ public function testRejectsBadInput(): void { try { (new Parser())->parse('{'); $this->fail('no exception');tx0 reports: takes the failure that fail() throws } catch (Exception $e) { } try { (new Parser())->parse('['); self::fail('no exception');tx0 reports: takes the failure } catch (\Throwable) { $this->addToAssertionCount(1); } try { (new Parser())->parse('('); $this->fail('no exception'); } catch (ParseError $e) { } try { (new Parser())->parse(')'); $this->fail('no exception'); } catch (\Exception $e) { $this->assertInstanceOf(ParseError::class, $e); } try { (new Parser())->parse('<'); $this->fail('no exception'); } catch (\RuntimeException $e) { throw $e; } try { (new Parser())->parse('>'); $this->fail('no exception'); } catch (\App\Exception $e) { } try { (new Parser())->parse('!'); $this->fail(); } catch (ParseError $e) { $this->assertSame(1, $e->getLine()); } catch (\Exception) { $this->fail(); } }} class Helper{ public function run($test) { try { $test->fail('x'); } catch (\Exception $e) { } }} 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:phpunit-fail-caught" = "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:phpunit-fail-caught] reason="..."tx0 explain tx0/php:phpunit-fail-caught shows the same in the terminal. Found a false positive? Report it.