如果我是正确的,SimpleTest将允许您断言
PHP错误被抛出.但是,根据文档,我无法弄清楚如何使用它.我想声明我传递给构造函数的对象是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); }
我哪里错了?
类型提示抛出E_RECOVERABLE_ERROR,自PHP版本5.2以来可以被SimpleTest捕获.以下将捕获包含文本“必须是实例”的任何错误. PatternExpectation的构造函数采用perl正则表达式.
public function testConstruct_ExpectsAnInstanceOfMyOtherObject() { $notAnObject = 'foobar'; $this->expectError(new PatternExpectation("/must be an instance of/i")); $object = new Object($notAnObject); }