我已经构建了ZF2“入门”应用程序,并尝试将ZF2 UnitTesting 教程中的测试应用到它。现在我在这个简单的测试中遇到了麻烦:
[项目]/module/Album/test/AlbumTest/Controller/AlbumControllerTest.php
<?php
namespace AlbumTest\Controller;
...
class AlbumControllerTest extends AbstractHttpControllerTestCase
{
...
public function testIndexActionCanBeAccessed()
{
$this->dispatch('/album');
$this->assertResponseStatusCode(200);
$this->assertModuleName('Album');
$this->assertControllerName('Album\Controller\Album');
$this->assertControllerClass('AlbumController');
$this->assertMatchedRouteName('album');
}
}
命令行:/var/www/sandbox/zf2sandbox/module/Album/test/
# phpunit
PHPUnit 3.7.13 by Sebastian Bergmann.
Configuration read from /var/www/sandbox/zf2sandbox/module/Album/test/phpunit.xml
F....
Time: 0 seconds, Memory: 10.00Mb
There was 1 failure:
1) AlbumTest\Controller\AlbumControllerTest::testIndexActionCanBeAccessed
Failed asserting response code "200", actual status code is "500"
/var/www/sandbox/zf2sandbox/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:373
/var/www/sandbox/zf2sandbox/module/Album/test/AlbumTest/Controller/AlbumControllerTest.php:49
FAILURES!
Tests: 5, Assertions: 11, Failures: 1.
所以,assertResponseStatusCode(200)
失败了,因为状态码是500
。为什么?
当我在浏览器( http://zf2sandbox.sandbox.loc/album )中调用此路径时,它可以工作:
谢谢