Nette bridge - service http.response requires return type is Nette\Http\Response instead of Nette\Http\IResponse
JanMikes opened this issue · 3 comments
Version: 3.0.2
Bug Description
I am using symfony\browserkit component in integration tests with nette application, the problem is return type from DI container for service http.response
is specific class instead of interface, which prevents replacing it with own implementation
Here is the response source code: https://github.com/NBrowserKit/NBrowserKit/blob/v2.0.0/src/NetteResponseProxy.php
/** @var Nette\Http\IResponse $response */
$container->removeService('httpResponse');
$container->addService('httpResponse', $response);
and i receive
Nette\InvalidArgumentException : Service 'http.response' must be instance of Nette\Http\Response, NBrowserKit\Response given.
/home/users/klarka/wc/17/vendor/nette/di/src/DI/Container.php:83
/home/users/klarka/wc/17/tests/Integration/BrowserClient.php:33
/home/users/klarka/wc/17/vendor/symfony/browser-kit/Client.php:407
/home/users/klarka/wc/17/tests/Integration/Cache/Nocache/NoCacheTest.php:36
Steps To Reproduce
Replace response service with IResponse
implementation but not Nette\Http\Response
$container->removeService('httpResponse');
$container->addService('httpResponse', $response);
Expected Behavior
To work :-)
Possible Solution
src/Bridges/HttpDI/HttpExtension.php:
$response = $builder->addDefinition($this->prefix('response'))
+ ->setType(Nette\Http\IResponse::class)
->setFactory(Nette\Http\Response::class);
Same issue might be with request (not tested though).
It is related to #90 (comment) & #147. Solution is to add class: Nette\Http\IResponse
in config file.
Thank you for your hint.
services:
http.response:
class: Nette\Http\IResponse
throws Nette\DI\ServiceCreationException : Service 'http.response': Class Nette\Http\IResponse not found.
but
services:
http.response:
type: Nette\Http\IResponse
fixes it 😄