-
Notifications
You must be signed in to change notification settings - Fork 665
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Silenced interface (#1236)
- Loading branch information
1 parent
50f9fd9
commit 355ff05
Showing
3 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Laravel\Horizon\Contracts; | ||
|
||
interface Silenced | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace Laravel\Horizon\Tests\Feature\Listeners; | ||
|
||
use Illuminate\Queue\Jobs\RedisJob; | ||
use Laravel\Horizon\Contracts\JobRepository; | ||
use Laravel\Horizon\Contracts\Silenced; | ||
use Laravel\Horizon\Contracts\TagRepository; | ||
use Laravel\Horizon\Events\JobDeleted; | ||
use Laravel\Horizon\JobPayload; | ||
use Laravel\Horizon\Listeners\MarkJobAsComplete; | ||
use Laravel\Horizon\Tests\IntegrationTest; | ||
use Mockery as m; | ||
|
||
class MarkJobAsCompleteTest extends IntegrationTest | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
|
||
m::close(); | ||
} | ||
|
||
protected function getEnvironmentSetUp($app): void | ||
{ | ||
parent::getEnvironmentSetUp($app); | ||
|
||
$app['config']->set('horizon.silenced', [ | ||
'App\\Jobs\\ConfigJob', | ||
]); | ||
} | ||
|
||
public function test_it_can_mark_a_job_as_complete(): void | ||
{ | ||
$this->runScenario('App\\Jobs\\TestJob', false); | ||
} | ||
|
||
public function test_it_can_handle_silenced_jobs_from_the_config(): void | ||
{ | ||
$this->runScenario('App\\Jobs\\ConfigJob', true); | ||
} | ||
|
||
public function test_it_can_handle_silenced_jobs_from_an_interface(): void | ||
{ | ||
$this->runScenario(SilencedJob::class, true); | ||
} | ||
|
||
public function test_it_can_handle_jobs_which_are_not_silenced(): void | ||
{ | ||
$this->runScenario(NonSilencedJob::class, false); | ||
} | ||
|
||
public function runScenario(string $job, bool $silenced): void | ||
{ | ||
$payload = m::mock(JobPayload::class); | ||
$payload->shouldReceive('commandName')->andReturn($job); | ||
$payload->shouldReceive('tags')->andReturn([]); | ||
|
||
$job = m::mock(RedisJob::class); | ||
$job->shouldReceive('hasFailed')->andReturn(false); | ||
|
||
$event = m::mock(JobDeleted::class); | ||
$event->payload = $payload; | ||
$event->job = $job; | ||
|
||
$jobs = m::mock(JobRepository::class); | ||
$jobs->shouldReceive('completed')->once()->with($payload, false, $silenced); | ||
|
||
$tags = m::mock(TagRepository::class); | ||
$tags->shouldReceive('monitored')->once()->with([])->andReturn([]); | ||
|
||
$listener = new MarkJobAsComplete($jobs, $tags); | ||
|
||
$listener->handle($event); | ||
} | ||
} | ||
|
||
class SilencedJob implements Silenced | ||
{ | ||
} | ||
|
||
class NonSilencedJob | ||
{ | ||
} |