Problems with PHPUnit testing

Home Forums Learn ZF2 Problems with PHPUnit testing


This topic contains 5 replies, has 2 voices, and was last updated by  Slavey Karadzhov 3 years, 3 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #758

    I’m completed the chapter about Unit Testing (book pg 103), but am receiving the following error when I try to run the phpunit.xml as a phpUnit test:

    Fatal error: Call to undefined method UserTestControllerAccountControllerTest::dispach() in C:xampphtdocsZendProjectslearnzf2moduleUsertestsUserControllerAccountControllerTest.php on line 26

    Here is the code in the AccountControllerTest.php, and I have verified that the file exists. It won’t recognize my attempt to extend the AbstractHttpControllerTestCase, even though it doesn’t complain about the definition of AbstractHttpControllerTestCase just above it.

    namespace UserTestController;

    use ZendTestPHPUnitControllerAbstractHttpControllerTestCase;

    class AccountControllerTest extends AbstractHttpControllerTestCase
    protected $traceError = true;

    public function setUp()
    $this->setApplicationConfig(include __DIR__.’….configapplication.config.php’);

    public function testMeAction()
    // $application = $this->getApplication();
    // $serviceManager = $this->getServiceManager();
    // $eventManager = $this->getEventManager();

    // This is how the request object can be accessed and modified.
    // $request = $this->getRequest();

    // The dispatch method returns the result
    $result = $this->dispach(‘/user/account/me’);


    //This is how the response object can be accessed.
    // $response = $this->getResponse();

    //And here we can use the response to check the status code.
    // $this->assertEquals(200, $response->getStatusCode());

    I have created a githup if you need it.


    Slavey Karadzhov

    Hi wattp, please, tell me the URL of the github repo and I can take a look later this week. In addition what command (the exact syntax please) are you executing on your system and what version of PHPUnit is used?


    I am running the test through Zend Studio 12.5 by right clicking on the phpunit.xml file and selecting Run As->PHPUnit Test. I have PHPUnit and PHPUnit 4 installed (I’m trying to use PHPUnit 4, but it’s not giving me an option). I am on a Windows machine.


    OK, I figured out I was excluding the Test directory from my project, so that was causing the extend error from AbstractHttpControllerTestCase. However, I am still having the same error.


    After I re-included the Test directory, I realized that I misspelled dispatch, so never mind. I’ll post again here if I run into anything I can’t figure out. Bah.


    Slavey Karadzhov

    > I realized that I misspelled dispatch…
    > I’ll post again here if I run into anything I can’t figure out…
    Ok, no problem 🙂

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.