If I am correct, SimpleTest will allow you to assert a PHP error is thrown. However, I can’t figure out how to use it, based on the documentation. I want to assert that the object I pass into my constructor is an instance of MyOtherObject
class Object { public function __construct(MyOtherObject $object) { //do something with $object } } //...and in my test I have... public function testConstruct_ExpectsAnInstanceOfMyOtherObject() { $notAnObject = 'foobar'; $object = new Object($notAnObject); $this->expectError($object); }
Where am I going wrong?
Type hinting throws E_RECOVERABLE_ERROR which can be caught by SimpleTest since PHP version 5.2. The following will catch any error containing the text ‘must be an instance of’. The constructor of PatternExpectation takes a perl regex.