Markdown

[PHPUnit] Remaining deprecation notices (9)

PHPunit Warning
 Using a colon that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}" is deprecated since version 3.2 and will throw a ParseException in 4.0:

[eric_tu@localhost eric_tu]$ vendor/bin/phpunit  --coverage-html web/reports/
PHPUnit 5.7.20 by Sebastian Bergmann and contributors.

...................                                               19 / 19 (100%)

Time: 9.87 seconds, Memory: 36.50MB

OK (19 tests, 39 assertions)

Generating code coverage report in HTML format ... done

Remaining deprecation notices (9)

Using a colon that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}" is deprecated since version 3.2 and will throw a ParseException in 4.0: 9x
    9x in BankControllerTest::testRegisterAction from AppBundle\Entity

[eric_tu@localhost eric_tu]$ vendor/bin/phpunit  --coverage-html web/reports/
PHPUnit 5.7.20 by Sebastian Bergmann and contributors.

...................                                               19 / 19 (100%)

Time: 8.99 seconds, Memory: 37.25MB

OK (19 tests, 39 assertions)

Generating code coverage report in HTML format ... done


As Juhana commented you should first of all fix your code where the warning(s) appear. It’s a sign that the code is not working properly / strictly.
By default, PHPUnit converts PHP errors, warnings, and notices that are triggered during the execution of a test to an exception.
See Testing PHP Errors which has more information how to test for your warnings (and how to ignore warnings in sub-routines you call in tests).
To disable the default behaviour, you can tell PHPUnit to do so in your tests, e.g. within the setUp of your test or the test itself by setting a static variable in the global namespace:
#Warning:
PHPUnit_Framework_Error_Warning::$enabled = FALSE;
#notice, strict:
PHPUnit_Framework_Error_Notice::$enabled = FALSE;
Another option to change the default behaviour is to configure the testrunner with an XML file with the following settings:

</phpunit>
These three options are not available as command-line switches.
See as well the related question: test the return value of a method that triggers an error with PHPUnit.
shareimprove this answer
edited May 23 at 12:10
Community♦
11
answered Dec 7 '11 at 9:27
hakre
142k27245452
thank u it works with "# notice, strict: PHPUnit_Framework_Error_Notice::$enabled = FALSE; " – somu.web Dec 7 '11 at 9:54
2
I tried to use this to test some file operations with vfsStream. Disabling PHP_Unit exceptions did not work (needed because of some chmod() which are not supported). I have to after all use good old silence operator ‘@’. – Zap Dec 22 '11 at 19:32

留言