PHPUnit 约束扩展给出错误 "PHPUnit_Util_Type::export()" 未找到
PHPUnit constraints extension gives error "PHPUnit_Util_Type::export()" not found
我想要一个模拟对象,它可以告诉我是否:
- 当其中一个方法被调用时
- 传递给该方法的参数之一
- 是一个数组
- 并且有一对特定的 key/value。
我想用PHPUnit的约束来实现,所以我的测试代码是这样的:
$mock = $this->getMock('\Jodes\MyClass');
$mock->expects($this->once())
->method('myMethod')
->with(
$this->logicalAnd(
$this->isType('array'),
$this->arrayHasPair('my_key', 'my_value'),
)
);
// ... code here that should call the mock method
在this previous SO question中,这家伙最终写了自己的约束。
我发现 this library 似乎实现了很多漂亮的东西。所以我通过在 composer.json
的要求部分添加这一行来安装它:
"etsy/phpunit-extensions": "@stable"
但是当我尝试使用它时,出现错误。我是这样使用的:
class MyClassTest extends PHPUnit_Framework_TestCase {
public function arrayHasPair($key, $value){
return new PHPUnit_Extensions_Constraint_ArrayHasKeyValuePair($key, $value);
}
public function testmyMethod(){
// code as per my example above
}
}
但这会产生此错误:
PHP Fatal error: Call to undefined method PHPUnit_Util_Type::export() in C:\MyProject\vendor\etsy\phpunit-extensions\PHPUnit\Extensions\Constraint\ArrayHasKeyValuePair.php on line 50
This previous question/answer 解释了问题所在,但我不确定我应该怎么做。这是否意味着该库的开发人员已经放弃了它?有替代品吗?或者我有什么选择来修复它?我很惊讶在 PHPUnit 中仍然不存在这样的基本约束。显然我可以编写自己的约束条件,但这肯定是不必要的吗?
PHPUnit_Util_Type::export()
方法刚刚被删除。您要使用的扩展必须更新以与当前版本的 PHPUnit 兼容。
我想要一个模拟对象,它可以告诉我是否:
- 当其中一个方法被调用时
- 传递给该方法的参数之一
- 是一个数组
- 并且有一对特定的 key/value。
我想用PHPUnit的约束来实现,所以我的测试代码是这样的:
$mock = $this->getMock('\Jodes\MyClass');
$mock->expects($this->once())
->method('myMethod')
->with(
$this->logicalAnd(
$this->isType('array'),
$this->arrayHasPair('my_key', 'my_value'),
)
);
// ... code here that should call the mock method
在this previous SO question中,这家伙最终写了自己的约束。
我发现 this library 似乎实现了很多漂亮的东西。所以我通过在 composer.json
的要求部分添加这一行来安装它:
"etsy/phpunit-extensions": "@stable"
但是当我尝试使用它时,出现错误。我是这样使用的:
class MyClassTest extends PHPUnit_Framework_TestCase {
public function arrayHasPair($key, $value){
return new PHPUnit_Extensions_Constraint_ArrayHasKeyValuePair($key, $value);
}
public function testmyMethod(){
// code as per my example above
}
}
但这会产生此错误:
PHP Fatal error: Call to undefined method PHPUnit_Util_Type::export() in C:\MyProject\vendor\etsy\phpunit-extensions\PHPUnit\Extensions\Constraint\ArrayHasKeyValuePair.php on line 50
This previous question/answer 解释了问题所在,但我不确定我应该怎么做。这是否意味着该库的开发人员已经放弃了它?有替代品吗?或者我有什么选择来修复它?我很惊讶在 PHPUnit 中仍然不存在这样的基本约束。显然我可以编写自己的约束条件,但这肯定是不必要的吗?
PHPUnit_Util_Type::export()
方法刚刚被删除。您要使用的扩展必须更新以与当前版本的 PHPUnit 兼容。