This is a question on PHP Unit Test giving me a Class Not Found Error.
Background
I am using Zend Studio 10.5 to develop a Zend Framework 2 application. I have a few modules loaded, including ZfcUser
and BjyAuthorize
FedcoUser is the module that has a Controller Guard that uses guard rules of BjyAuthorize:
<?php
namespace FedcoUser\Controller;
use Zend\View\Model\ViewModel;
use ZfcUser\Controller\UserController as ZfcUserController;
class MachinistController extends ZfcUserController
{
public function indexAction()
{
if (!$this->zfcUserAuthentication()->hasIdentity()) {
return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
}
return new ViewModel();
}
}
Using Zend Studio 10.5 native menus, I have created a test case for the controller above. When I run it I get the following error:
Debug Error: FedcoUser/Controller/MachinistController.php line 8 - Class 'ZfcUser\Controller\UserController' not found
My assumption is that somehow, autoloader for PHPUnit cannot figure out where the class is being placed, because the class it cannot find is located at
vendor/zf-commons/zfc-user/src/ZfcUser/Controller/UserController.php
I am not yet familiar with how PHPUnit works to be able to fix this error. Does PHPUnit even have an autoloader? There are files called bootstrap.php
, phpunit.xml
, and TestConfiguration.php
in my module's /test/
folder, if that helps. I tried to randomly add various modules and paths to TestConfiguration.php
file as below but it did not help:
$additionalModulePaths = array(
'ZfcUser' => realpath('vendor/zf-commons/zfc-user/src/ZfcUser/Controller/UserController.php'),
);
Can you help?