問題在「Getting Started with Zend Framework 2」教程中,有一個應用程序的基本單元測試示例:http://zf2.readthedocs.org/en/latest/user-guide/unit-testing.html我剛剛複製了代碼(只需更改include __DIR__ . '/../init_autoloader.php';
到include __DIR__ . '/../../../init_autoloader.php';
),現在我發現了一個錯誤:ZF2快速入門教程和PHPUnit
[email protected]:/var/www/sandbox/zf2sandbox/module/Application/test# phpunit
PHPUnit 3.7.13 by Sebastian Bergmann.
Configuration read from /var/www/sandbox/zf2sandbox/module/Application/test/phpunit.xml
E
Time: 0 seconds, Memory: 3.75Mb
There was 1 error:
1) ApplicationTest\Controller\IndexControllerTest::testIndexActionCanBeAccessed
array_replace_recursive(): Argument #1 is not an array
/lib/ZendFramework/ZendFramework-2.1.0/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:144
/lib/ZendFramework/ZendFramework-2.1.0/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:173
/lib/ZendFramework/ZendFramework-2.1.0/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:193
/lib/ZendFramework/ZendFramework-2.1.0/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:236
/var/www/sandbox/zf2sandbox/module/Application/test/ApplicationTest/Controller/IndexControllerTest.php:18
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
當我只使用了標準的PHPUnit斷言,methodes像assertEmpty(...),它工作正常。
這裏是我的IndexControllerTest.php:
<?php
namespace ApplicationTest\Controller;
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
class IndexControllerTest extends AbstractHttpControllerTestCase
{
public function setUp()
{
$this->setApplicationConfig(
include '/var/www/sandbox/zf2sandbox/config/test/application.config.php'
);
parent::setUp();
}
public function testIndexActionCanBeAccessed()
{
$this->dispatch('/');
$this->assertResponseStatusCode(200);
$this->assertModuleName('application');
$this->assertControllerName('application_index');
$this->assertControllerClass('IndexController');
$this->assertMatchedRouteName('home');
// $this->assertEmpty(null);
}
}
有人可以幫忙嗎?
THX
它給你的錯誤:'1)ApplicationTest \控制器\ IndexControllerTest :: testIndexActionCanBeAccessed array_replace_recursive():參數#1不是一個array'。從那開始工作。 (你的配置文件沒有正確設置......) – 2013-02-15 17:33:36
我不明白這個錯誤,它說我幾乎沒有。只有那個array_replace_recursive()被調用的地方有一個錯誤的參數......你能解釋一下,這個問題是什麼?我的主要application.config.php沒有改變。/config/test中的application.config.php爲空。我剛剛遵循了本教程中描述的步驟。 – automatix 2013-02-15 18:02:11
檢查'setUp'我假設錯誤是你給定的配置文件沒有返回數組。 - well nvm ... @Ocramius已經指出了一個小時前...;) – Sam 2013-02-15 19:32:11