Problems with PHPUnit testing

Home Forums Learn ZF2 Problems with PHPUnit testing

Tagged: 

This topic contains 5 replies, has 2 voices, and was last updated by  Slavey Karadzhov 1 year, 11 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #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.

    <?php
    namespace UserTestController;

    use ZendTestPHPUnitControllerAbstractHttpControllerTestCase;

    class AccountControllerTest extends AbstractHttpControllerTestCase
    {
    protected $traceError = true;

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

    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->assertActionName(‘me’);
    $this->assertControllerName(‘UserControllerAccount’);

    //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.

    #759

    Slavey Karadzhov
    Participant

    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?

    #760

    https://github.com/pwatt9/learnzf2

    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.

    #761

    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.

    #762

    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.

    #763

    Slavey Karadzhov
    Participant

    > 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.