Note that there are some explanatory texts on larger screens.

plurals
  1. POPHPUnit code coverage for class that extends abstract class
    text
    copied!<p>I have an abstract class <code>Exception</code> in custom namespace which has no abstract methods. All methods are shown as covered by its tests (mocked in a standard way). The reason to make it abstract is unimportant.</p> <p>Then I have about 10 classes that extend <code>Exception</code> but don't add or override any methods, properties, constants, etc. It is obvious that all of them should be covered too, but they are shown as not fully covered. I read the docs and googled for a while but didn't find the answer.</p> <ul> <li>PHP_CodeCoverage 1.1.3</li> <li>PHPUnit 3.6.12</li> <li>PHP 5.4.4</li> <li>Xdebug 2.2.1-5.4-vc9</li> </ul> <p>While annotating with <code>@codeCoverageIgnore</code> is a solution I want to find out why it happens this way rather then get 100% coverage.</p> <p>UPD: sources.</p> <p>------------- abstract class ----------</p> <pre><code>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-&gt;info = $info; } /** * Get the Exception additional info * @return mixed */ public function getInfo() { return $this-&gt;info; } } </code></pre> <p>------------- Tests for abstract class ----------</p> <pre><code>class ExceptionTest extends \PHPUnit_Framework_TestCase { /** * @covers \Jade\Core\Base\Exception * * @group public */ public function testGetInfo() { $info = array('info' =&gt; 'test'); $stub = $this-&gt;getMockForAbstractClass('\Jade\Core\Base\Exception', array('message', $info)); $this-&gt;assertEquals($info, $stub-&gt;getInfo()); } /** * @covers \Jade\Core\Base\Exception * * @group public */ public function testConstructWithDefaultInfo() { $stub = $this-&gt;getMockForAbstractClass('\Jade\Core\Base\Exception', array('message')); $this-&gt;assertEmpty($stub-&gt;getInfo()); } } </code></pre> <p>------------- class that extends abstract class ----------</p> <pre><code>namespace Jade\Core\Exceptions; class Dict extends \Jade\Core\Base\Exception { } </code></pre> <p><img src="https://i.stack.imgur.com/kHilQ.png" alt="Code coverage tool output"></p> <p><strong>Update</strong></p> <p>Renaming <code>\Jade\Core\Base\Exception</code> to avoid possible collision with \Exception didn't help (i tried <code>\Jade\Core\Base\Ixception</code>).</p> <p>Making Exception class a regular class, not abstract also didn't help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload