Skip to content

Commit

Permalink
Merge pull request #906 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 29, 2024
2 parents 7f3cefe + 894c8f3 commit 535191f
Show file tree
Hide file tree
Showing 69 changed files with 581 additions and 578 deletions.
5 changes: 3 additions & 2 deletions app/Http/Controllers/Api/Volumes/MetadataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ protected function updateImageMetadata(StoreVolumeMetadata $request)
}
$image->fillable(ImageMetadata::ALLOWED_ATTRIBUTES);
$image->fill($fill->toArray());

$metadata = $row->only(ImageMetadata::ALLOWED_METADATA);
$metadata = $row
->only(ImageMetadata::ALLOWED_METADATA)
->map(fn ($str) => strpos($str, '.') ? floatval($str) : intval($str));
$image->metadata = array_merge($image->metadata, $metadata->toArray());
$image->save();
}
Expand Down
6 changes: 3 additions & 3 deletions tests/php/AnnotationSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testUsers()
$user = UserTest::create();
$this->model->users()->attach($user);
$sessionUser = $this->model->users()->first();
$this->assertEquals([
$this->assertSame([
'id' => $user->id,
'firstname' => $user->firstname,
'lastname' => $user->lastname,
Expand Down Expand Up @@ -608,8 +608,8 @@ public function testStartsAtEndsAtISO8601()
'ends_at' => '2016-09-07T00:00:00.000+02:00',
]);

$this->assertEquals('2016-09-04T22:00:00+00:00', $session->starts_at_iso8601);
$this->assertEquals('2016-09-06T22:00:00+00:00', $session->ends_at_iso8601);
$this->assertSame('2016-09-04T22:00:00+00:00', $session->starts_at_iso8601);
$this->assertSame('2016-09-06T22:00:00+00:00', $session->ends_at_iso8601);

$this->assertArrayHasKey('starts_at_iso8601', $session->toArray());
$this->assertArrayHasKey('ends_at_iso8601', $session->toArray());
Expand Down
8 changes: 4 additions & 4 deletions tests/php/AnnouncementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ public function testScopeActive()
{
$this->model->show_until = '2022-10-20 16:17:00';
$this->model->save();
$this->assertEquals(0, Announcement::active()->count());
$this->assertSame(0, Announcement::active()->count());

$this->model->show_until = now()->addDay();
$this->model->save();
$this->assertEquals(1, Announcement::active()->count());
$this->assertSame(1, Announcement::active()->count());

$this->model->show_until = null;
$this->model->save();
$this->assertEquals(1, Announcement::active()->count());
$this->assertSame(1, Announcement::active()->count());
}

public function testGetActive()
{
$this->model->show_until = now()->addDay();
$this->model->save();

$this->assertEquals($this->model->id, Announcement::getActive()->id);
$this->assertSame($this->model->id, Announcement::getActive()->id);

$this->model->delete();
$this->assertNull(Announcement::getActive());
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Console/Commands/PruneNotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testHandle()
]);

(new PruneNotifications)->handle();
$this->assertEquals(2, DatabaseNotification::count());
$this->assertSame(2, DatabaseNotification::count());
$this->assertNull(DatabaseNotification::find('1'));
}
}
8 changes: 4 additions & 4 deletions tests/php/FederatedSearchInstanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ public function testScopeWithRemoteToken()
public function testSetRemoteTokenAttribute()
{
$this->model->remote_token = 'test';
$this->assertEquals('test', decrypt($this->model->getAttributes()['remote_token']));
$this->assertSame('test', decrypt($this->model->getAttributes()['remote_token']));
}

public function testGetRemoteTokenAttribute()
{
$this->model->setRawAttributes(['remote_token' => encrypt('test')]);
$this->assertEquals('test', $this->model->remote_token);
$this->assertSame('test', $this->model->remote_token);
}

