Ana içeriğe atla

Kayıtlar

Şubat, 2022 tarihine ait yayınlar gösteriliyor

Laravel Model İlişki Unit Test

Laravel Elequent modelleri laravelin en güçlü taraflarından birisi. Modelleri birbirleri ile ilişkilendirerek çok rahat veri yapılarını oluşturabiliyorsunuz. Laravele eklenen ilişkiler için unit test yazmanız gerekse bunu şöyle yapabilirsiniz. <?php namespace App\Models ; use Illuminate\Database\Eloquent\Factories\ HasFactory ; use Illuminate\Database\Eloquent\ Model ; class Account extends Model { use HasFactory ; public function investor () { return $this -> belongsTo ( Investor :: class ); } } Bu örnek modelimiz olsun. İnvestor ilişkisine birim testi yazmak isteyelim. <?php namespace Tests\Unit\Models ; use App\Models\ Account ; use App\Models\ Investor ; use Mockery ; use PHPUnit\Framework\ TestCase ; class AccountTest extends TestCase { public function test_belongs_to_investor () { $account = Mockery :: mock ( Account :: class )-> makePartial (); $account -> shouldReceive ( 'belongsTo' )