Код: Выделить всё
class ServiceOne{
public function testOne($name){
app(ServiceTwo::class, ['name' => $name])->testTwo();
}
}
class ServiceTwo{
__construct(private string $name){}
public function testTwo(){
//so domething with $this->name;
}
}
Код: Выделить всё
$mock = \Mockery::mock(ServiceTwo::class)
->shouldReceive('testTwo')
->once()
->getMock();
$this->app->bind(ServiceTwo::class, function () use ($mock) {
return $mock;
});
app(ServiceOne::class)->testOne('testing');
Код: Выделить всё
public function testOne($name){
app(ServiceTwo::class, ['name' => $name])->testTwo();
}
Код: Выделить всё
public function testOne($name){
app(ServiceTwo::class)->testTwo();
}
Код: Выделить всё
public function testOne($name){
app(ServiceTwo::class, ['name' => ''different])->testTwo();
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... structor-a
Мобильная версия