For the following code:
class Foo { function __construct() { throw new My_DataException('see?'); } }s
You will get a coverage code if you follow this line in tests:
new Foo;
For such a test, you can specify the Phpunit that you expect with annotation:
However, Exceptions are usually exceptions, so you do not cover them, but you can also be there for security reasons, and you still do not know how you can run them using test settings / data / parameters.
Then think and try to call them. Otherwise, it may turn out that the code is superfluous, because technically you cannot throw an exception, therefore, this is not necessary.
In cases where you know that they can happen, but you still cannot activate them (is this possible?), You can mark certain areas of your script that should be excluded from the coverage report in the source code:
// @codeCoverageIgnoreStart throw new My_DataException('see?'); // @codeCoverageIgnoreEnd
Use it rarely, you can remove it in the future.
source share