public function create(Request $request, Create\Handler $handler): Response
final readonly class Handler
{
public function __construct(
private EnterpriseDispatcherRepository $enterpriseDispatcherRepository,
private Flusher $flusher,
private EnterpriseDispatcherService $enterpriseDispatcherService,
private CustomHttpClient $customHttpClient,
) {}
public function handle(Command $command): void
{
dd($this->enterpriseDispatcherService->getEnterpriseDispatcherRealUserId($command->url, $command->login, $command->password));
}
$client->getContainer()->get(EnterpriseDispatcherService::class)
, то вернёт нужно значение, но как только уходит в контроллер, он использует настоящие классы, игнорируя те, что я замокал. public function testCreate(): void
{
$client = self::createClient();
$service = $this->createMock(EnterpriseDispatcherService::class);
$service->expects($this->once())
->method('getEnterpriseDispatcherRealUserId')
->willReturn($userId = 12333);
self::getContainer()->set(EnterpriseDispatcherService::class, $service);
$this->loginAs('test_admin');
$client->request('GET', '/enterprise-dispatchers/create');
$crawler = $client->submitForm('Create', [
'form[name]' => $name = 'Test Enterprise Dispatcher',
'form[url]' => 'http://127.0.0.2:9003',
'form[login]' => 'test_login',
'form[password]' => 'test_password',
]);
}
$client->submitForm()
, оно должен вернуть 12333, но оно упадёт с ошибкой, потому что будет использовать оригинальный класс.