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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:53:29+00:00 2026-05-24T19:53:29+00:00

I am writing a Zend Framework application and unit testing it with PHPUnit. In

  • 0

I am writing a Zend Framework application and unit testing it with PHPUnit. In general, things are going swimmingly however I have a small, but annoying issue with PHPUnit and code coverage – it sometimes tells me that a particular line is not tested, and I don’t know how to force it to be tested.

In the following code, for example, I launch two tests: one with a GET request, one with a POST request. The tests pass, and that’s all fine. When I look at the code coverage, however, it shows me that the ‘else’ line is not executed.

public function editAction()
{        
    if ($request->isPost()) {
        // do actions related to POST
    } else {
        // do action related to GET
    }
}

Any ideas? As a side issue, do you usually persevere with unit tests until you get 100% code coverage? Or is this not really practical?

Thanks muchly…

  • 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-24T19:53:30+00:00Added an answer on May 24, 2026 at 7:53 pm

    The code you have only comments for is what matters. The closing brace of a block will be shown as executable in the code coverage report if it’s possible to fall through to the end. Look for a branch that you aren’t actually testing.

    if ($request->isPost()) {
        if ($x < 5) {
            return '<';
        }
        elseif ($x > 5) {
            return '>';
        }
        // Do you have a test for $x == 5?
    }
    

    As for the 100% code coverage goal, I agree wholeheartedly with Bill. For some framework classes that I write I will strive to make 100%, but I know that doesn’t mean I’ve truly tested every possibility. Often, when I find myself working overly hard to achieve 100% coverage, it’s probably OCD kicking in. 🙂

    Just . . . one . . . more . . . test . . .

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

Sidebar

Related Questions

I'm writing some unit test with phpUnit to test a Zend Framework application and
I am used to writing unit tests in Zend Framework 1.9 using PHPUnit_Framework_TestCase for
I am building a Zend Framework application that performs jobs submitted by the user.
I'm writing an application that that I'm going to provide as a service and
Writing my first Linq application, and I'm trying to find the best way to
I am integrating third party code into the web application I am writing in
I'm interested in using Doctrine as an ORM for a new Zend Framework app
I am creating an MVC application framework, using only libararies and components that I
I am using the Zend Framework, and I use the .htaccess for some settings.
I set out writing a ZF (v1.10.3) application and chose to use Zend_Config_Ini to

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.