Level 70
4 likes
I have a trait inside tests\Feature\Traits:
<?php
namespace Tests\Feature\Traits;
trait HasMediaTest
{
public function test_something_in_the_trait()
{
$this->assertTrue(true);
}
}
It is used like this:
<?php
namespace Tests\Feature;
use Tests\Feature\Traits\HasMediaTest;
use Tests\TestCase;
class UserTest extends TestCase
{
use HasMediaTest;
public function test_something()
{
$this->assertTrue(true);
}
}
Both tests pass fine. But in cmd line I get a warning:
WARN Class HasMediaTest cannot be found in /Users/panthro/Documents/web/applawred/tests/Feature/Traits/HasMediaTest.php
I have done the usual composer dump-autoload.
Here is the composer file:
"autoload": {
"psr-4": {
"App\": "app/",
"Database\Factories\": "database/factories/",
"Database\Seeders\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
}
},
@panthro Ahh....
Your class name is HasMediaTest. The keyword Test as a suffix is the problem. It is reserved for the test class only. Therefore file not found warning appears.
You simply rename it to HasMedia or HasMediaTrait of your class name.
You should not use test as a suffix.
Please or to participate in this conversation.