-
Notifications
You must be signed in to change notification settings - Fork 61
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
using "Behatch\Context\RestContext" cause The service has a dependency on a non-existent service "behatch.http_call.request" #111
Comments
I have the same problem. behatch.http_call.request:
class: Behatch\HttpCall\Request
arguments:
- '@behat.mink'
public: false Original path with configuration: |
I have the same issue. You can inject Behatch dependencies through behat.yml like this:
Because Behatch provide a resolver to behat But symfony-extension only provide dependency injection for context as service... so:
in service_test.yaml this doesn't work (because behatch service are private and can only be injected through behat Resolver
@GrzegorzMatuszakTSH I'm not sure your solution is the best, because you provide a new reference of this object, I'm not sure that internally behatch will use the same instance. So between your context and behatch context, informations will be differents. This is a real issue. I think there is two way to handle this:
|
@CharloMez Yes, I agree with you. |
@CharloMez would you be willing to contribute the second solution? |
@pamil I'm trying, but I don't find how to get all ArgumentResolver...
I got nothing, but behat find them in it's extension here I think I miss something in symfony process. It is probably not the same container which is injected in behat extension, but I don't know how to access to the same container from SymfonyExtension. |
I tried many other solutions (extending JsonContext, calling the behatch internal container to get the JsonContext, ...) but only one worked (that's dirty though): Reflection <?php
namespace App\Tests\Behat;
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behatch\Context\JsonContext;
use Behatch\HttpCall\HttpCallResultPool;
use Behatch\Json\JsonInspector;
class JsonExtendedContext implements Context
{
private HttpCallResultPool $httpCallResultPool;
private JsonInspector $inspector;
/**
* @BeforeScenario
*/
public function beforeScenario(BeforeScenarioScope $scope)
{
$jsonContext = $scope->getEnvironment()->getContext(JsonContext::class);
$refl = new \ReflectionClass(JsonContext::class);
$httpCallResultPoolProperty = $refl->getProperty('httpCallResultPool');
$inspectorProperty = $refl->getProperty('inspector');
$httpCallResultPoolProperty->setAccessible(true);
$inspectorProperty->setAccessible(true);
$this->httpCallResultPool = $httpCallResultPoolProperty->getValue($jsonContext);
$this->inspector = $inspectorProperty->getValue($jsonContext);
}
// your steps here ... |
Given the example from the original @masoud91 comment, it seems you are only using the However this is not resolving the issue of getting the |
@pamil I'm happy to contribute the second solution if this is still needed, I implemented an extension on top of the original sf2 extension and it doesn't work with this one, so if you give me some guidance I can contribute. |
I managed to wrangle a working version by doing this:
However, using this method I couldn't get a working version to override For other services, here's the list of available services that I found in the container:
|
Hey guys, Thanks for your awesome work.
I'm trying to use Behatch RestContext in my context but I get the following error:
Am I wrong somewhere?
This is my configuration:
symfony: 4.4
composer.json:
behat.yml
service_test.yml
app/tests/Behat/FeatureContext.php
The text was updated successfully, but these errors were encountered: