2
提示我想测试一下这个方法:如何进行单元测试类型PHPUnit的
类:
public function bind(\Elastica\ResultSet $result = null) {
if (!$result instanceof \Elastica\ResultSet) {
throw new \InvalidArgumentException('I need an instance of \Elastica\ResultSet');
}
$this->bindedData = $result->getResults();
$this->isBinded = true;
}
测试
public function testGetTransformedDataNotSuccesful() {
$this->object->bind(new \stdClass()); //This throws a Catchable fatal error
}
我的问题是:
我如何测试这个?
另一种方法是不要键入提示方法var。
或者我不应该测试这个。
PHP会抛出异常而不是抛出致命错误吗?
对不起,我忘了这个。我会更新我的问题。 – MadeOfSport 2014-08-29 14:58:55
*更新了答案*问题保持不变。您强烈地键入\ Elastica \ ResultSet,但您传递了stdclass();还有什么应该发生:) – Hirnhamster 2014-08-29 15:03:18
我不知道。我希望PHP的抛出和异常不是一个可捕捉的致命错误或类似的东西。所以我的问题是 - 这是可测试的PHPUnit测试?你懂我的意思吗 ? – MadeOfSport 2014-08-29 15:06:34