Laravel extending Illuminate \ Foundation \ Testing \ TestCase with custom namespace
I am trying to set up unit tests for my Laravel API (5.2) project. Before using the unit tests, I would like to define their own namespace for them, so I created namespace Test;
in the TestCase.php
default file . For example:
namespace Test;
class TestCase extends Illuminate\Foundation\Testing\TestCase
{
...
}
Then I created a folder UnitTests
in a folder tests
and put my unit tests in that folder with the following namespace:
namespace Test\UnitTests;
use Test\TestCase;
class CreateAccountTest extends TestCase
{
...
}
Now when I want to run my unit tests I get the following error:
PHP Fatal error: Class 'Test\Illuminate\Foundation\Testing\TestCase' not found in /var/www/ops/tests/TestCase.php on line 6
Thus, Laravel assumes that the class Illuminate\Foundation\Testing\TestCase
is in the Test namespace instead Illuminate
of the Laravel namespace .
I also have the following autoload set up in the file composer.json
:
"autoload": {
"classmap": [
"database",
"tests"
],
"psr-4": {
"App\\": "app/",
"Test\\": "tests/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
}
I have also tried both commands without success:
-
php artisan config:cache
-
composer dump-autoload
source to share