public function testCreateLocalToken()
{
$token = $this->model->createLocalToken();
$this->assertEquals(64, strlen($token));
$this->assertEquals(hash('sha256', $token), $this->model->local_token);
$this->assertSame(64, strlen($token));
$this->assertSame(hash('sha256', $token), $this->model->local_token);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public function testUpdate()

$session = $session->fresh();

$this->assertEquals('my cool name', $session->name);
$this->assertEquals('2016-09-07', $session->ends_at->format('Y-m-d'));
$this->assertEquals([$this->admin()->id], $session->users()->pluck('id')->all());
$this->assertSame('my cool name', $session->name);
$this->assertSame('2016-09-07', $session->ends_at->format('Y-m-d'));
$this->assertSame([$this->admin()->id], $session->users()->pluck('id')->all());
}

public function testUpdateTimezones()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testStore()
// show_until must be in the future
->assertStatus(422);

$this->assertEquals(0, Announcement::count());
$this->assertSame(0, Announcement::count());

$this
->json('POST', '/api/v1/announcements', [
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Http/Controllers/Api/ApiTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public function testStore()
// missing purpose
$response->assertStatus(422);

$this->assertEquals(1, $token->owner->apiTokens()->count());
$this->assertSame(1, $token->owner->apiTokens()->count());

$response = $this->json('POST', '/api/v1/api-tokens', ['purpose' => 'abc'])
->assertJsonFragment(['purpose' => 'abc']);

$response->assertSuccessful();
$this->assertEquals(2, $token->owner->apiTokens()->count());
$this->assertSame(2, $token->owner->apiTokens()->count());
$this->assertStringContainsString('"token":"', $response->getContent());

$response = $this->post('/api/v1/api-tokens', ['purpose' => 'def'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public function testStore()

$instance = FederatedSearchInstance::first();
$this->assertNotNull($instance);
$this->assertEquals('my instance', $instance->name);
$this->assertEquals('https://example.com', $instance->url);
$this->assertSame('my instance', $instance->name);
$this->assertSame('https://example.com', $instance->url);
$this->assertNull($instance->local_token);
$this->assertNull($instance->remote_token);
$this->assertNull($instance->indexed_at);
Expand Down Expand Up @@ -86,8 +86,8 @@ public function testUpdate()
->assertStatus(200);

$instance->refresh();
$this->assertEquals('my updated instance', $instance->name);
$this->assertEquals('https://www.example.com', $instance->url);
$this->assertSame('my updated instance', $instance->name);
$this->assertSame('https://www.example.com', $instance->url);
}

public function testUpdateSetRemoteToken()
Expand Down Expand Up @@ -116,12 +116,12 @@ public function testUpdateSetRemoteToken()
])
->assertStatus(200);

$this->assertEquals('mytoken', $instance->fresh()->remote_token);
$this->assertSame('mytoken', $instance->fresh()->remote_token);
$this->assertCount(1, $container);
$request = $container[0]['request'];
$this->assertEquals('https://example.com/api/v1/federated-search-index', strval($request->getUri()));
$this->assertEquals('Bearer mytoken', $request->getHeaderLine('Authorization'));
$this->assertEquals('HEAD', $request->getMethod());
$this->assertSame('https://example.com/api/v1/federated-search-index', strval($request->getUri()));
$this->assertSame('Bearer mytoken', $request->getHeaderLine('Authorization'));
$this->assertSame('HEAD', $request->getMethod());
Bus::assertDispatched(UpdateFederatedSearchIndex::class);
}

Expand Down Expand Up @@ -254,9 +254,9 @@ public function testUpdateUrlWithRemoteToken()
Bus::assertNotDispatched(UpdateFederatedSearchIndex::class);
$this->assertCount(1, $container);
$request = $container[0]['request'];
$this->assertEquals('https://www.example.com/api/v1/federated-search-index', strval($request->getUri()));
$this->assertEquals('Bearer mytoken', $request->getHeaderLine('Authorization'));
$this->assertEquals('HEAD', $request->getMethod());
$this->assertSame('https://www.example.com/api/v1/federated-search-index', strval($request->getUri()));
$this->assertSame('Bearer mytoken', $request->getHeaderLine('Authorization'));
$this->assertSame('HEAD', $request->getMethod());
}

