【发布时间】:2013-02-15 17:03:54
【问题描述】:
在“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';)现在我出现错误:
root@devmv:/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.
当我只使用像 assertEmpty(...) 这样的标准 PHPUnit 断言方法时,它可以正常工作。
这是我的 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);
}
}
有人可以帮忙吗?
谢谢
【问题讨论】:
-
它给你错误:
1) ApplicationTest\Controller\IndexControllerTest::testIndexActionCanBeAccessed array_replace_recursive(): Argument #1 is not an array。从那开始工作。 (您的配置文件设置不正确...) -
我不明白这个错误,它几乎什么也没告诉我。只是 array_replace_recursive() 在某个地方被调用了一个错误的论点......你能解释一下,问题是什么?我的主要 application.config.php 没有改变。 /config/test 中的 application.config.php 为空。我刚刚按照教程中描述的步骤进行操作。
-
检查
setUp我假设错误是您给定的配置文件没有返回数组。 - 好吧,nvm...@Ocramius 一小时前已经指出了这一点... ;)
标签: php phpunit zend-framework2