0
votes

In the "Getting Started with Zend Framework 2" tutorial there is an example for the basic unit testing of the application: http://zf2.readthedocs.org/en/latest/user-guide/unit-testing.html I've just copied the code (had only to change include __DIR__ . '/../init_autoloader.php'; to include __DIR__ . '/../../../init_autoloader.php';) and now I'm getting an error:

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.

When I use only the standard PHPUnit assertion methodes like assertEmpty(...), it works fine.

Here is my 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);
    }
}

Can somebody help?

Thx

1
It gives you the error: 1) ApplicationTest\Controller\IndexControllerTest::testIndexActionCanBeAccessed array_replace_recursive(): Argument #1 is not an array. Work from that. (your configfile is not setup correctly...)Green Black
I don't understand this error, it says me nearly nothing. Only that the array_replace_recursive() has been called somewhere whith a wrong argument... Can you please explain, what hte issue is? My main application.config.php has not been changed. The application.config.php in /config/test is empty. I've just followed the steps described in the tutorial.automatix
Check the setUp i assume the error is that your given config-file is not returning an array. - well nvm... @Ocramius already pointed that out an hour ago... ;)Sam

1 Answers

0
votes

Check that your line

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

actually produces an array. So far, I guess it is producing false or not returning anything.

The file should look like:

<?php

return array(
    // ...
);