public function testUpdateGetLocalToken()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ public function store($url)
])
->assertStatus(200);

$this->assertEquals(3, $this->annotation->image->annotations()->count());
$this->assertSame(3, $this->annotation->image->annotations()->count());
$annotation = $this->annotation->image->annotations()->orderBy('id', 'desc')->first();
$this->assertEquals(Shape::pointId(), $annotation->shape_id);
$this->assertEquals([100, 100], $annotation->points);
$this->assertEquals(1, $annotation->labels()->count());
$this->assertEquals($this->labelRoot()->id, $annotation->labels()->first()->label_id);
$this->assertSame(Shape::pointId(), $annotation->shape_id);
$this->assertSame([100, 100], $annotation->points);
$this->assertSame(1, $annotation->labels()->count());
$this->assertSame($this->labelRoot()->id, $annotation->labels()->first()->label_id);
}

public function testStoreValidation()
Expand Down Expand Up @@ -193,7 +193,7 @@ public function storeValidation($url)
]])
->assertStatus(422);

$this->assertEquals(1, $this->annotation->image->annotations()->count());
$this->assertSame(1, $this->annotation->image->annotations()->count());

$this
->postJson($url, [[
Expand Down Expand Up @@ -259,7 +259,7 @@ public function testStoreLabelIdIsString()
])
->assertStatus(200);

$this->assertEquals(2, $this->annotation->image->annotations()->count());
$this->assertSame(2, $this->annotation->image->annotations()->count());
}

public function testStoreLabelIdIsFloat()
Expand Down
14 changes: 7 additions & 7 deletions tests/php/Http/Controllers/Api/ImageAnnotationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ public function testStore()

$annotation = $this->image->annotations->first();
$this->assertNotNull($annotation);
$this->assertEquals(2, sizeof($annotation->points));
$this->assertEquals(1, $annotation->labels()->count());
$this->assertSame(2, sizeof($annotation->points));
$this->assertSame(1, $annotation->labels()->count());
}

public function testStoreValidatePoints()
Expand Down Expand Up @@ -342,16 +342,16 @@ public function update($url)

$this->annotation = $this->annotation->fresh();

$this->assertEquals(4, sizeof($this->annotation->points));
$this->assertEquals(15, $this->annotation->points[1]);
$this->assertSame(4, sizeof($this->annotation->points));
$this->assertSame(15, $this->annotation->points[1]);

$response = $this->json('PUT', "{$url}/{$id}", ['points' => [20, 25]]);
$response->assertStatus(200);

$this->annotation = $this->annotation->fresh();

$this->assertEquals(2, sizeof($this->annotation->points));
$this->assertEquals(25, $this->annotation->points[1]);
$this->assertSame(2, sizeof($this->annotation->points));
$this->assertSame(25, $this->annotation->points[1]);
}

public function testUpdateInvalidPoints()
Expand Down Expand Up @@ -429,7 +429,7 @@ public function updateChangeShape($url)
->assertStatus(200);

$this->annotation->refresh();
$this->assertEquals(Shape::circleId(), $this->annotation->shape_id);
$this->assertSame(Shape::circleId(), $this->annotation->shape_id);
}

public function testDestroy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function store($url)
]);
$response->assertStatus(422);

$this->assertEquals(0, $this->annotation->labels()->count());
$this->assertSame(0, $this->annotation->labels()->count());

$this->beUser();
$response = $this->post("{$url}/{$id}/labels", [
Expand All @@ -151,7 +151,7 @@ public function store($url)
'confidence' => 0.1,
]);
$response->assertStatus(201);
$this->assertEquals(1, $this->annotation->labels()->count());
$this->assertSame(1, $this->annotation->labels()->count());

