diff --git a/app/Jobs/ProcessPosterImage.php b/app/Jobs/ProcessPosterImage.php new file mode 100644 index 0000000..742c4d9 --- /dev/null +++ b/app/Jobs/ProcessPosterImage.php @@ -0,0 +1,26 @@ +concert = $concert; + } + + public function handle() + { + // + } +} diff --git a/app/Listeners/SchedulePosterImageProcessing.php b/app/Listeners/SchedulePosterImageProcessing.php new file mode 100644 index 0000000..6536037 --- /dev/null +++ b/app/Listeners/SchedulePosterImageProcessing.php @@ -0,0 +1,18 @@ +concert->hasPoster()) { + ProcessPosterImage::dispatch($event->concert); + } + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index a182657..ff965d3 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -13,8 +13,8 @@ class EventServiceProvider extends ServiceProvider * @var array */ protected $listen = [ - 'App\Events\SomeEvent' => [ - 'App\Listeners\EventListener', + 'App\Events\ConcertAdded' => [ + 'App\Listeners\SchedulePosterImageProcessing', ], ]; diff --git a/tests/Unit/Listeners/SchedulePosterImageProcessingTest.php b/tests/Unit/Listeners/SchedulePosterImageProcessingTest.php new file mode 100644 index 0000000..07d45dc --- /dev/null +++ b/tests/Unit/Listeners/SchedulePosterImageProcessingTest.php @@ -0,0 +1,44 @@ + 'posters/example-poster.png', + ]); + + ConcertAdded::dispatch($concert); + + Queue::assertPushed(ProcessPosterImage::class, function ($job) use ($concert) { + return $job->concert->is($concert); + }); + } + + /** @test */ + function a_job_is_not_queued_if_a_poster_is_not_present() + { + Queue::fake(); + + $concert = \ConcertFactory::createUnpublished([ + 'poster_image_path' => null, + ]); + + ConcertAdded::dispatch($concert); + + Queue::assertNotPushed(ProcessPosterImage::class); + } +}