相关疑难解决方法(0)

简单的ZF2单元使用ZfcUser测试控制器

我在尝试对使用ZfcUser进行身份验证的操作进行单元测试时遇到问题.我需要一些方法来模拟ZfcUser Controller插件,但我不太确定如何做到这一点.我已成功地为表格和模型生成了一些单元测试,但是控制器需要大量注入的对象并导致问题.有谁知道如何设置ZfcUser模拟器来成功测试控制器?

这是我的测试(从ZF2教程复制):

<?php
namespace SmsTest\Controller;

use SmsTest\Bootstrap;
use Sms\Controller\SmsController;
use Zend\Http\Request;
use Zend\Http\Response;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\Router\RouteMatch;
use Zend\Mvc\Router\Http\TreeRouteStack as HttpRouter;
use PHPUnit_Framework_TestCase;

class SmsControllerTest extends PHPUnit_Framework_TestCase
{
    protected $controller;
    protected $request;
    protected $response;
    protected $routeMatch;
    protected $event;

    protected function setUp()
    {

        $serviceManager = Bootstrap::getServiceManager();

        $this->controller = new SmsController();
        $this->request    = new Request();
        $this->routeMatch = new RouteMatch(array('controller' => 'index'));
        $this->event      = new MvcEvent();
        $config = $serviceManager->get('Config');
        $routerConfig = isset($config['router']) ? $config['router'] : array();
        $router = HttpRouter::factory($routerConfig);
        $this->event->setRouter($router);
        $this->event->setRouteMatch($this->routeMatch);
        $this->controller->setEvent($this->event); …
Run Code Online (Sandbox Code Playgroud)

php phpunit unit-testing zend-framework2 zfcuser

8
推荐指数
1
解决办法
5203
查看次数

标签 统计

php ×1

phpunit ×1

unit-testing ×1

zend-framework2 ×1

zfcuser ×1