【发布时间】:2013-06-17 11:04:08
【问题描述】:
Magento 有一个静态方法,可以在抛出异常之前进行一些额外的报告。
/**
* Throw Exception
*
* @param string $message
* @param string $messageStorage
* @throws Mage_Core_Exception
*/
public static function throwException($message, $messageStorage = null)
{
if ($messageStorage && ($storage = self::getSingleton($messageStorage))) {
$storage->addError($message);
}
throw new Mage_Core_Exception($message);
}
保证抛出异常,因此 PHPUnit 的代码覆盖将 Mage::throwException 语句后的右大括号视为未覆盖的代码,这有点烦人。
我查看了the PHPUnit documentation,但我没有看到任何非骇人听闻的方式让它考虑覆盖线。 (我考虑在方法 hacky 的末尾放置一个死代码 return 语句,或者实际上是我们每次使用 Mage::throwException 时必须做的任何事情。)
有什么方法可以教 PHPUnit Mage::throwException 总是 抛出一个异常,所以对待它(关于覆盖率)和 throw new WhateverException() 一样吗?
【问题讨论】:
-
除非this 有帮助,否则我认为你会坚持下去。
标签: php magento phpunit code-coverage