2013-02-15 109 views
0

问题在“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

+0

它给你的错误:'1)ApplicationTest \控制器\ IndexControllerTest :: testIndexActionCanBeAccessed array_replace_recursive():参数#1不是一个array'。从那开始工作。 (你的配置文件没有正确设置......) – 2013-02-15 17:33:36

+0

我不明白这个错误,它说我几乎没有。只有那个array_replace_recursive()被调用的地方有一个错误的参数......你能解释一下,这个问题是什么?我的主要application.config.php没有改变。/config/test中的application.config.php为空。我刚刚遵循了本教程中描述的步骤。 – automatix 2013-02-15 18:02:11

+0

检查'setUp'我假设错误是你给定的配置文件没有返回数组。 - well nvm ... @Ocramius已经指出了一个小时前...;) – Sam 2013-02-15 19:32:11

回答

0

检查您的线路

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

实际上产生的数组。到目前为止,我想这是产生false或不返回任何东西。

的文件应该是这样:

<?php 

return array(
    // ... 
); 
+0

是的,我的/config/test/application.config.php是空的......现在,我不再收到此错误。有一个新的错误:'Zend \ ModuleManager \ Exception \ RuntimeException:模块(应用程序)无法初始化。“但这是另一个错误,也许是另一个线程。谢谢! – automatix 2013-02-18 11:56:44