Make unittests strict
kiesel opened this issue · 1 comments
kiesel commented
Scope of Change
A new check will be introduced to the unittest.TestCase class that will assert
that no PHP notices have been produced while running a test.
Rationale
PHP notices often indicate some kind of defect in a software which is
not critical at first glance but can have a hidden impact whose source
then is hard to spot.
A recent test-run revealed some (real) bugs in XP core packages that went
unnoticed until now and which were found by checking the error stack.
Functionality
A new check will be performed after each test method run.
Note
Checks on the error registry are only performed when a test case does not
throw an exception.
Consider this:
<?php
if (!($exif= exif_read_data('/tmp/image.jpg'))) {
throw new FormatException('Cannot read EXIF data');
}
?>
- exif_read_data() will return FALSE which is checked and an exception
is thrown. A unittest will test for this behaviour using @expect e.g. - exif_read_data() will also emit a warning explaining why it couldn't
read the EXIF data. - This warning contains useful information, so it shouldn't be deleted
in the above example.
Security considerations
n/a
Speed impact
n/a
Dependencies
n/a
Related documents
- http://xp-framework.net/rfc/contrib/rfc0145.diff
Implementing patch
kiesel commented
Should this behavior be deactivateable by a @non-strict class annotation?
kiesel, Sun, 25 Nov 2007 12:40:06 +0100