I'm trying to test methods from the following class that I wrote (there are more functions than shown, basically one function for each is the _ * () method):
class Validate { private static $initialized = false; private function __construct() {} private static function initialize() { if(self::$initialized) { return; } else { self::$initialized = true;
When I check if methods generate an exception from invalid input, it works great! However, when I check if the method works, PHPUnit is expected to complain because I have no statements in the test. Specific error:
# RISKY This test did not perform any assertions
However, I have no meaning for the statement, so I'm not sure how to overcome this.
I read some about testing static methods, but mostly it deals with dependencies between static methods. In addition, even non-static methods cannot have a return value, so how can I fix this?
For reference, my test code is:
class ValidateTest extends PHPUnit_Framework_TestCase { public function testIsStringThrowsExceptionArgumentInvalid() { Validate::isString(NULL); } public function testIsStringNoExceptionArgumentValid() { Validate::isString("I am a string."); } }
php unit-testing phpunit
Matthew Herbst
source share