2
我有这书上的代码工作,我不能让它在PHPUnit 4.3assertAttributeEqual不适用于私有属性
class Foo {
protected $message;
protected function bar($environment) {
$this->message = "PROTECTED BAR";
if($environment == 'dev') {
$this->message = 'CANDY BAR';
}
}
}
class FooTest extends PHPUnit_Framework_TestCase {
public function testProtectedBar() {
$expectedMessage = 'PROTECTED BAR';
$reflectedFoo = new ReflectionMethod('Foo', 'bar');
$reflectedFoo->setAccessible(true);
$reflectedFoo->invoke(new Foo(), 'production');
$this->assertAttributeEquals(
$expectedMessage,
'message',
$reflectedFoo,
'Did not get expected message'
);
}
}
通过运行PHPUnit之后,我得到'PHPUnit_Framework_Exception: Attribute "message" not found in object.'
这是奇怪的,或者API可能在4.3中改变了?
对不起,只是复制和粘贴你的代码,它仍然是一样的错误。 – Zed 2014-11-09 07:52:12
刚刚添加了公共属性,并且错误消息是相同的:“在对象中找不到”属性“xxx”。“ – Zed 2014-11-09 08:50:56