1

I'm using PHPunit to test our Zend Framework project and it works allright but i'm not getting coverage om my action methods in my controllers.

Although I get coverage in number off lines of code but I want to have coverage on the functions/methods.

I see a lot of examples on the internet where they just do it like this:

class IndexTest extends Zend_Test_PHPUnit_ControllerTestCase
{
  public function testIndexAction() {
    $this->dispatch('/');
    $this->assertController('index');
    $this->assertAction('index');
    $this->assertXpath("//form[@action = '/index']");
  }
}

Which should work even if I look to this example from Jon:

http://www.zendcasts.com/unit-testing-with-the-zend-framework-with-zend_test-and-phpunit/2009/06/

http://code.google.com/p/zendcasts/source/browse/#svn/trunk/zc25-unit-testing

I'm doing it almost the exact way but it's not giving me any percentage of code coverage in functions, except for the init() function but I think that one is automaticly ignored by Zend Controller testcase.

I'm I doing something stupid or doesn't PHPUnit reconize it's calling this action? Using PHPUnit 3.5.14 and Zend Framework 1.11.x

5
  • Are you sure your function is actually getting called? Commented Nov 7, 2011 at 19:22
  • No that's the point, code coverage is saying indexAction is not called and therefor not covered but I can't find out why it says it's not called while other lines of code inside that function are covered? Commented Nov 7, 2011 at 19:50
  • What version of Xdebug are you running? Commented Nov 8, 2011 at 2:03
  • According to my phpinfo i'm running xdebug 2.1.0 Commented Nov 8, 2011 at 7:52
  • I figured out, it's a stupid mistake, because you need to cover all lines of a specific function in order to get 100% coverage for that method. Thanks anyway! Commented Nov 8, 2011 at 11:40

1 Answer 1

1

To get code coverage for a specific function from PHPunit you need to make sure every line of your function is called by your tests, so that every possible situation is taken care of and tested.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.