Skip to content

Instantly share code, notes, and snippets.

@androa
Created February 1, 2011 15:16
Show Gist options
  • Save androa/805991 to your computer and use it in GitHub Desktop.
Save androa/805991 to your computer and use it in GitHub Desktop.
Testing both return value and E_NOTICE/E_USER_NOTICE
<?php
class ClassWithError {
public function multiplyByTen($value = 0) {
if (!$value) {
trigger_error('Value is missing', E_USER_NOTICE());
return false;
}
return $value * 10;
}
}
?>
I want to test both that it triggers an error and that it returns false.
Currently I'm doing this with two tests, one that expects the PHPUnit_Framework_Error_Notice
and one where I turn it of with PHPUnit_Framework_Error_Notice::$enabled = false while
asserting that the return value is false.
It works, but this will display the error message when running phpunit and it's not that pretty. Any better solutions?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment