Skip to content

Commit 23b6fe9

Browse files
willtjdivine
authored andcommitted
tests: for snake case morph relation name
1 parent 551ec9f commit 23b6fe9

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

tests/RelationsTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,21 +370,21 @@ public function testMorph(): void
370370
$this->assertEquals($photo->id, $client->photo->id);
371371

372372
$photo = Photo::first();
373-
$this->assertEquals($photo->imageable->name, $user->name);
373+
$this->assertEquals($photo->hasImage->name, $user->name);
374374

375375
$user = User::with('photos')->find($user->_id);
376376
$relations = $user->getRelations();
377377
$this->assertArrayHasKey('photos', $relations);
378378
$this->assertEquals(1, $relations['photos']->count());
379379

380-
$photos = Photo::with('imageable')->get();
380+
$photos = Photo::with('hasImage')->get();
381381
$relations = $photos[0]->getRelations();
382-
$this->assertArrayHasKey('imageable', $relations);
383-
$this->assertInstanceOf(User::class, $photos[0]->imageable);
382+
$this->assertArrayHasKey('hasImage', $relations);
383+
$this->assertInstanceOf(User::class, $photos[0]->hasImage);
384384

385385
$relations = $photos[1]->getRelations();
386-
$this->assertArrayHasKey('imageable', $relations);
387-
$this->assertInstanceOf(Client::class, $photos[1]->imageable);
386+
$this->assertArrayHasKey('hasImage', $relations);
387+
$this->assertInstanceOf(Client::class, $photos[1]->hasImage);
388388
}
389389

390390
public function testHasManyHas(): void

tests/models/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function users(): BelongsToMany
2020

2121
public function photo(): MorphOne
2222
{
23-
return $this->morphOne('Photo', 'imageable');
23+
return $this->morphOne('Photo', 'has_image');
2424
}
2525

2626
public function addresses(): HasMany

tests/models/Photo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Photo extends Eloquent
1111
protected $collection = 'photos';
1212
protected static $unguarded = true;
1313

14-
public function imageable(): MorphTo
14+
public function hasImage(): MorphTo
1515
{
1616
return $this->morphTo();
1717
}

tests/models/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function groups()
7373

7474
public function photos()
7575
{
76-
return $this->morphMany('Photo', 'imageable');
76+
return $this->morphMany('Photo', 'has_image');
7777
}
7878

7979
public function addresses()

0 commit comments

Comments
 (0)