Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nette bridge - service http.response requires return type is Nette\Http\Response instead of Nette\Http\IResponse #169

Closed
JanMikes opened this issue Oct 16, 2019 · 3 comments

Comments

@JanMikes
Copy link

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);
@JanMikes
Copy link
Author

Same issue might be with request (not tested though).

@dg
Copy link
Member

dg commented Oct 16, 2019

It is related to #90 (comment) & #147. Solution is to add class: Nette\Http\IResponse in config file.

@JanMikes
Copy link
Author

JanMikes commented Oct 16, 2019

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 😄

@dg dg closed this as completed Oct 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants