Nov 20, 2022
0
Level 19
Binding a mocked instance in the app container doesn't work in parallel
I have a test that works in serial, but when I try to execute it in parallel it fails for some reason...
(The Operation class extends the Command class and is used for Crons).
class ImportEmailsTest extends TestCase
{
public function testOperation(): void
{
$mockProcessor = Mockery::mock(MailboxProcessor::class)
->shouldReceive('importFromMailbox')->once()
->getMock();
$this->app->instance(MailboxProcessor::class, $mockProcessor);
$this->artisan('import-emails')
->assertSuccessful();
}
}
class ImportEmails extends Operation
{
protected $key = 'import-emails';
public function __construct(
protected MailboxProcessor $mailProcessor,
) {
parent::__construct();
}
public function operation()
{
$this->mailProcessor->importFromMailbox();
}
}
Any thoughts? I can't seems to figure out why it doesn't work. If I dd(app()->has(MailboxProcessor::class)); in the operation method it returns true.
Please or to participate in this conversation.