Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8370709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:58:42+00:00 2026-06-09T13:58:42+00:00

Im aiming for very high code coverage and want to either cover exception classes

  • 0

Im aiming for very high code coverage and want to either cover exception classes or have them excluded from the codecoverage reports.

Example code

class My_DataException extends Exception
{}

class Foo
{
   function __construct() { throw new My_DataException('see?'); }
}

How can I either get code coverage on My_DataException (in library/My/DataException.php) or have the file excluded from appearing in the code coverage report? I’d prefer not to use the annotation method (@codeCoverageIgnore or something like that).

My phpunit.xml has a black list defined, and no whitelist

<filter>
    <blacklist>
        <directory suffix="Exception.php">../library/</directory>
    </blacklist>
</filter>

Every Exception file will end in “Exception.php” so im not sure why the suffix portion doesnt work.

Additional Details:

  • This is not a question about the right amount of coverage
  • I would prefer to not use the annotation method in each Exception file
  • Every Exception file will end in “Exception.php” eg. My/Exception.php or My/DataException.php
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:58:43+00:00Added an answer on June 9, 2026 at 1:58 pm

    For the following code:

    class Foo
    {
        function __construct() {
            throw new My_DataException('see?');
        }
    }s
    

    You will get code coverage if you execute that line in tests:

    new Foo;
    

    For such a test you can tell Phpunit which exception you expect with an annotation:

    /**
     * @expectedException My_DataException
     */
    

    However Exceptions are normally exceptions so you do not cover them but there can be in there for safety reasons too and you yet do not know how you can trigger them with test-setup / data / parameters.

    Then think harder and try to trigger them. Otherwise it might be that the code is superfluous because technically you are not able to throw the exception, hence it is not necessary.

    For the cases you know they can happen but you still can not trigger them (is that possible?) you can mark certain areas of your script to be excluded from coverage reporting in the source code:

    // @codeCoverageIgnoreStart
    throw new My_DataException('see?');
    // @codeCoverageIgnoreEnd
    

    Use it sparsely you might want to remove this in the future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very small animation I want to do by moving a view's
I am aiming for regex code to grab phone number and remove unneeded characters.
I am aiming to create a very basic web based DBMS for Microsoft SQL
I'm aiming to build up a JSON array of mouse positions and pass them
I don't really know how to describe what I'm aiming at (EDIT: I want
I have an activity, composed of an AsyncTask aiming to launch a request when
Turns out I am not explaining what I want to do very well so
I'm very new to using C#. If you have ever heard of the Karol
I'm VERY confused as to why this code Html.ActionLink(About, About, Home, new { hidefocus
I am aiming to create a .bat launcher that will execute a command line

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.