Jul 21, 2022
0
Level 23
Target [Symfony\Contracts\EventDispatcher\EventDispatcherInterface] is not instantiable while building [Symfony\Component\HttpKernel\HttpKernel].
I write a custom TestCase class which extends the basic one to override the call method:
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
//this part is custom
$uri = '/api/v1/' . $uri;
if($this->auth){
$this->withToken($this->getToken());
}
//end custom
$kernel = $this->app->make(HttpKernel::class);
$files = array_merge($files, $this->extractFilesFromDataArray($parameters));
$symfonyRequest = SymfonyRequest::create(
$this->prepareUrlForRequest($uri), $method, $parameters,
$cookies, $files, array_replace($this->serverVariables, $server), $content
);
$response = $kernel->handle(
$request = Request::createFromBase($symfonyRequest)
);
$kernel->terminate($request, $response);
if ($this->followRedirects) {
$response = $this->followRedirects($response);
}
return $this->createTestResponse($response);
}
But it will throw an error Target [Symfony\Contracts\EventDispatcher\EventDispatcherInterface] is not instantiable while building [Symfony\Component\HttpKernel\HttpKernel].
so what I do wrong?
Please or to participate in this conversation.