Zend framework2 自动加载在哪里?尝试单元测试

Zend framework2 自动加载在哪里?尝试单元测试,zend-framework2,Zend Framework2,我正在关注zend framework 2的入门,它建议使用测试,它建议: namespace ApplicationTest\Controller; use ApplicationTest\Bootstrap; use Zend\Mvc\Router\Http\TreeRouteStack as HttpRouter; use Application\Controller\IndexController; use Zend\Http\Request; use Zend\Http\Respon

我正在关注zend framework 2的入门,它建议使用测试,它建议:

namespace ApplicationTest\Controller;

use ApplicationTest\Bootstrap;
use Zend\Mvc\Router\Http\TreeRouteStack as HttpRouter;
use Application\Controller\IndexController;
use Zend\Http\Request;
use Zend\Http\Response;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\Router\RouteMatch;
use PHPUnit_Framework_TestCase;

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

    protected function setUp()
    {
        $serviceManager = Bootstrap::getServiceManager();
        $this->controller = new IndexController();
        $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);
        $this->controller->setServiceLocator($serviceManager);
    }
    public function testIndexActionCanBeAccessed()
    {
        $this->routeMatch->setParam('action', 'index');

        $result   = $this->controller->dispatch($this->request);
        $response = $this->controller->getResponse();

        $this->assertEquals(200, $response->getStatusCode());        

    }
}
如您所见,没有自动加载($class)


为了手动工作,我添加了
include“../../Bootstrap.php”它确实解决了问题,但我记得,一旦我能够使用此代码,并且教程似乎没有忘记一些概念上显而易见的东西,并且在主题评论中没有对此的反馈,可能我缺少了一些东西,上面的代码可能如何工作?

我设法让它工作,但注意到您无法使用phpUnit的扩展请求和响应对象。这些是早期2.0版本的说明。至少在2.0.7之后,指令会有很大不同,代码也会更清晰:


您是否按照说明中的指示在
zf2教程/module/Application/test
下创建了
phpunit.xml.dist
?据我所知,只要文件在同一个文件夹中,它就应该包括
Bootstrap.php
。是的,它就像教程建议的那样存在,如果你熟悉教程,我让它工作,继续教程到下一个测试(相册),但没有工作,我回到第一个测试,它不起作用,调试开始了:你现在的问题是什么?我一直在学习教程,它对我来说效果很好,尽管我确实因为没有认真学习而遇到了一些问题。@aydin:谢谢,但如果你建议我重做所有教程,那可能会奏效,但目标不是让它工作,(我不想要入门应用),目标是能够做项目。那时我将面临这样的问题,因为没有一步一步的教程。所以我会选择深入一点,试着survive@shampoo,而不是暗示。我只是问你的新问题是什么。我是说教程是按原样工作的。
<?php

namespace ApplicationTest\Controller;

use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;

class IndexControllerTest extends AbstractHttpControllerTestCase
{
    public function setUp()
    {
        $this->setApplicationConfig(
            include '/path/to/application/config/test/application.config.php'
        );
        parent::setUp();
    }

    public function testIndexActionCanBeAccessed()
    {
        $this->dispatch('/');
        $this->assertResponseStatusCode(200);

        $this->assertModuleName('application');
        $this->assertControllerName('application_index');
        $this->assertControllerClass('IndexController');
        $this->assertMatchedRouteName('home');
    }
}