How to make PHP warnings fail PHPUnit test cases?
We have to add failOnWarning="true"
to treat such warnings as errors:
There was 1 warning:1) The data provider specified for Tests\CreateSomethingTest::testCreateSomething is invalid.FAILURES!Tests: 841, Assertions: 2493, Failures: 1, Errors: 0.
So our config looks like:
<phpunit convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnFailure="false" failOnWarning="true">
Make sure that options convert...ToExceptions
are set to true
. Unfortunately options are not available in command-line, so you have to create phpunit.xml
:
<?xml version="1.0" encoding="UTF-8"?><phpunit convertErrorsToExceptions = "true" convertNoticesToExceptions = "true" convertWarningsToExceptions = "true"></phpunit>