Event::assertDispatched(AnnotationLabelAttached::class);

Expand All @@ -163,7 +163,7 @@ public function store($url)
$response->assertStatus(201);

Event::assertDispatched(AnnotationLabelAttached::class);
$this->assertEquals(2, $this->annotation->labels()->count());
$this->assertSame(2, $this->annotation->labels()->count());
$response->assertJsonFragment([
'id' => $this->labelRoot()->id,
'name' => $this->labelRoot()->name,
Expand All @@ -184,7 +184,7 @@ public function store($url)
]);
// the same user cannot attach the same label twice
$response->assertStatus(400);
$this->assertEquals(2, $this->annotation->labels()->count());
$this->assertSame(2, $this->annotation->labels()->count());
}

public function testUpdate()
Expand Down Expand Up @@ -225,14 +225,14 @@ public function update($url)
$response = $this->put("{$url}/{$id}");
$response->assertStatus(200);

$this->assertEquals(0.5, $annotationLabel->fresh()->confidence);
$this->assertSame(0.5, $annotationLabel->fresh()->confidence);
$this->beEditor();
$response = $this->put("{$url}/{$id}", [
'_token' => Session::token(),
'confidence' => 0.1,
]);
$response->assertStatus(200);
$this->assertEquals(0.1, $annotationLabel->fresh()->confidence);
$this->assertSame(0.1, $annotationLabel->fresh()->confidence);
}

public function testDestroy()
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Http/Controllers/Api/ImageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testShowFile()

$response = $this->get("/api/v1/images/{$id}/file");
$response->assertStatus(200);
$this->assertEquals('image/jpeg', $response->headers->get('content-type'));
$this->assertSame('image/jpeg', $response->headers->get('content-type'));
}

public function testShowFileTiled()
Expand Down
8 changes: 4 additions & 4 deletions tests/php/Http/Controllers/Api/ImageLabelControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testStore()
$response = $this->json('POST', "/api/v1/images/{$id}/labels");
$response->assertStatus(422);

$this->assertEquals(0, $this->image->labels()->count());
$this->assertSame(0, $this->image->labels()->count());

$this->beUser();
$response = $this->post("/api/v1/images/{$id}/labels", [
Expand All @@ -73,21 +73,21 @@ public function testStore()
'label_id' => $this->labelRoot()->id,
]);
$response->assertSuccessful();
$this->assertEquals(1, $this->image->labels()->count());
$this->assertSame(1, $this->image->labels()->count());

$this->beAdmin();
// the same label cannot be attached twice
$response = $this->post("/api/v1/images/{$id}/labels", [
'label_id' => $this->labelRoot()->id,
]);
$response->assertStatus(400);
$this->assertEquals(1, $this->image->labels()->count());
$this->assertSame(1, $this->image->labels()->count());

$response = $this->json('POST', "/api/v1/images/{$id}/labels", [
'label_id' => $this->labelChild()->id,
]);
$response->assertSuccessful();
$this->assertEquals(2, $this->image->labels()->count());
$this->assertSame(2, $this->image->labels()->count());
$response->assertJsonFragment([
'id' => $this->labelChild()->id,
'name' => $this->labelChild()->name,
Expand Down
6 changes: 3 additions & 3 deletions tests/php/Http/Controllers/Api/LabelControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public function testUpdate()
$response->assertStatus(200);

$label = $label->fresh();
$this->assertEquals('new label name', $label->name);
$this->assertEquals('bada55', $label->color);
$this->assertEquals($sibling->id, $label->parent_id);
$this->assertSame('new label name', $label->name);
$this->assertSame('bada55', $label->color);
$this->assertSame($sibling->id, $label->parent_id);
}

public function testUpdateVersionedTree()
Expand Down
Loading

0 comments on commit 535191f

Please sign in to comment.