Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jakegroves's avatar

PHP Fatal error: Class 'TestCase' not found

I did not know where to put this. But i have the laravel 5.2 package and i am attempting to run some tests and i have the following file "tests/UserTest.php" with the following code:

<?php

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class UserTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testExample()
    {
        $this->visit('/register')
            ->type('test', 'name')
            ->type('test@test.com', 'email')
            ->type('test1', 'password')
            ->type('test1', 'password_confirmation')
            ->press('Register')
            ->seePageIs('/home');
    }
}

But when i run this in the cmd line:

php vendor/phpunit/phpunit/phpunit

i get thefollowing output:

PHPUnit 4.8.24 by Sebastian Bergmann and contributors.



Time: 914 ms, Memory: 4.00Mb

No tests executed!

But when i manually put in hte file name:

php vendor/phpunit/phpunit/phpunit tests/UserTest.php

i get this output:

PHP Fatal error:  Class 'TestCase' not found in W:\UniXampp\htdocs\tests\UserTest.php on line 7

Fatal error: Class 'TestCase' not found in W:\UniXampp\htdocs\tests\UserTest.php on line 7

Any reason why my test isn't running or whatnot??

0 likes
8 replies
bobbybouwmann's avatar

The TestCase class only exists within the framework, not in your package. You need to setup everything yourself if you want to make these tests work in your package

jakegroves's avatar

@Dan thanks i also had to add this in composer.jon:

    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },

and do composer update just posting incase anyone has same issue in future

3 likes
hesamurai's avatar

I had the same problem while trying to configure phpStorm to run my tests.

Apparently, phpStorm has a bug regarding the testing environment settings.

For me, the problem was that the initial settings of the test environment was wrong and I was trying to correct it but phpStorm did not reflect my new settings. So I ended up deleting the whole .idea folder from the project root so I could set the test environment from scratch.

2 likes
levendcll's avatar

i face this issue to but can't work this. Is there any body can help me?

C:\xampp\php\php.exe C:/Users/Lenovo/AppData/Local/Temp/ide-phpunit.php --bootstrap C:\xampp\htdocs\Kumbara-Api\tests_bootstrap.php --no-configuration C:\xampp\htdocs\Kumbara-Api\tests Testing started at 17:59 ...

Fatal error: Class 'Tests\TestCase' not found in

1 like
godbout's avatar

For me it was a little harder.

Had to get the new content of TestCase.php on github, then add manually CreatesApplication.php in the same folder, then update composer.json with the new settings for autoload-dev.

1 like
Shahrukh4's avatar

use the dependancy on the top of your class as follows,

use Tests\TestCase

class UserTest extends TestCase{

    ...//your business logic

}

Please or to participate in this conversation.