Search code examples
phpzend-frameworkphpunitzend-framework2

PHP Fatal error: Class 'Zend\Mvc\Application' not found


So i've been following this tutorial:

http://framework.zend.com/manual/2.0/en/user-guide/routing-and-controllers.html

i'm at the point where i'm supposed to run phpunit -- i run the command phpunit module/Album/src/Album/Controller/AlbumControllerTest.php

and i'm hitting a problem:

PHP Fatal error:  Class 'Zend\Mvc\Application' not found in /home/...rest of the folders here.../AlbumControllerTest.php on line 71

line 71 in AlbumControllerTest.php is:

$bootstrap        = \Zend\Mvc\Application::init(include 'config/application.config.php');

When i look under Zend/Mvc/ i see a file called Application, so i'm assuming this is not the issue.

config/application.config.php looks like this:

<?php
// config/application.config.php:
return array(
    'modules' => array(
        'Application',
        'Album',                  // <-- Add this line
    ),
    'module_listener_options' => array(
        'config_glob_paths'    => array(
            'config/autoload/{,*.}{global,local}.php',
        ),
        'module_paths' => array(
            './module',
            './vendor',
        ),
    ),
);

?>

as per tutorial - i believe. Does anyone know how to solve this?!


Solution

  • I faced the same issue when upgrading from Magento Commerce 2.2.7 to 2.3. I've fixed it by manually editing composer.json autoload:

    "autoload-dev": {
        "psr-4": {
    
    
            "Magento\\Framework\\": "lib/internal/Magento/Framework/",
            "Magento\\Setup\\": "setup/src/Magento/Setup/",
            "Magento\\": "app/code/Magento/",
            "Zend\\Mvc\\Controller\\": "setup/src/Zend/Mvc/Controller/"
        }
    },
    

    The, running the command:

    composer dumpautoload
    

    That's it.