Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing Zend Framework 2 PHPUnit中缺少DbAdapter依赖项_Unit Testing_Controller_Dependencies_Phpunit_Zend Framework2 - Fatal编程技术网

Unit testing Zend Framework 2 PHPUnit中缺少DbAdapter依赖项

Unit testing Zend Framework 2 PHPUnit中缺少DbAdapter依赖项,unit-testing,controller,dependencies,phpunit,zend-framework2,Unit Testing,Controller,Dependencies,Phpunit,Zend Framework2,我有一个非常简单的控制器动作 <?php namespace Application\Controller; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; class IndexController extends AbstractActionController { public function myAction() { return new

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

<?php
namespace Application\Controller;

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

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

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

如果可以,请发布您的PHPUnit init文件、Bootstrap.php、PHPUnit.xml.dist和TestConfig.php.dist。
<?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');
    }
}
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