Answer the question
In order to leave comments, you need to log in
How to properly lock __invoke method?
Tested class
class Handler {
public function __invoke($params)
{
// У TemplateService тоже есть метод __invoke()
$templateService = new TemplateService();
$templateService($string);
}
}
class HandlerTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$this->mockTemplateService();
}
public function testInvoke()
{
$handler = new Handler();
$handler->__invoke($params);
}
private function mockTemplateService()
{
$templateService = \Mockery::mock(TemplateService::class);
$templateService->shouldReceive('__invoke')
->with(__DIR__ .'templates/template.docx')
->andReturn(file_get_contents(__DIR__ . '../../data/template.docx'));
return $this->app->instance(TemplateService::class, $templateService);
}
}
Answer the question
In order to leave comments, you need to log in
As far as I understand, you add a mock to the container, but then manually create an object, and do not request from the container
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question