我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
)。
使 Exception 类成为常规类,而不是抽象类也没有帮助。