【问题标题】:phpunit unit testing error zf2 doctrinephpunit单元测试错误zf2教义
【发布时间】:2012-12-26 16:42:41
【问题描述】:

我刚刚开始使用 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\Serv iceManager::get 无法获取或创建教义.entityman 的实例 ager.orm_default 来自测试..

我不明白,请帮忙!

【问题讨论】:

  • 你能看到webapp吗?这可能是一个问题,因为 Doctrine 没有正确安装或配置不正确。
  • 感谢朱里安的回复。是的,webapp 运行良好,并且 Doctrine 也已正确安装。添加、编辑、列出和删除功能在 Doctrine for Album 模块中运行良好。

标签: unit-testing doctrine-orm zend-framework2


【解决方案1】:

好的,终于明白了!! 我将 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 命令显示没有错误!

希望对他人有所帮助。

【讨论】:

  • 谢谢!!我一直在寻找几个小时。终于成功了!
猜你喜欢
  • 2014-11-06
  • 2014-05-18
  • 2015-03-24
  • 1970-01-01
  • 2015-04-22
  • 2013-01-25
  • 2014-06-22
  • 2010-11-14
  • 1970-01-01
相关资源
最近更新 更多