Configuring Phpunit in Zend 2.5

Asked

Viewed 85 times

1

I’m trying to set up Phpunit in Zend, but it’s giving an error when I run phpunit on the terminal.

error:

$ phpunit PHP Fatal error:  Uncaught exception 'RuntimeException' with message 'Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.' in /media/candidosouza/Development/GITHUB/Learning-ZF2/03-ZF2-Avancado/module/CJSN/tests/Bootstrap.php:75

My Bootstrap class, taken from the documentation

Bootstrap class Documentation

My settings are on my Github

Error is falling on this Bootstrap class IF:

if (!$zf2Path) {
    throw new RuntimeException(
        'Unable to load ZF2. Run `php composer.phar install` or'
        . ' define a ZF2_PATH environment variable.'
    );
}

My files are set up as in the documentation! Can anyone tell me why that mistake!

How do I fix it?

Thank you!!!

  • run the command composer install, or composer.phar install, for all paths to be mounted

  • Hello André Henriques! Everything is already installed! This Composer run message only happens because of if in the Bootstrap class, but all my components are installed

  • Thank you for your attention André!!!

  • I’m sorry for not answering, I just looked at the error and put the comment, because reponder I can not, because long ago I do not use zend.

  • the phpunit dependency has been placed in the Composer file?

  • Hello André, is not not, it already comes installed in Zend! When you first install the dependencies with Composer, it is already installed automatically...

Show 1 more comment

1 answer

1


The problem was in the path path of the file Bootstrap.php on line 69 and 70

elseif (is_dir($vendorPath . '/zendframework/zendframework/library')) {
            $zf2Path = $vendorPath . '/zendframework/zendframework/library';

and on line 85

include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';

I am using the latest version of Zend, the 2.5, in this version the path path has changed, the folder structure has been changed.

Correction of lines 69 and 70 are:

elseif (is_dir($vendorPath . '/zendframework/')) {
            $zf2Path = $vendorPath . '/zendframework/';
        }

and line 85

include $zf2Path . '/zend-loader/src/AutoloaderFactory.php';

this way Phpunit is running perfectly

Browser other questions tagged

You are not signed in. Login or sign up in order to post.