Skip to content

Commit

Permalink
Merge pull request #178 from biigle/use-assertSame
Browse files Browse the repository at this point in the history
Replace assertEquals by assertSame
  • Loading branch information
mzur authored Aug 22, 2024
2 parents e3f5ce2 + 78a9d6e commit 1971d62
Show file tree
Hide file tree
Showing 19 changed files with 182 additions and 182 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ jobs:
docker pull ghcr.io/biigle/worker:latest
- name: Start test database
run: docker-compose up -d --no-build database_testing && sleep 5
run: docker compose up -d --no-build database_testing && sleep 5
working-directory: ../core

- name: Run tests
run: docker-compose run --rm -u 1001 worker php -d memory_limit=1G vendor/bin/phpunit --random-order --filter 'Biigle\\Tests\\Modules\\'${MODULE_NAME}
run: docker compose run --rm -u 1001 worker php -d memory_limit=1G vendor/bin/phpunit --random-order --filter 'Biigle\\Tests\\Modules\\'${MODULE_NAME}
working-directory: ../core
8 changes: 4 additions & 4 deletions tests/AnnotationCandidateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ public function testAttributes()
public function testCastPoints()
{
$annotation = static::create(['points' => [1, 2, 3, 4]]);
$this->assertEquals([1, 2, 3, 4], $annotation->fresh()->points);
$this->assertSame([1, 2, 3, 4], $annotation->fresh()->points);
}

public function testGetPoints()
{
$annotation = static::make(['points' => [1, 2]]);
$this->assertEquals([1, 2], $annotation->getPoints());
$this->assertSame([1, 2], $annotation->getPoints());
}

public function testGetShape()
{
$this->assertEquals($this->model->shape, $this->model->getShape());
$this->assertSame($this->model->shape, $this->model->getShape());
}

public function testGetFile()
{
$this->assertEquals($this->model->image, $this->model->getFile());
$this->assertSame($this->model->image, $this->model->getFile());
}
}
4 changes: 2 additions & 2 deletions tests/GenericImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testInstance()
public function testAttributes()
{
$i = new GenericImage(1, 'url');
$this->assertEquals(1, $i->getId());
$this->assertEquals('url', $i->getUrl());
$this->assertSame(1, $i->getId());
$this->assertSame('url', $i->getUrl());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function testUpdate()
->assertStatus(200);

$a->refresh();
$this->assertEquals([10, 20, 30], $a->points);
$this->assertSame([10, 20, 30], $a->points);
}

public function testUpdateLabel()
Expand Down Expand Up @@ -134,7 +134,7 @@ public function testUpdateLabel()
])
->assertStatus(200);

$this->assertEquals($this->labelRoot()->id, $a->fresh()->label_id);
$this->assertSame($this->labelRoot()->id, $a->fresh()->label_id);

$this->putJson("/api/v1/maia/annotation-candidates/{$a->id}", [
'label_id' => null,
Expand Down Expand Up @@ -172,7 +172,7 @@ public function testUpdatePoints()
->assertStatus(200);

Queue::assertPushed(ProcessObjectDetectedImage::class, function ($job) use ($a) {
$this->assertEquals([$a->id], $job->only);
$this->assertSame([$a->id], $job->only);
$this->assertFalse($job->skipFeatureVectors);

return true;
Expand Down
34 changes: 17 additions & 17 deletions tests/Http/Controllers/Api/MaiaJobControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ public function testStoreNoveltyDetection()

$job = MaiaJob::first();
$this->assertNotNull($job);
$this->assertEquals($id, $job->volume_id);
$this->assertEquals($this->editor()->id, $job->user_id);
$this->assertEquals(State::noveltyDetectionId(), $job->state_id);
$this->assertEquals($this->defaultParams, $job->params);
$this->assertSame($id, $job->volume_id);
$this->assertSame($this->editor()->id, $job->user_id);
$this->assertSame(State::noveltyDetectionId(), $job->state_id);
$this->assertSame($this->defaultParams, $job->params);

// only one running job at a time
$this->postJson("/api/v1/volumes/{$id}/maia-jobs", $this->defaultParams)
Expand Down Expand Up @@ -249,7 +249,7 @@ public function testStoreUseExistingAnnotations()
$job = MaiaJob::first();
$this->assertTrue($job->shouldUseExistingAnnotations());
$this->assertFalse($job->shouldShowTrainingProposals());
$this->assertEquals(State::objectDetectionId(), $job->state_id);
$this->assertSame(State::objectDetectionId(), $job->state_id);
}

public function testStoreExistingAnnotationsRestrictLabels()
Expand Down Expand Up @@ -295,7 +295,7 @@ public function testStoreExistingAnnotationsRestrictLabels()
->assertSuccessful();
$job = MaiaJob::first();
$this->assertArrayHasKey('oa_restrict_labels', $job->params);
$this->assertEquals([$this->labelChild()->id], $job->params['oa_restrict_labels']);
$this->assertSame([$this->labelChild()->id], $job->params['oa_restrict_labels']);
}

public function testStoreUseExistingAnnotationsShowTrainingProposals()
Expand Down Expand Up @@ -329,7 +329,7 @@ public function testStoreUseExistingAnnotationsShowTrainingProposals()
$job = MaiaJob::first();
$this->assertTrue($job->shouldUseExistingAnnotations());
$this->assertTrue($job->shouldShowTrainingProposals());
$this->assertEquals(State::noveltyDetectionId(), $job->state_id);
$this->assertSame(State::noveltyDetectionId(), $job->state_id);
}

public function testStoreNdClustersTooFewImages()
Expand Down Expand Up @@ -407,9 +407,9 @@ public function testStoreKnowledgeTransfer()

$job = MaiaJob::first();
$this->assertTrue($job->shouldUseKnowledgeTransfer());
$this->assertEquals(State::objectDetectionId(), $job->state_id);
$this->assertSame(State::objectDetectionId(), $job->state_id);
$this->assertArrayHasKey('kt_volume_id', $job->params);
$this->assertEquals($volume->id, $job->params['kt_volume_id']);
$this->assertSame($volume->id, $job->params['kt_volume_id']);
}

public function testStoreKnowledgeTransferRestrictLabels()
Expand Down Expand Up @@ -471,11 +471,11 @@ public function testStoreKnowledgeTransferRestrictLabels()

$job = MaiaJob::first();
$this->assertTrue($job->shouldUseKnowledgeTransfer());
$this->assertEquals(State::objectDetectionId(), $job->state_id);
$this->assertSame(State::objectDetectionId(), $job->state_id);
$this->assertArrayHasKey('kt_volume_id', $job->params);
$this->assertEquals($volume->id, $job->params['kt_volume_id']);
$this->assertSame($volume->id, $job->params['kt_volume_id']);
$this->assertArrayHasKey('kt_restrict_labels', $job->params);
$this->assertEquals([$ia->label_id], $job->params['kt_restrict_labels']);
$this->assertSame([$ia->label_id], $job->params['kt_restrict_labels']);
}

public function testStoreAreaKnowledgeTransfer()
Expand Down Expand Up @@ -544,9 +544,9 @@ public function testStoreAreaKnowledgeTransfer()

$job = MaiaJob::first();
$this->assertTrue($job->shouldUseKnowledgeTransfer());
$this->assertEquals(State::objectDetectionId(), $job->state_id);
$this->assertSame(State::objectDetectionId(), $job->state_id);
$this->assertArrayHasKey('kt_volume_id', $job->params);
$this->assertEquals($volume->id, $job->params['kt_volume_id']);
$this->assertSame($volume->id, $job->params['kt_volume_id']);
}

public function testStoreAreaKnowledgeTransferLaserPointsFallback()
Expand Down Expand Up @@ -646,11 +646,11 @@ public function testStoreAreaKnowledgeTransferRestrictLabels()

$job = MaiaJob::first();
$this->assertTrue($job->shouldUseKnowledgeTransfer());
$this->assertEquals(State::objectDetectionId(), $job->state_id);
$this->assertSame(State::objectDetectionId(), $job->state_id);
$this->assertArrayHasKey('kt_volume_id', $job->params);
$this->assertEquals($volume->id, $job->params['kt_volume_id']);
$this->assertSame($volume->id, $job->params['kt_volume_id']);
$this->assertArrayHasKey('kt_restrict_labels', $job->params);
$this->assertEquals([$ia->label_id], $job->params['kt_restrict_labels']);
$this->assertSame([$ia->label_id], $job->params['kt_restrict_labels']);
}

public function testDestroy()
Expand Down
6 changes: 3 additions & 3 deletions tests/Http/Controllers/Api/TrainingProposalControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testSubmit()
Event::fake();
$this->postJson("/api/v1/maia-jobs/{$job->id}/training-proposals")->assertStatus(200);
Event::assertDispatched(MaiaJobContinued::class);
$this->assertEquals(State::objectDetectionId(), $job->fresh()->state_id);
$this->assertSame(State::objectDetectionId(), $job->fresh()->state_id);

