dkplus/unit-test

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (dev-master) of this package.

Zend Framework 2 Controller Unit Testing

dev-master 2012-10-09 23:16 UTC

This package is auto-updated.

Last update: 2019-02-20 19:59:26 UTC


README

Zend Framework 2 Controller Unit Testing

Supports mocking of request, response, event, routematch and plugins.

Controller:

<?php
namespace MyModule\Controller;

class IndexController
{
    public function indexAction()
    {
        $id = $this->getRequest()->getQuery('id');

        return array('id' => $id);
    }
}

TestCase:

<?php
namespace MyModuleTest\Controller;

use DkplusUnitTest\Controller\StandardTestCase;

class IndexControllerTest extends StandardTestCase
{
    private $controller;

    public function setUp()
    {
        $this->controller = \new MyModule\Controller\IndexController();
        $this->setUpController($this->controller);
    }

    public function testIndexActionReturnsIdFromQuery()
    {
        $this->setQueryData(array($id => 42));

        $result = $this->controller->indexAction();
        $this->assertEquals(42, $result['id']);
    }
}