简体   繁体   中英

How to prevent module from being loaded in Zend Framework 2 phpunit test

I wrote a ZF2 application with an Auth module. The setup of this Auth module is done in its Module.php file.

I set up a test like in the Zend Framework 2 Unit Testing Tutorial ( http://framework.zend.com/manual/2.2/en/tutorials/unittesting.html ) but with the Application module to test. In the test's bootstrap.php I only include the Application module in the config:

$config = array(
    'module_listener_options' => array(
        'module_paths' => $zf2ModulePaths,
    ),
    'modules' => array(
        'Application',
    )
);

And in the phpunit.xml I only included this test directory:

<phpunit bootstrap="Bootstrap.php">
    <testsuites>
        <testsuite name="myApplication">
            <directory>./ApplicationTest</directory>
        </testsuite>
    </testsuites>
</phpunit>

I expect not to have the Auth module being loaded and so it should be disabled for the test. But I get an Exception thrown by a function in the Auth module so I think it is loaded anyhow.

Do I misunderstand the bootstrapping and is there a way to prevent that module from being loaded?

Maybe it is not the perfect solution, but the following works: replace the method setUp with

public function setUp()
{
    $config = include '/path/to/config/application.config.php';
    $config['modules'] = array('Application');

    $this->setApplicationConfig($config);

    parent::setUp();
}

The array can include other modules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM