1

我有一个非常简单的控制器动作

<?php
namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class IndexController extends AbstractActionController {
    public function myAction() {
        return new ViewModel();
    }
}

并想测试它:

<?php
namespace ApplicationTest\Controller;

use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;

class IndexControllerTest extends AbstractHttpControllerTestCase
{
    public function setUp()
    {
        $this->setApplicationConfig(
            include '../../../config/application.config.php'
        );
        /*
        $test = $this->getApplicationConfig();
        print_r($test);
        die('~~~');
        */
        parent::setUp();
    }

    public function testIndexActionCanBeAccessed() {

        $this->dispatch('/my');
        $this->assertResponseStatusCode(200);

        $this->assertModuleName('Application');
        $this->assertControllerName('Application\Controller\Index');
        $this->assertControllerClass('IndexController');
        $this->assertMatchedRouteName('my');
    }
}

当我启动 PHPUnit 时,我得到这个错误:

1) ApplicationTest\Controller\IndexControllerTest::testIndexActionCanBeAccessed
Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for Zend\Db\Adapter\Adapter

/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:456
/path/to/project/module/Catalog/Module.php:56
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:737
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:869
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:494
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:441
/path/to/project/module/Catalog/Module.php:51
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:737
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:869
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:494
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:441
/path/to/project/module/Cache/Module.php:58
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:737
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:869
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:494
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:441
/path/to/project/module/Search/Module.php:61
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:737
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:869
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:494
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:441
/path/to/project/module/Search/Module.php:81
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:737
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/AbstractPluginManager.php:205
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:494
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:441
/path/to/project/vendor/zendframework/zendframework/library/Zend/ServiceManager/AbstractPluginManager.php:103
/path/to/project/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php:378
/path/to/project/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php:397
/path/to/project/module/Application/view/layout/layout.phtml:76
/path/to/project/module/Application/view/layout/layout.phtml:76
/path/to/project/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php:507
/path/to/project/vendor/zendframework/zendframework/library/Zend/View/View.php:205
/path/to/project/vendor/zendframework/zendframework/library/Zend/Mvc/View/Http/DefaultRenderingStrategy.php:126
/path/to/project/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:472
/path/to/project/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:207
/path/to/project/vendor/zendframework/zendframework/library/Zend/Mvc/View/Http/DefaultRenderingStrategy.php:136
/path/to/project/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:472
/path/to/project/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:207
/path/to/project/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:332
/path/to/project/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:307
/path/to/project/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:255
/path/to/project/module/Application/test/ApplicationTest/Controller/IndexControllerTest.php:37

为什么?我没有DbTable在此操作中使用我的课程。

4

0 回答 0