Cannot extend controller test class


I have a Base class to be extended by the controller tests:

//Base.php namespace AppBundle\Tests\System; abstract class Base extends \PHPUnit_Framework_TestCase { ... }

But when I try to extend it:

//DefaultControllerTest.php namespace AppBundle\Tests\Controller; use AppBundle\Tests\System\Base; class DefaultControllerTest extends Base { ... }

I get this error:


/usr/bin/php /tmp/ide-phpunit.php --configuration /server/project/phpunit.xml /server/project/src/AppBundle/Tests Testing started at 18:36 ... PHP Fatal error: Class 'AppBundle\Tests\System\Base' not found in /server/project/src/AppBundle/Tests/Controller/DefaultControllerTest.php on line 7

Process finished with exit code 255


PhpStorm is detecting the Base class in DefaultController.php, so it does not seem a typo.

This is my phpunit.xml:

<?xml version="1.0" encoding="UTF-8"?> <phpunit backupGlobals = "false" backupStaticAttributes = "false" colors = "true" convertErrorsToExceptions = "true" convertNoticesToExceptions = "true" convertWarningsToExceptions = "true" processIsolation = "false" stopOnFailure = "false" syntaxCheck = "false" bootstrap = "app/bootstrap.php.cache" > <testsuites> <testsuite name="Tests"> <directory>src/AppBundle/Tests</directory> </testsuite> </testsuites> <php> <server name="KERNEL_DIR" value="app" /> </php> <groups> <exclude> <group>slow</group> </exclude> </groups> <!-- This is for code coverage --> <filter> <whitelist> <directory>app</directory> <directory>src</directory> <exclude> <directory>app/cache/*</directory> <file>app/check.php</file> </exclude> </whitelist> </filter> </phpunit>

Any idea of what I'm missing?


I believe you can actually tell phpunit directly to use the composer autoloader:


Instead of "web/app_test.php"

This is for Symfony >= 2.8, for previous versions I think it would be "vendor/autoload.php"


As @malcolm and @Ilya Yarkovets suggest, I need to include the testing autoloader. So I've created an app_test.php file inside web directory with this configuration:

use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Debug\Debug; /** * @var Composer\Autoload\ClassLoader $loader */ $loader = require __DIR__.'/../app/autoload.php'; Debug::enable(); $kernel = new AppKernel('test', true); $kernel->loadClassCache(); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response);

and changed this line in phpunit.xml:

bootstrap = "web/app_test.php" >

I'm not sure yet if app_test.php should be modified, but now seems to work as expected.


  • Attempted to call an undefined method named “getRequest” of class . Sendind e-mail in SwiftMailer Sy
  • How many spring controller in spring3
  • How to - alert ,in jquery ajax form, after successful form submission?
  • Why and tag don't work in PhpStorm
  • Method 'create' not found in class Illuminate\\Support\\Facades\\Schema
  • Symfony2 custom form field
  • Multidimensional array as a flat array problem
  • Catch-all route in Symfony 3
  • Why nullable types will not be equal in this case?
  • “Member has private access error” after deleting plugin in CakePHP using PhpStorm
  • Bundle install fails - Gem using github url - What is wrong?
  • Doctrine: UniqueEntity with Many-to-Many field
  • Creating new docker-machine instance always fails validating certs using openstack driver
  • Passing a Scala type to a function
  • Allocating a 2D contiguous array within a function
  • Detection of framework usage on Mac system?
  • How to discover Font Type?
  • Error processing multiple files
  • Eloquent paginate function in Slim 3 project using twig
  • java inputstream
  • Bad request using file_get_contents for PUT request in PHP
  • When to use `image` and when to use `Matrix` in Emgu CV?
  • Using $this when not in object context
  • Uncaught Error: Could not find module `ember-load-initializers`
  • How do I fake an specific browser client when using Java's Net library?
  • How reduce the height of an mschart by breaking up the y-axis
  • SSO with signing and signature validation doesn't work
  • Perl system calls when running as another user using sudo
  • Deserializing XML into class C#
  • Cannot Parse HTML Data Using Android / JSOUP
  • How to include full .NET prerequisite for Wix Burn installer
  • Java static initializers and reflection
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • unknown Exception android
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize