-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Astrotomic/issue-1
add model assertion that two models are related
- Loading branch information
Showing
5 changed files
with
144 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Astrotomic\PhpunitAssertions\Tests\Laravel\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class Comment extends Model | ||
{ | ||
protected $table = 'comments'; | ||
protected $guarded = []; | ||
|
||
public static function migrate(): void | ||
{ | ||
Schema::create((new self)->table, static function (Blueprint $table): void { | ||
$table->increments('id'); | ||
$table->text('message'); | ||
$table->foreignId('post_id')->constrained('posts'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
public function post(): BelongsTo | ||
{ | ||
return $this->belongsTo(Post::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Astrotomic\PhpunitAssertions\Tests\Laravel\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\HasMany; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class Post extends Model | ||
{ | ||
protected $table = 'posts'; | ||
protected $guarded = []; | ||
|
||
public static function migrate(): void | ||
{ | ||
Schema::create((new self)->table, static function (Blueprint $table): void { | ||
$table->increments('id'); | ||
$table->string('title'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
public function comments(): HasMany | ||
{ | ||
return $this->hasMany(Comment::class); | ||
} | ||
} |