【问题标题】:Trouble with the ZF2 Getting Started tutorial and PHPUnitZF2 入门教程和 PHPUnit 的问题
【发布时间】: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


【解决方案1】:

检查你的线路

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

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

文件应如下所示:

<?php

return array(
    // ...
);

【讨论】:

  • 是的,我的 /config/test/application.config.php 是空的...现在,我不再收到此错误。有一个新错误:Zend\ModuleManager\Exception\RuntimeException: Module (Application) could not be initialized. 但这是另一个错误,可能是另一个线程。谢谢!
猜你喜欢
  • 2012-12-08
  • 2011-08-18
  • 1970-01-01
  • 2018-06-29
  • 1970-01-01
  • 2023-03-31
  • 1970-01-01
  • 2011-04-03
  • 1970-01-01
相关资源
最近更新 更多