From b8d79acd12443796c7f374a836d028153a004398 Mon Sep 17 00:00:00 2001 From: Martin Zurowietz Date: Wed, 4 Oct 2023 12:08:09 +0200 Subject: [PATCH] Update tests for Laravel 10 References https://github.com/biigle/core/pull/665 --- .../Api/Projects/LargoControllerTest.php | 35 +++++++++---------- .../Api/Volumes/LargoControllerTest.php | 35 +++++++++---------- tests/Jobs/ApplyLargoSessionTest.php | 25 ++++++------- tests/Listeners/ImagesCleanupListenerTest.php | 25 +++++++------ tests/Listeners/VideosCleanupListenerTest.php | 25 +++++++------ .../Observers/ImageAnnotationObserverTest.php | 7 ++-- .../Observers/VideoAnnotationObserverTest.php | 7 ++-- 7 files changed, 85 insertions(+), 74 deletions(-) diff --git a/tests/Http/Controllers/Api/Projects/LargoControllerTest.php b/tests/Http/Controllers/Api/Projects/LargoControllerTest.php index fabd0eb2..d213ef01 100644 --- a/tests/Http/Controllers/Api/Projects/LargoControllerTest.php +++ b/tests/Http/Controllers/Api/Projects/LargoControllerTest.php @@ -14,6 +14,7 @@ use Biigle\Tests\VideoAnnotationTest; use Biigle\Tests\VideoTest; use Biigle\Tests\VolumeTest; +use Queue; class LargoControllerTest extends ApiTestCase { @@ -133,7 +134,6 @@ public function testErrorsVideoAnnotations() public function testQueueImageAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/projects/{$this->project()->id}/largo", [ 'dismissed_image_annotations' => [ @@ -141,12 +141,11 @@ public function testQueueImageAnnotations() ], 'changed_image_annotations' => [], ]); - $this->assertEquals('default', $this->dispatchedJobs[0]->queue); + Queue::assertPushedOn('default', ApplyLargoSession::class); } public function testQueueVideoAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/projects/{$this->project()->id}/largo", [ 'dismissed_video_annotations' => [ @@ -154,12 +153,11 @@ public function testQueueVideoAnnotations() ], 'changed_video_annotations' => [], ]); - $this->assertEquals('default', $this->dispatchedJobs[0]->queue); + Queue::assertPushedOn('default', ApplyLargoSession::class); } public function testDismissImageAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/projects/{$this->project()->id}/largo", [ 'dismissed_image_annotations' => [ @@ -168,11 +166,11 @@ public function testDismissImageAnnotations() 'changed_image_annotations' => [], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testDismissVideoAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/projects/{$this->project()->id}/largo", [ 'dismissed_video_annotations' => [ @@ -181,11 +179,11 @@ public function testDismissVideoAnnotations() 'changed_video_annotations' => [], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testDismissForceDenyImageAnnotations() { - $this->doesntExpectJobs(ApplyLargoSession::class); $this->imageAnnotationLabel->user_id = $this->admin()->id; $this->imageAnnotationLabel->save(); $this->beEditor(); @@ -197,11 +195,11 @@ public function testDismissForceDenyImageAnnotations() 'force' => true, ]) ->assertStatus(403); + Queue::assertNotPushed(ApplyLargoSession::class); } public function testDismissForceDenyVideoAnnotations() { - $this->doesntExpectJobs(ApplyLargoSession::class); $this->videoAnnotationLabel->user_id = $this->admin()->id; $this->videoAnnotationLabel->save(); $this->beEditor(); @@ -213,11 +211,11 @@ public function testDismissForceDenyVideoAnnotations() 'force' => true, ]) ->assertStatus(403); + Queue::assertNotPushed(ApplyLargoSession::class); } public function testDismissForceImageAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beExpert(); $this->postJson("/api/v1/projects/{$this->project()->id}/largo", [ 'dismissed_image_annotations' => [ @@ -227,11 +225,11 @@ public function testDismissForceImageAnnotations() 'force' => true, ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testDismissForceVideoAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beExpert(); $this->postJson("/api/v1/projects/{$this->project()->id}/largo", [ 'dismissed_video_annotations' => [ @@ -241,11 +239,11 @@ public function testDismissForceVideoAnnotations() 'force' => true, ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeOwnImageAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/projects/{$this->project()->id}/largo", [ 'dismissed_image_annotations' => [ @@ -256,11 +254,11 @@ public function testChangeOwnImageAnnotations() ], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeOwnVideoAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/projects/{$this->project()->id}/largo", [ 'dismissed_video_annotations' => [ @@ -271,11 +269,11 @@ public function testChangeOwnVideoAnnotations() ], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeOtherImageAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beAdmin(); $this->postJson("/api/v1/projects/{$this->project()->id}/largo", [ 'dismissed_image_annotations' => [ @@ -286,11 +284,11 @@ public function testChangeOtherImageAnnotations() ], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeOtherVideoAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beAdmin(); $this->postJson("/api/v1/projects/{$this->project()->id}/largo", [ 'dismissed_video_annotations' => [ @@ -301,11 +299,11 @@ public function testChangeOtherVideoAnnotations() ], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeOtherForceImageAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beExpert(); $this->postJson("/api/v1/projects/{$this->project()->id}/largo", [ 'dismissed_image_annotations' => [ @@ -317,11 +315,11 @@ public function testChangeOtherForceImageAnnotations() 'force' => true, ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeOtherForceVideoAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beExpert(); $this->postJson("/api/v1/projects/{$this->project()->id}/largo", [ 'dismissed_video_annotations' => [ @@ -333,6 +331,7 @@ public function testChangeOtherForceVideoAnnotations() 'force' => true, ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeMultipleImageAnnotations() @@ -342,7 +341,6 @@ public function testChangeMultipleImageAnnotations() 'user_id' => $this->editor()->id, ]); - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/projects/{$this->project()->id}/largo", [ 'dismissed_image_annotations' => [ @@ -355,6 +353,7 @@ public function testChangeMultipleImageAnnotations() ], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeMultipleVideoAnnotations() @@ -364,7 +363,6 @@ public function testChangeMultipleVideoAnnotations() 'user_id' => $this->editor()->id, ]); - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/projects/{$this->project()->id}/largo", [ 'dismissed_video_annotations' => [ @@ -377,6 +375,7 @@ public function testChangeMultipleVideoAnnotations() ], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testStoreSetJobIdImageAnnotations() diff --git a/tests/Http/Controllers/Api/Volumes/LargoControllerTest.php b/tests/Http/Controllers/Api/Volumes/LargoControllerTest.php index d357a3c7..fb3a3823 100644 --- a/tests/Http/Controllers/Api/Volumes/LargoControllerTest.php +++ b/tests/Http/Controllers/Api/Volumes/LargoControllerTest.php @@ -14,6 +14,7 @@ use Biigle\Tests\VideoAnnotationTest; use Biigle\Tests\VideoTest; use Biigle\Tests\VolumeTest; +use Queue; class LargoControllerTest extends ApiTestCase { @@ -133,7 +134,6 @@ public function testErrorsVideoAnnotations() public function testQueueImageAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/volumes/{$this->imageVolume->id}/largo", [ 'dismissed_image_annotations' => [ @@ -141,12 +141,11 @@ public function testQueueImageAnnotations() ], 'changed_image_annotations' => [], ]); - $this->assertEquals('default', $this->dispatchedJobs[0]->queue); + Queue::assertPushedOn('default', ApplyLargoSession::class); } public function testQueueVideoAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/volumes/{$this->videoVolume->id}/largo", [ 'dismissed_video_annotations' => [ @@ -154,12 +153,11 @@ public function testQueueVideoAnnotations() ], 'changed_video_annotations' => [], ]); - $this->assertEquals('default', $this->dispatchedJobs[0]->queue); + Queue::assertPushedOn('default', ApplyLargoSession::class); } public function testDismissImageAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/volumes/{$this->imageVolume->id}/largo", [ 'dismissed_image_annotations' => [ @@ -168,11 +166,11 @@ public function testDismissImageAnnotations() 'changed_image_annotations' => [], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testDismissVideoAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/volumes/{$this->videoVolume->id}/largo", [ 'dismissed_video_annotations' => [ @@ -181,11 +179,11 @@ public function testDismissVideoAnnotations() 'changed_video_annotations' => [], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testDismissForceDenyImageAnnotations() { - $this->doesntExpectJobs(ApplyLargoSession::class); $this->imageAnnotationLabel->user_id = $this->admin()->id; $this->imageAnnotationLabel->save(); $this->beEditor(); @@ -197,11 +195,11 @@ public function testDismissForceDenyImageAnnotations() 'force' => true, ]) ->assertStatus(403); + Queue::assertNotPushed(ApplyLargoSession::class); } public function testDismissForceDenyVideoAnnotations() { - $this->doesntExpectJobs(ApplyLargoSession::class); $this->videoAnnotationLabel->user_id = $this->admin()->id; $this->videoAnnotationLabel->save(); $this->beEditor(); @@ -213,11 +211,11 @@ public function testDismissForceDenyVideoAnnotations() 'force' => true, ]) ->assertStatus(403); + Queue::assertNotPushed(ApplyLargoSession::class); } public function testDismissForceImageAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beExpert(); $this->postJson("/api/v1/volumes/{$this->imageVolume->id}/largo", [ 'dismissed_image_annotations' => [ @@ -227,11 +225,11 @@ public function testDismissForceImageAnnotations() 'force' => true, ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testDismissForceVideoAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beExpert(); $this->postJson("/api/v1/volumes/{$this->videoVolume->id}/largo", [ 'dismissed_video_annotations' => [ @@ -241,11 +239,11 @@ public function testDismissForceVideoAnnotations() 'force' => true, ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeOwnImageAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/volumes/{$this->imageVolume->id}/largo", [ 'dismissed_image_annotations' => [ @@ -256,11 +254,11 @@ public function testChangeOwnImageAnnotations() ], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeOwnVideoAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/volumes/{$this->videoVolume->id}/largo", [ 'dismissed_video_annotations' => [ @@ -271,11 +269,11 @@ public function testChangeOwnVideoAnnotations() ], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeOtherImageAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beAdmin(); $this->postJson("/api/v1/volumes/{$this->imageVolume->id}/largo", [ 'dismissed_image_annotations' => [ @@ -286,11 +284,11 @@ public function testChangeOtherImageAnnotations() ], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeOtherVideoAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beAdmin(); $this->postJson("/api/v1/volumes/{$this->videoVolume->id}/largo", [ 'dismissed_video_annotations' => [ @@ -301,11 +299,11 @@ public function testChangeOtherVideoAnnotations() ], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeOtherForceImageAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beExpert(); $this->postJson("/api/v1/volumes/{$this->imageVolume->id}/largo", [ 'dismissed_image_annotations' => [ @@ -317,11 +315,11 @@ public function testChangeOtherForceImageAnnotations() 'force' => true, ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeOtherForceVideoAnnotations() { - $this->expectsJobs(ApplyLargoSession::class); $this->beExpert(); $this->postJson("/api/v1/volumes/{$this->videoVolume->id}/largo", [ 'dismissed_video_annotations' => [ @@ -333,6 +331,7 @@ public function testChangeOtherForceVideoAnnotations() 'force' => true, ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeMultipleImageAnnotations() @@ -342,7 +341,6 @@ public function testChangeMultipleImageAnnotations() 'user_id' => $this->editor()->id, ]); - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/volumes/{$this->imageVolume->id}/largo", [ 'dismissed_image_annotations' => [ @@ -355,6 +353,7 @@ public function testChangeMultipleImageAnnotations() ], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testChangeMultipleVideoAnnotations() @@ -364,7 +363,6 @@ public function testChangeMultipleVideoAnnotations() 'user_id' => $this->editor()->id, ]); - $this->expectsJobs(ApplyLargoSession::class); $this->beEditor(); $this->postJson("/api/v1/volumes/{$this->videoVolume->id}/largo", [ 'dismissed_video_annotations' => [ @@ -377,6 +375,7 @@ public function testChangeMultipleVideoAnnotations() ], ]) ->assertStatus(200); + Queue::assertPushed(ApplyLargoSession::class); } public function testStoreSetJobIdImageAnnotations() diff --git a/tests/Jobs/ApplyLargoSessionTest.php b/tests/Jobs/ApplyLargoSessionTest.php index 728e88d1..7e855b34 100644 --- a/tests/Jobs/ApplyLargoSessionTest.php +++ b/tests/Jobs/ApplyLargoSessionTest.php @@ -16,6 +16,7 @@ use Biigle\Tests\VideoAnnotationTest; use Biigle\Tests\VideoTest; use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Queue; use TestCase; class ApplyLargoSessionTest extends TestCase @@ -264,7 +265,6 @@ public function testLabelMeanwhileDeletedVideoAnnotations() public function testDismissImageAnnotations() { - $this->expectsJobs(RemoveImageAnnotationPatches::class); $user = UserTest::create(); $al1 = ImageAnnotationLabelTest::create(['user_id' => $user->id]); @@ -275,11 +275,11 @@ public function testDismissImageAnnotations() // al1 was dismissed but not changed, should be deleted. $this->assertFalse($al1->exists()); $this->assertFalse($al1->annotation()->exists()); + Queue::assertPushed(RemoveImageAnnotationPatches::class); } public function testDismissVideoAnnotations() { - $this->expectsJobs(RemoveVideoAnnotationPatches::class); $user = UserTest::create(); $al1 = VideoAnnotationLabelTest::create(['user_id' => $user->id]); @@ -290,11 +290,11 @@ public function testDismissVideoAnnotations() // al1 was dismissed but not changed, should be deleted. $this->assertFalse($al1->exists()); $this->assertFalse($al1->annotation()->exists()); + Queue::assertPushed(RemoveVideoAnnotationPatches::class); } public function testDismissForceImageAnnotations() { - $this->expectsJobs(RemoveImageAnnotationPatches::class); $user = UserTest::create(); $al1 = ImageAnnotationLabelTest::create(['user_id' => $user->id]); $user2 = UserTest::create(); @@ -305,11 +305,11 @@ public function testDismissForceImageAnnotations() $this->assertFalse($al1->exists()); $this->assertFalse($al1->annotation()->exists()); + Queue::assertPushed(RemoveImageAnnotationPatches::class); } public function testDismissForceVideoAnnotations() { - $this->expectsJobs(RemoveVideoAnnotationPatches::class); $user = UserTest::create(); $al1 = VideoAnnotationLabelTest::create(['user_id' => $user->id]); $user2 = UserTest::create(); @@ -320,11 +320,11 @@ public function testDismissForceVideoAnnotations() $this->assertFalse($al1->exists()); $this->assertFalse($al1->annotation()->exists()); + Queue::assertPushed(RemoveVideoAnnotationPatches::class); } public function testChangeOwnImageAnnotations() { - $this->doesntExpectJobs(RemoveImageAnnotationPatches::class); $user = UserTest::create(); $al1 = ImageAnnotationLabelTest::create(['user_id' => $user->id]); $annotation = $al1->annotation; @@ -338,11 +338,11 @@ public function testChangeOwnImageAnnotations() // al1 was dismissed and then changed, should have a new annotation label $this->assertNull($al1->fresh()); $this->assertEquals($l1->id, $annotation->labels()->first()->label_id); + Queue::assertNotPushed(RemoveImageAnnotationPatches::class); } public function testChangeOwnVideoAnnotations() { - $this->doesntExpectJobs(RemoveVideoAnnotationPatches::class); $user = UserTest::create(); $al1 = VideoAnnotationLabelTest::create(['user_id' => $user->id]); $annotation = $al1->annotation; @@ -356,11 +356,11 @@ public function testChangeOwnVideoAnnotations() // al1 was dismissed and then changed, should have a new annotation label $this->assertNull($al1->fresh()); $this->assertEquals($l1->id, $annotation->labels()->first()->label_id); + Queue::assertNotPushed(RemoveVideoAnnotationPatches::class); } public function testChangeOtherImageAnnotations() { - $this->doesntExpectJobs(RemoveImageAnnotationPatches::class); $user = UserTest::create(); $al1 = ImageAnnotationLabelTest::create(['user_id' => $user->id]); $annotation = $al1->annotation; @@ -377,11 +377,11 @@ public function testChangeOtherImageAnnotations() $this->assertNotNull($al1->fresh()); $this->assertNotNull($annotation->fresh()); $this->assertEquals(2, $annotation->labels()->count()); + Queue::assertNotPushed(RemoveImageAnnotationPatches::class); } public function testChangeOtherVideoAnnotations() { - $this->doesntExpectJobs(RemoveVideoAnnotationPatches::class); $user = UserTest::create(); $al1 = VideoAnnotationLabelTest::create(['user_id' => $user->id]); $annotation = $al1->annotation; @@ -398,11 +398,11 @@ public function testChangeOtherVideoAnnotations() $this->assertNotNull($al1->fresh()); $this->assertNotNull($annotation->fresh()); $this->assertEquals(2, $annotation->labels()->count()); + Queue::assertNotPushed(RemoveVideoAnnotationPatches::class); } public function testChangeOtherForceImageAnnotations() { - $this->doesntExpectJobs(RemoveImageAnnotationPatches::class); $user = UserTest::create(); $al1 = ImageAnnotationLabelTest::create(['user_id' => $user->id]); $annotation = $al1->annotation; @@ -417,11 +417,11 @@ public function testChangeOtherForceImageAnnotations() $this->assertNull($al1->fresh()); $this->assertNotNull($annotation->fresh()); $this->assertEquals($l1->id, $annotation->labels()->first()->label_id); + Queue::assertNotPushed(RemoveImageAnnotationPatches::class); } public function testChangeOtherForceVideoAnnotations() { - $this->doesntExpectJobs(RemoveVideoAnnotationPatches::class); $user = UserTest::create(); $al1 = VideoAnnotationLabelTest::create(['user_id' => $user->id]); $annotation = $al1->annotation; @@ -436,11 +436,11 @@ public function testChangeOtherForceVideoAnnotations() $this->assertNull($al1->fresh()); $this->assertNotNull($annotation->fresh()); $this->assertEquals($l1->id, $annotation->labels()->first()->label_id); + Queue::assertNotPushed(RemoveVideoAnnotationPatches::class); } public function testChangeMultipleImageAnnotations() { - $this->doesntExpectJobs(RemoveImageAnnotationPatches::class); $user = UserTest::create(); $al1 = ImageAnnotationLabelTest::create(['user_id' => $user->id]); $annotation = $al1->annotation; @@ -469,11 +469,11 @@ public function testChangeMultipleImageAnnotations() $this->assertCount(2, $labels); $this->assertContains($l1->id, $labels); $this->assertContains($l2->id, $labels); + Queue::assertNotPushed(RemoveImageAnnotationPatches::class); } public function testChangeMultipleVideoAnnotations() { - $this->doesntExpectJobs(RemoveVideoAnnotationPatches::class); $user = UserTest::create(); $al1 = VideoAnnotationLabelTest::create(['user_id' => $user->id]); $annotation = $al1->annotation; @@ -502,6 +502,7 @@ public function testChangeMultipleVideoAnnotations() $this->assertCount(2, $labels); $this->assertContains($l1->id, $labels); $this->assertContains($l2->id, $labels); + Queue::assertNotPushed(RemoveVideoAnnotationPatches::class); } public function testRemoveJobIdOnFinishImageAnnotations() diff --git a/tests/Listeners/ImagesCleanupListenerTest.php b/tests/Listeners/ImagesCleanupListenerTest.php index da630ce6..857a1e6c 100644 --- a/tests/Listeners/ImagesCleanupListenerTest.php +++ b/tests/Listeners/ImagesCleanupListenerTest.php @@ -10,13 +10,14 @@ use Faker\Factory as Faker; use Illuminate\Database\QueryException; use TestCase; +use Queue; class ImagesCleanupListenerTest extends TestCase { public function testHandleEmpty() { - $this->doesntExpectJobs(RemoveImageAnnotationPatches::class); with(new ImagesCleanupListener)->handle(new ImagesDeleted([])); + Queue::assertNotPushed(RemoveImageAnnotationPatches::class); } public function testHandleMalformed() @@ -27,9 +28,9 @@ public function testHandleMalformed() public function testNotThere() { - $this->doesntExpectJobs(RemoveImageAnnotationPatches::class); $faker = Faker::create(); with(new ImagesCleanupListener)->handle(new ImagesDeleted([$faker->uuid()])); + Queue::assertNotPushed(RemoveImageAnnotationPatches::class); } public function testHandle() @@ -39,16 +40,18 @@ public function testHandle() $image2 = ImageTest::create(['volume_id' => $image->volume_id, 'filename' => 'a']); $a2 = ImageAnnotationTest::create(['image_id' => $image2->id]); - $this->expectsJobs(RemoveImageAnnotationPatches::class); with(new ImagesCleanupListener)->handle(new ImagesDeleted([$image->uuid, $image2->uuid])); - $job = end($this->dispatchedJobs); - $expect = [ $a->id => $image->uuid, $a2->id => $image2->uuid, ]; - $this->assertEquals($expect, $job->annotationIds); + + Queue::assertPushed(function (RemoveImageAnnotationPatches $job) use ($expect) { + $this->assertEquals($expect, $job->annotationIds); + + return true; + }); } public function testPartial() @@ -58,14 +61,16 @@ public function testPartial() $image2 = ImageTest::create(['volume_id' => $image->volume_id, 'filename' => 'a']); $a2 = ImageAnnotationTest::create(['image_id' => $image2->id]); - $this->expectsJobs(RemoveImageAnnotationPatches::class); with(new ImagesCleanupListener)->handle(new ImagesDeleted([$image->uuid])); - $job = end($this->dispatchedJobs); - $expect = [ $a->id => $image->uuid, ]; - $this->assertEquals($expect, $job->annotationIds); + + Queue::assertPushed(function (RemoveImageAnnotationPatches $job) use ($expect) { + $this->assertEquals($expect, $job->annotationIds); + + return true; + }); } } diff --git a/tests/Listeners/VideosCleanupListenerTest.php b/tests/Listeners/VideosCleanupListenerTest.php index 6c0f8ccf..c9df3908 100644 --- a/tests/Listeners/VideosCleanupListenerTest.php +++ b/tests/Listeners/VideosCleanupListenerTest.php @@ -10,13 +10,14 @@ use Faker\Factory as Faker; use Illuminate\Database\QueryException; use TestCase; +use Queue; class VideosCleanupListenerTest extends TestCase { public function testHandleEmpty() { - $this->doesntExpectJobs(RemoveVideoAnnotationPatches::class); with(new VideosCleanupListener)->handle(new VideosDeleted([])); + Queue::assertNotPushed(RemoveVideoAnnotationPatches::class); } public function testHandleMalformed() @@ -27,9 +28,9 @@ public function testHandleMalformed() public function testNotThere() { - $this->doesntExpectJobs(RemoveVideoAnnotationPatches::class); $faker = Faker::create(); with(new VideosCleanupListener)->handle(new VideosDeleted([$faker->uuid()])); + Queue::assertNotPushed(RemoveVideoAnnotationPatches::class); } public function testHandle() @@ -39,16 +40,18 @@ public function testHandle() $video2 = VideoTest::create(['volume_id' => $video->volume_id, 'filename' => 'b']); $a2 = VideoAnnotationTest::create(['video_id' => $video2->id]); - $this->expectsJobs(RemoveVideoAnnotationPatches::class); with(new VideosCleanupListener)->handle(new VideosDeleted([$video->uuid, $video2->uuid])); - $job = end($this->dispatchedJobs); - $expect = [ $a->id => $video->uuid, $a2->id => $video2->uuid, ]; - $this->assertEquals($expect, $job->annotationIds); + + Queue::assertPushed(function (RemoveVideoAnnotationPatches $job) use ($expect) { + $this->assertEquals($expect, $job->annotationIds); + + return true; + }); } public function testPartial() @@ -58,14 +61,16 @@ public function testPartial() $video2 = VideoTest::create(['volume_id' => $video->volume_id, 'filename' => 'b']); $a2 = VideoAnnotationTest::create(['video_id' => $video2->id]); - $this->expectsJobs(RemoveVideoAnnotationPatches::class); with(new VideosCleanupListener)->handle(new VideosDeleted([$video->uuid])); - $job = end($this->dispatchedJobs); - $expect = [ $a->id => $video->uuid, ]; - $this->assertEquals($expect, $job->annotationIds); + + Queue::assertPushed(function (RemoveVideoAnnotationPatches $job) use ($expect) { + $this->assertEquals($expect, $job->annotationIds); + + return true; + }); } } diff --git a/tests/Observers/ImageAnnotationObserverTest.php b/tests/Observers/ImageAnnotationObserverTest.php index 77b3256d..b0dea7e1 100644 --- a/tests/Observers/ImageAnnotationObserverTest.php +++ b/tests/Observers/ImageAnnotationObserverTest.php @@ -6,26 +6,27 @@ use Biigle\Modules\Largo\Jobs\RemoveImageAnnotationPatches; use Biigle\Tests\ImageAnnotationTest; use TestCase; +use Queue; class ImageAnnotationObserverTest extends TestCase { public function testDeleting() { $annotation = ImageAnnotationTest::create(); - $this->expectsJobs(RemoveImageAnnotationPatches::class); $annotation->delete(); + Queue::assertPushed(RemoveImageAnnotationPatches::class); } public function testCreated() { - $this->expectsJobs(GenerateImageAnnotationPatch::class); $annotation = ImageAnnotationTest::create(); + Queue::assertPushed(GenerateImageAnnotationPatch::class); } public function testSaved() { $annotation = ImageAnnotationTest::create(); - $this->expectsJobs(GenerateImageAnnotationPatch::class); $annotation->save(); + Queue::assertPushed(GenerateImageAnnotationPatch::class); } } diff --git a/tests/Observers/VideoAnnotationObserverTest.php b/tests/Observers/VideoAnnotationObserverTest.php index e9e07856..e0b059b1 100644 --- a/tests/Observers/VideoAnnotationObserverTest.php +++ b/tests/Observers/VideoAnnotationObserverTest.php @@ -6,26 +6,27 @@ use Biigle\Modules\Largo\Jobs\RemoveVideoAnnotationPatches; use Biigle\Tests\VideoAnnotationTest; use TestCase; +use Queue; class VideoAnnotationObserverTest extends TestCase { public function testDeleting() { $annotation = VideoAnnotationTest::create(); - $this->expectsJobs(RemoveVideoAnnotationPatches::class); $annotation->delete(); + Queue::assertPushed(RemoveVideoAnnotationPatches::class); } public function testCreated() { - $this->expectsJobs(GenerateVideoAnnotationPatch::class); $annotation = VideoAnnotationTest::create(); + Queue::assertPushed(GenerateVideoAnnotationPatch::class); } public function testSaved() { $annotation = VideoAnnotationTest::create(); - $this->expectsJobs(GenerateVideoAnnotationPatch::class); $annotation->save(); + Queue::assertPushed(GenerateVideoAnnotationPatch::class); } }