0

在“ 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);
    }
}

有人可以帮忙吗?

谢谢

4

1 回答 1

0

检查您的线路

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

实际上产生一个数组。到目前为止,我猜它正在生产false或不返回任何东西。

该文件应如下所示:

<?php

return array(
    // ...
);
于 2013-02-15T18:34:39.590 回答