【问题标题】:Can I teach PHPUnit that Mage::throwException *always* throws an exception?我可以教 PHPUnit Mage::throwException *always* 抛出异常吗?
【发布时间】: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


【解决方案1】:

我也有这个问题。

只要做:

throw Mage::getException(...);

并在 getException 中返回异常对象。否则你会被它困住。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 1970-01-01
    • 2011-08-06
    • 2017-10-06
    相关资源
    最近更新 更多