Answer the question
In order to leave comments, you need to log in
How to Mock PHPUnit related models in Laravel?
Hello everyone, tell me how to lock the linked model?
class Test1 extends Model
{
public function type_status()
{
return $this->belongsTo('App\Types', 'type_id');
}
}
class Types extends Model
{
}
public function testGetTable()
{
$test1= $this->createMock(Test1::class);
$test1->type_id = 1;
$types = $this->createMock(Types::class);
$types->id = 1;
$types->type = 'Type1';
$types->reduction = 'T1';
$test1->attach($types);
}
$test1->method('type_status')->willReturn('T1');
Answer the question
In order to leave comments, you need to log in
In general, my decision was:
1. installing codeception
2. wrapping the public function type_status () method in:
public function getTypes()
{
return $this->type_status;
}
Stub::make(Test1::class,
[
'getTypes' => function(){}
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question