Zend Framework Testing Utils
PHP
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
library/DkplusUnitTest
README.md
autoload_classmap.php
autoload_function.php
autoload_register.php
composer.json

README.md

DkplusUnitTest

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']);
    }
}