You can use the resolve() method to manually resolve the service in your test. This will allow you to inject the service into your test without having to create a contextual binding.
class EmailTemplateServiceTest extends TestCase
{
use RefreshDatabase;
private $user = null;
private $service = null;
/**
* test that the service can return available email templates
*/
public function testServiceCanReturnAvailableEmailTemplates()
{
$this->prepare();
$this->service = $this->app->resolve(TemplateServiceInterface::class);
$this->assertInstanceOf(\App\Services\EmailTemplateService::class, $this->service);
$templates = $this->service->getAvailablePublicTemplates($this->user->user_code);
$this->assertCount(0, $templates);
}
/**
* Prepares the test environment with authentication
*/
public function prepare($abilities = [])
{
$this->withoutExceptionHandling();
$this->user = User::factory()->create();
Sanctum::actingAs( $this->user, $abilities );
}
}