PHPUnit with a Zend Framework 2 module

柔情痞子 提交于 2019-12-01 08:16:34

In the meantime I was able to solve it using set_include_path() and spl_autoload_register() as described in http://robertbasic.com/blog/unit-testing-zend-framework-2-modules.

I had the issue as well.

I solved it by running phpunit from the root of my ZF2 project with the following arguments:

 ./vendor/bin/phpunit
  --bootstrap ./module/Rest/test/Bootstrap.php
  ./module/Rest/test/RestTest/Controller/RestControllerTest.php

my

<zf2_project_root>/module/Rest/test/TestConfig.php.dist

is setup up to test my Rest module as show here:

<?php
return array(
    'modules' => array(
        'Rest' // <- my 'Rest' module is the one I test here.
    ),
    'module_listener_options' => array(
        'config_glob_paths'    => array(
            '../../../config/autoload/{,*.}{global,local}.php',
        ),
        'module_paths' => array(
            'module',
            'vendor',
        ),
    ),
);

of course, my ./composer.json contains a reference to phpunit as follow:

{
    "require" : {
        ...,
        "phpunit/phpunit" : "3.7.*",
        ...,
    }
}

Note:

phpunit can also be invoked with bootstrap class only (i.e., whithout specifying the test suite class). Also using the --colors flag makes phpunit output more readable:

 ./vendor/bin/phpunit
  --colors
  --bootstrap ./module/Rest/test/Bootstrap.php
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!