tests/Unit/Controller/Common/DevicesControllerTestCase.php
<?php namespace Tests\Unit\Controller\Common; use App\Http\MQTT\MessagePublisher;use Mockery; class DevicesControllerTestCase extends ControllerTestCase{The method mockMessagePublisher has a boolean flag argument $messagePublishedSuccessfully, which is a certain sign of a Single Responsibility Principle violation. protected function mockMessagePublisher(int $timesPublishIsCalled, bool $messagePublishedSuccessfully = true): void { $mockMessagePublisher = Mockery::mock(MessagePublisher::class); $mockMessagePublisher ->shouldReceive('publish') ->withAnyArgs() ->times($timesPublishIsCalled) ->andReturn($messagePublishedSuccessfully); $this->app->instance(MessagePublisher::class, $mockMessagePublisher); }}