ZF2入门教程和PHPUnit的问题


Trouble with the ZF2 Getting Started tutorial and PHPUnit

在"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.

当我只使用标准的PHPUnit断言方法,如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

检查您的线路

include '/var/www/sandbox/zf2sandbox/config/test/application.config.php'

实际上产生了一个数组。到目前为止,我猜它正在生成false,或者没有返回任何内容。

文件应该看起来像:

<?php
return array(
    // ...
);