You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have troubles mocking some HttpClient instance with the browser after validating a form.
Here is the code:
$this->browser()
->use(function () {
self::getContainer()->set('test.http_client', newMockHttpClient(newMockResponse()));
})
->visit('/') // some http calls are made here, using the mock client
->assertSuccessful()
->fillField('form[date]', '2021-11-10') // fill some fields
->click('form_search') // this click redirects us on the same page
->assertSuccessful() // :boom: 500 => the http_client is not mocked
Adding some dumps give me some clues
->use(function () {
// prints Symfony\Component\HttpClient\MockHttpClientdump(self::getContainer()->get('test.http_client')::class);
})
->click('form_search')
->use(function () {
// prints Symfony\Component\HttpClient\RetryableHttpClientdump(self::getContainer()->get('test.http_client')::class);
})
any ideas?
I saw this issue which is somehow related, but I don't even know where I could reuse the same "mocked container" or something else...
thanks for your help!
The text was updated successfully, but these errors were encountered:
BTW, the built container should be considered immutable - calling set() could have unintended consequences I believe. I think the service mocking library is your best bet. It allows you to swap/mock services and these swapped/mocked services will be used for the remainder of your test - even between kernel reboots/container resets.
Hello,
I have troubles mocking some
HttpClient
instance with the browser after validating a form.Here is the code:
Adding some dumps give me some clues
any ideas?
I saw this issue which is somehow related, but I don't even know where I could reuse the same "mocked container" or something else...
thanks for your help!
The text was updated successfully, but these errors were encountered: