I have an assertion in my code. Something like:
assert('is_string($var)');
If I write a test for PHPUnit that causes this assertion to fail with the message, Warning: assert(): Assertion "is_string($var)" failed in /path/to/file.php on line ###
And, my test also fails. I’ve tried adding @expectedException PHPUnit_Framework_Error_Warning to the docblock according to the documentation, but that doesn’t help. What do I need to do to make my test expect that this assertion will fail?
From php.net/assert:
So for normal code logic, use a boolean or some pre-defined constants. For exceptional logic use normal
ifstatements and throw anExceptionfor invalid input.If you are really keen on keeping the asserts, you could define an assert callback which throws an
Exceptionyou can catch in PHPUnit.