@panthro whilst you can't write a test for a trait directly, you can create a simple class in your test and then include the trait within that:
namespace App\Mixin;
trait MyTrait {
public function returnState(bool $state): bool {
return $state;
}
}
use App\Mixin\MyTrait;
use PHPUnit\Framework\TestCase;
class MyTraitTest extends TestCase {
public function testReturnStateAnonymous(): void {
$trait = new class {
use MyTrait;
};
self::assertTrue($trait->returnState(true));
self::assertFalse($trait->returnState(false));
}
}
If you are relying on your trait within a class, I would be happy to see the tests for the trait included in that class's tests.
That way you can ensure that your class still uses the trait. Testing trait on its own would allow someone to remove the trait from a specific class and not necessarily know that you did.