// Job is no longer in training proposal state.
$this->postJson("/api/v1/maia-jobs/{$job->id}/training-proposals")->assertStatus(422);
Expand Down Expand Up @@ -116,7 +116,7 @@ public function testUpdate()

$a->refresh();
$this->assertTrue($a->selected);
$this->assertEquals([10, 20, 30], $a->points);
$this->assertSame([10, 20, 30], $a->points);
}

public function testUpdateAfterState()
Expand Down Expand Up @@ -154,7 +154,7 @@ public function testUpdatePoints()
->assertStatus(200);

Queue::assertPushed(ProcessNoveltyDetectedImage::class, function ($job) use ($a) {
$this->assertEquals([$a->id], $job->only);
$this->assertSame([$a->id], $job->only);
$this->assertFalse($job->skipFeatureVectors);

return true;
Expand Down
4 changes: 2 additions & 2 deletions tests/Http/Requests/UpdateUserSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public function testUpdate()
$this->putJson("/api/v1/users/my/settings", ['maia_notifications' => 'email'])
->assertStatus(200);

$this->assertEquals('email', $this->user()->fresh()->getSettings('maia_notifications'));
$this->assertSame('email', $this->user()->fresh()->getSettings('maia_notifications'));

$this->putJson("/api/v1/users/my/settings", ['maia_notifications' => 'web'])
->assertStatus(200);

$this->assertEquals('web', $this->user()->fresh()->getSettings('maia_notifications'));
$this->assertSame('web', $this->user()->fresh()->getSettings('maia_notifications'));
}
}
12 changes: 6 additions & 6 deletions tests/Jobs/ConvertAnnotationCandidatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public function testHandle()

$a = $c1->fresh()->annotation;
$this->assertNotNull($a);
$this->assertEquals([1, 2, 3], $a->points);
$this->assertSame([1, 2, 3], $a->points);
$annotationLabel = $a->labels()->first();
$this->assertEquals($label->id, $annotationLabel->label_id);
$this->assertEquals($user->id, $annotationLabel->user_id);
$this->assertSame($label->id, $annotationLabel->label_id);
$this->assertSame($user->id, $annotationLabel->user_id);

$this->assertEquals($annotation->id, $c2->fresh()->annotation_id);
$this->assertSame($annotation->id, $c2->fresh()->annotation_id);

Queue::assertPushed(ProcessAnnotatedImage::class, function ($job) use ($c1, $a) {
$this->assertEquals($c1->image_id, $job->file->id);
$this->assertEquals([$a->id], $job->only);
$this->assertSame($c1->image_id, $job->file->id);
$this->assertSame([$a->id], $job->only);

return true;
});
Expand Down
32 changes: 16 additions & 16 deletions tests/Jobs/GenerateAnnotationFeatureVectorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public function testHandleTrainingProposals()
$filename = array_keys($input)[0];
$this->assertArrayHasKey($tp->id, $input[$filename]);
$box = $input[$filename][$tp->id];
$this->assertEquals([5, 5, 15, 15], $box);
$this->assertSame([5, 5, 15, 15], $box);

$vectors = TrainingProposalFeatureVector::where('job_id', $j->id)->get();
$this->assertCount(1, $vectors);
$this->assertEquals($tp->id, $vectors[0]->id);
$this->assertEquals(range(0, 383), $vectors[0]->vector->toArray());
$this->assertSame($tp->id, $vectors[0]->id);
$this->assertSame(range(0, 383), $vectors[0]->vector->toArray());
}

public function testHandleAnnotationCandidates()
Expand Down Expand Up @@ -80,12 +80,12 @@ public function testHandleAnnotationCandidates()
$filename = array_keys($input)[0];
$this->assertArrayHasKey($ac->id, $input[$filename]);
$box = $input[$filename][$ac->id];
$this->assertEquals([5, 5, 15, 15], $box);
$this->assertSame([5, 5, 15, 15], $box);

$vectors = AnnotationCandidateFeatureVector::where('job_id', $j->id)->get();
$this->assertCount(1, $vectors);
$this->assertEquals($ac->id, $vectors[0]->id);
$this->assertEquals(range(0, 383), $vectors[0]->vector->toArray());
$this->assertSame($ac->id, $vectors[0]->id);
$this->assertSame(range(0, 383), $vectors[0]->vector->toArray());
}

public function testHandleConvertPoint()
Expand All @@ -112,7 +112,7 @@ public function testHandleConvertPoint()
$filename = array_keys($input)[0];
$this->assertArrayHasKey($tp->id, $input[$filename]);
$box = $input[$filename][$tp->id];
$this->assertEquals([188, 188, 412, 412], $box);
$this->assertSame([188, 188, 412, 412], $box);
}

