Open ehibes opened 6 years ago
Hello,
You are printing the response headers instead of the request. On my end, I used this context for the authorization header and it was working great.
Ok for the response but executing this scenario and testing header return Behatch\Context\RestContext::theHeaderShouldContain() The header 'authorization' doesn't exist (OutOfBoundsException)
@login
Scenario: Create a result as admin
When I add "Content-Type" header equal to "application/ld+json"
And I add "Accept" header equal to "application/ld+json"
And the header "Authorization" should contain "Bearer"
And I send a "POST" request to "/api/results" with body:
I guess (not sure) it's because $scope->getEnvironment()->getContext(RestContext::class)
returns a new instance of RestContext
.
You can try to extend Behatch RestContext
and use this new class in your context configuration instead of the one from Behatch.
A bit like this https://www.bgalati.fr/blog/php-matcher-with-behat-to-assert-unpredictable-json/.
There is a context problem for sure, following features don't work either and return the same output :
Behatch\Context\RestContext::theHeaderShouldContain() The header 'authorization' doesn't exist (OutOfBoundsException)
When I add "Content-Type" header equal to "application/ld+json"
And I add "Accept" header equal to "application/ld+json"
And I add "Authorization" header equal to "Bearer token"
And the header "Authorization" should contain "Bearer"
Did you try what I proposed? Real world example:
I found the bug. When I put @logout
annotation anywhere in my features, the authorization header is missing, even if a @login
annotation is present on next scenario.
/**
* @BeforeScenario @logout
*/
public function logout() {
$this->restContext->iAddHeaderEqualTo('Authorization', '');
}
Hi,
I'm trying to login to an API before execute some behat tests with this function. It seems not to accept the header.
The last line return following output, where authorization header is missing