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 6901165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:38:20+00:00 2026-05-27T07:38:20+00:00

I’m working on a personal project for the learning experience, and also at the

  • 0

I’m working on a personal project for the learning experience, and also at the same time to implement a decent body of code. Part of this education, and making it a decent body of code, is unit testing. I have recently dived into PHPUnit and its code coverage tools.

I have encountered a situation with a particular implementation where the coding standard used causes code coverage to be lost. In this particular instance breaking the coding standard used causes a jump from 88% to 94% in code coverage.

In a method I have two lines that look like the following:

    // .. some data validation stuff
    trigger_error('Error validating the stuff', E_USER_WARNING);
}

The data validation and the stuff isn’t important here; the } is. Right now, when the unit test goes over this line of code, a PHPUnit_Framework_Error is thrown on the line before the }, since the code never actually continues on to the end of the brace, this line is never captured by code coverage.

If I do

    // .. some data validation stuff
    trigger_error('Error validating the stuff', E_USER_WARNING);}

I get a 6% jump in code coverage. I’ve tried setting PHPUnit_Framework_Error_Warning::$enabled to false, but then I get an ugly, expected, error message in my terminal, since I want this project to eventually be used by people other than myself, error messages on unit tests are unacceptable.

In addition, I really would like for my coding styles to be implemented consistently. The code-style violation would likely jump out upon further perusals of the code, meaning I’d also have to add a dreaded comment explaining why the braces were moved…likely in multiple places.

I guess my question(s) are:

  1. Is there a setting for PHPUnit that would allow the 1TBS to be used and still get covered by a test throwing an exception, or triggering an error, directly before a }?
  2. Is it more important to follow the coding standard or get a boost in code coverage? (Although the boost is really just the interpreter going over an extra })
  • 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-05-27T07:38:21+00:00Added an answer on May 27, 2026 at 7:38 am

    Don’t be obsessed with a number. You know that the numbers being reported are false and that you have more coverage than is being reported so why worry about it? It is more important that your tests cover all meaningful code than you achieve 100% code coverage.

    If you feel the coding standard is important, and this one looks to be, then don’t sacrifice readability for a number.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Does anyone know how can I replace this 2 symbol below from the string
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have some data like this: 1 2 3 4 5 9 2 6

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.