You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just posting a tip here that we stumbled on in our CI flow.
Some PHP code is pretty tough to test. In our case it was an array() argument to usort() where the name of the class was misspelled. Testing did not find this error and a bad version went out on the staging servers where it luckily was caught by the users before put into production.
Checking the output from the phpunit tests it is quite obvious that the code is wrong - it generates output such as:
A PHP Error was encountered
Severity: Warning
Message: usort() expects parameter 2 to be a valid callback, class 'the_class_name' not found
Filename: C:\ci-project\application\libraries\the_class_name.php
Line Number: 276
However, the tests ran successfully report all clear.
The solution we now have implemented is to generate exceptions when runtime errors are encountered. In our setUp() and tearDown() we have now added the following code:
publicfunctionsetUp()
{
set_error_handler(function($errno, $errstr, $errfile, $errline) {
thrownewRuntimeException($errstr . " on line " . $errline . " in file " . $errfile);
});
$this->resetInstance();
}
publicfunctiontearDown()
{
parent::tearDown();
restore_error_handler();
}
Just a friendly reminder that testing may not find all problems in your code :-)
UPDATE: Just remember that you will need to add settings (convert*) to your phpunit.xml to generate exceptions:
Just posting a tip here that we stumbled on in our CI flow.
Some PHP code is pretty tough to test. In our case it was an array() argument to usort() where the name of the class was misspelled. Testing did not find this error and a bad version went out on the staging servers where it luckily was caught by the users before put into production.
Checking the output from the phpunit tests it is quite obvious that the code is wrong - it generates output such as:
However, the tests ran successfully report all clear.
The solution we now have implemented is to generate exceptions when runtime errors are encountered. In our setUp() and tearDown() we have now added the following code:
Just a friendly reminder that testing may not find all problems in your code :-)
UPDATE: Just remember that you will need to add settings (
convert*
) to your phpunit.xml to generate exceptions:The text was updated successfully, but these errors were encountered: