1
votes

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

1
Are you sure your function is actually getting called? - Ira Baxter
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? - Kees Schepers
What version of Xdebug are you running? - David Harkness
According to my phpinfo i'm running xdebug 2.1.0 - Kees Schepers
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! - Kees Schepers

1 Answers

1
votes

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.