Created
February 1, 2011 15:16
-
-
Save androa/805991 to your computer and use it in GitHub Desktop.
Testing both return value and E_NOTICE/E_USER_NOTICE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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