【发布时间】:2012-08-17 22:02:07
【问题描述】:
我在自定义命名空间中有一个抽象类Exception,它没有抽象方法。所有方法都显示在其测试中(以标准方式模拟)。使其抽象的原因并不重要。
然后我有大约 10 个类扩展 Exception 但不添加或覆盖任何方法、属性、常量等。很明显,它们都应该被覆盖,但它们显示为未完全覆盖.我阅读了文档并搜索了一段时间,但没有找到答案。
- PHP_CodeCoverage 1.1.3
- PHPUnit 3.6.12
- PHP 5.4.4
- Xdebug 2.2.1-5.4-vc9
虽然使用 @codeCoverageIgnore 注释是一种解决方案,但我想找出为什么会这样,而不是获得 100% 的覆盖率。
UPD:来源。
----------抽象类----------
namespace Jade\Core\Base;
abstract class Exception extends \Exception {
/**
* Additional info for exception
* @var array|null
*/
protected $info;
public function __construct($message, array $info = null, $code = 0, \Exception $previous = null) {
parent::__construct($message, $code, $previous);
$this->info = $info;
}
/**
* Get the Exception additional info
* @return mixed
*/
public function getInfo() {
return $this->info;
}
}
------------- 抽象类测试 ----------
class ExceptionTest extends \PHPUnit_Framework_TestCase {
/**
* @covers \Jade\Core\Base\Exception
*
* @group public
*/
public function testGetInfo() {
$info = array('info' => 'test');
$stub = $this->getMockForAbstractClass('\Jade\Core\Base\Exception', array('message', $info));
$this->assertEquals($info, $stub->getInfo());
}
/**
* @covers \Jade\Core\Base\Exception
*
* @group public
*/
public function testConstructWithDefaultInfo() {
$stub = $this->getMockForAbstractClass('\Jade\Core\Base\Exception', array('message'));
$this->assertEmpty($stub->getInfo());
}
}
---------- 扩展抽象类的类 ----------
namespace Jade\Core\Exceptions;
class Dict extends \Jade\Core\Base\Exception {
}
更新
重命名\Jade\Core\Base\Exception 以避免可能与\Exception 发生冲突并没有帮助(我尝试了\Jade\Core\Base\Ixception)。
使异常类成为常规类,而不是抽象类也没有帮助。
【问题讨论】:
-
您能否发布一个示例,说明哪些行显示为未覆盖?是类声明还是大括号?
-
感谢编辑,我添加了源代码和 CodeCoverage 输出。
-
是的,这是我的错。我尝试了声明以使其按预期工作并忘记撤消更改。我修复了它,覆盖问题没有解决。
标签: php phpunit abstract-class code-coverage xdebug