public function testHandleConvertRectangle()
Expand All @@ -139,7 +139,7 @@ public function testHandleConvertRectangle()
$filename = array_keys($input)[0];
$this->assertArrayHasKey($tp->id, $input[$filename]);
$box = $input[$filename][$tp->id];
$this->assertEquals([10, 10, 20, 20], $box);
$this->assertSame([10, 10, 20, 20], $box);
}

public function testHandleConvertLineString()
Expand All @@ -166,7 +166,7 @@ public function testHandleConvertLineString()
$filename = array_keys($input)[0];
$this->assertArrayHasKey($tp->id, $input[$filename]);
$box = $input[$filename][$tp->id];
$this->assertEquals([10, 10, 20, 20], $box);
$this->assertSame([10, 10, 20, 20], $box);
}

public function testHandleConvertEllipse()
Expand All @@ -193,7 +193,7 @@ public function testHandleConvertEllipse()
$filename = array_keys($input)[0];
$this->assertArrayHasKey($tp->id, $input[$filename]);
$box = $input[$filename][$tp->id];
$this->assertEquals([10, 10, 20, 20], $box);
$this->assertSame([10, 10, 20, 20], $box);
}

public function testHandleConvertPolygon()
Expand All @@ -220,7 +220,7 @@ public function testHandleConvertPolygon()
$filename = array_keys($input)[0];
$this->assertArrayHasKey($tp->id, $input[$filename]);
$box = $input[$filename][$tp->id];
$this->assertEquals([10, 10, 20, 20], $box);
$this->assertSame([10, 10, 20, 20], $box);
}

public function testHandleCoodinatesOutsideImageNegative()
Expand All @@ -247,7 +247,7 @@ public function testHandleCoodinatesOutsideImageNegative()
$filename = array_keys($input)[0];
$this->assertArrayHasKey($tp->id, $input[$filename]);
$box = $input[$filename][$tp->id];
$this->assertEquals([0, 0, 30, 30], $box);
$this->assertSame([0, 0, 30, 30], $box);
}

public function testHandleCoodinatesOutsideImageNegativeProblematic()
Expand Down Expand Up @@ -280,7 +280,7 @@ public function testHandleCoodinatesOutsideImageNegativeProblematic()
$this->assertArrayHasKey($tp->id, $input[$filename]);
$box = $input[$filename][$tp->id];
// Moving the box outside negative space makes it overflow in the positive space.
$this->assertEquals([0, 0, 25, 25], $box);
$this->assertSame([0, 0, 25, 25], $box);
}

public function testHandleCoodinatesOutsideImagePositive()
Expand Down Expand Up @@ -312,7 +312,7 @@ public function testHandleCoodinatesOutsideImagePositive()
$filename = array_keys($input)[0];
$this->assertArrayHasKey($tp->id, $input[$filename]);
$box = $input[$filename][$tp->id];
$this->assertEquals([70, 70, 100, 100], $box);
$this->assertSame([70, 70, 100, 100], $box);
}

public function testHandleCoodinatesOutsideImagePositiveProblematic()
Expand Down Expand Up @@ -345,7 +345,7 @@ public function testHandleCoodinatesOutsideImagePositiveProblematic()
$this->assertArrayHasKey($tp->id, $input[$filename]);
$box = $input[$filename][$tp->id];
// Moving the box outside positive space makes it overflow in the negative space.
$this->assertEquals([0, 0, 25, 25], $box);
$this->assertSame([0, 0, 25, 25], $box);
}

public function testHandleCoodinatesOutsideImageBoth()
Expand Down Expand Up @@ -377,7 +377,7 @@ public function testHandleCoodinatesOutsideImageBoth()
$filename = array_keys($input)[0];
$this->assertArrayHasKey($tp->id, $input[$filename]);
$box = $input[$filename][$tp->id];
$this->assertEquals([0, 0, 100, 100], $box);
$this->assertSame([0, 0, 100, 100], $box);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Jobs/NoveltyDetectionFailureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testHandle()
Notification::assertSentTo($job->user, NoveltyDetectionFailed::class);

$job->refresh();
$this->assertEquals(State::failedNoveltyDetectionId(), $job->state_id);
$this->assertEquals('This is the message.', $job->error['message']);
$this->assertSame(State::failedNoveltyDetectionId(), $job->state_id);
$this->assertSame('This is the message.', $job->error['message']);
}
}
Loading

0 comments on commit 1971d62

Please sign in to comment.