1
我已經構建了ZF2 "Getting Started" application,並試圖將ZF2 UnitTesting tutorial中的測試應用到它。現在我有這個簡單的測試一個麻煩:Zend Framework 2問題UnitTesting教程:狀態碼500
[項目] /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 /沙/ zf2sandbox /模塊/專輯/測試/
# 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)稱這條道路,它的工作原理:
THX
好吧,但我怎麼可能工作和返回狀態302沒有嘲笑?奇怪的行爲是在本地主機上它可以工作,但是當我在主機上運行相同的代碼時,我看到狀態500.可能是什麼原因? – 2015-06-24 06:08:01