Class '..\Unit\UnitTestCase' not found

Viewed 619

I am upgrading laravel from 5.5.* to 5.6.0. Composer install ran fine. I am trying to run unit tests upon which this error is popping up.

Class '..\Unit\UnitTestCase' not found

This is the stack trace of the error:

Fatal error: Uncaught Error: Class 'PhiraterTest\Unit\UnitTestCase' not found in /home/vagrant/code/phirater-l51/tests/unit/Phirater/AdditionalCurrencies/CreateAdditionalCurrencyCommandHandlerTest.php:11 Stack trace: #0 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/Util/Fileloader.php(64): include_once() #1 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/Util/Fileloader.php(48): PHPUnit\Util\Fileloader::load('/home/vagrant/c...') #2 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/Framework/TestSuite.php(325): PHPUnit\Util\Fileloader::checkAndLoad('/home/vagrant/c...') #3 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/Framework/TestSuite.php(403): PHPUnit\Framework\TestSuite->addTestFile('/home/vagrant/c...') #4 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(65): PHPUnit\Framework\TestSuite->addTestFiles(Array) #5 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/TextUI/Command.php(169): PHPUnit\Runner\BaseTestRunner->getTest('tes in /home/vagrant/code/phirater-l51/tests/unit/Phirater/AdditionalCurrencies/CreateAdditionalCurrencyCommandHandlerTest.php on line 11

My unit tests are in tests/ directory. My UnitTestCase class in extended by \TestCase class and TestCase class is extended by BrowserKitTestCase. What am i doing wrong here? What could be the solution?

1 Answers

If your dependency class is really present and has proper namespace, then the most probable reasons of mentioned error are (avoid copying below examples to your project, that will definetely not work):

  • composer.json file (root directory) has no relevant record of the dependency (do not forget composer.lock file also), smth like:

    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    
  • as a result of above, vendor/autoload.php file (or any of its merged siblings, e.g. vendor/composer/autoload_classmap.php, depending on your case) can miss relevant record of the dependency, smth like:

      return array(
          'PHPUnit\\Framework\\TestCase' => '/vendor/phpunit/phpunit/src/Framework/TestCase.php',
    

In most such cases it is really a missed dependency delivered by autoload.php functionality, which in its turn caused by composer malfunctioning. So taking in account all that, try to update composer itself by running composer self-update, and then updating your dependencies by composer update.

Related