I'm trying to set up unit tests for my Laravel (5.2) API project. Before I use the unit tests I'd like to define a custom namespace for them so I created the namespace Test;
in the default TestCase.php
file. Like so:
namespace Test;
class TestCase extends Illuminate\Foundation\Testing\TestCase
{
...
}
Then I created a folder UnitTests
under the tests
folder 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
So basically, Laravel thinks the Illuminate\Foundation\Testing\TestCase
class is found within the Test namespace instead of the Illuminate
namespace from Laravel.
I also have the following autoload configured in the composer.json
file:
"autoload": {
"classmap": [
"database",
"tests"
],
"psr-4": {
"App\\": "app/",
"Test\\": "tests/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
}
I've also tried running both commands with no success:
php artisan config:cache
composer dump-autoload
via SolveSoul