PHPUnit单元测试错误:ZF2 Doctrine

8
我刚刚开始使用Zend框架2和Doctrine。我想为我的专辑模块设置单元测试。 当我在命令提示符中运行“c:\ wamp \ www \ zf2-tutorial \ module \ Album \ test> phpunit”时,会出现以下错误:
PHPUnit 3.7.10 by Sebastian Bergmann.

Configuration read from C:\wamp\www\zf2-tutorial\module\Album\test\phpunit.xml.d
ist

.FFE

Time: 2 seconds, Memory: 8.25Mb

There was 1 error:

1) AlbumTest\Controller\AlbumControllerTest::testIndexActionCanBeAccessed
Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\Serv
iceManager::get was unable to fetch or create an instance for doctrine.entityman
ager.orm_default

C:\wamp\www\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Service
Manager\ServiceManager.php:452
C:\wamp\www\zf2-tutorial\module\Album\src\Album\Controller\AlbumController.php:2
5
C:\wamp\www\zf2-tutorial\module\Album\src\Album\Controller\AlbumController.php:3
3
C:\wamp\www\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Mvc\Con
troller\AbstractActionController.php:88
C:\wamp\www\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\EventMa
nager\EventManager.php:464
C:\wamp\www\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\EventMa
nager\EventManager.php:208
C:\wamp\www\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Mvc\Con
troller\AbstractController.php:107
C:\wamp\www\zf2-tutorial\module\Album\test\AlbumTest\Controller\AlbumControllerT
est.php:71

--


There were 2 failures:

1) AlbumTest\Controller\AlbumControllerTest::testDeleteActionCanBeAccessed
Failed asserting that 302 matches expected 200.

C:\wamp\www\zf2-tutorial\module\Album\test\AlbumTest\Controller\AlbumControllerT
est.php:54

2) AlbumTest\Controller\AlbumControllerTest::testEditActionCanBeAccessed
Failed asserting that 302 matches expected 200.

C:\wamp\www\zf2-tutorial\module\Album\test\AlbumTest\Controller\AlbumControllerT
est.php:64

FAILURES!
Tests: 4, Assertions: 3, Failures: 2, Errors: 1.

问题的根源似乎是:Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\ServiceManager::get无法获取或创建doctrine.entitymanager.orm_default实例。我不理解这个,请帮助!

你能看到网页应用程序吗?这可能是因为Doctrine没有正确安装或配置不正确的问题。 - Jurian Sluiman
谢谢您的回复Jurian。是的,Web应用程序运行良好,并且Doctrine也已正确安装。对于专辑模块,使用Doctrine的添加、编辑、列出和删除功能都能正常工作。 - Prashant
1个回答

19

好的,终于搞定了!! 我修改了位于 module/Album/test 目录下的 TestConfig.php.dist 文件。

<?php
return array(
    'modules' => array(
        'DoctrineModule',
        'DoctrineORMModule',
        'Album',
    ),
    'module_listener_options' => array(
        'config_glob_paths'    => array(
            '../../../config/autoload/{,*.}{global,local}.php',
        ),
        'module_paths' => array(
            'module',
            'vendor',
        ),
    ),
);

所以基本上只是添加了两个缺失的模块,DoctrineModule和DoctrineORMModule,然后phpunit命令没有显示任何错误!

希望能帮助其他人。


谢谢!我已经搜索了好几个小时了,终于成功了! - Chip Dean

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接