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

Call to a member function json() on null #34

Open
soullivaneuh opened this issue Jul 31, 2015 · 1 comment
Open

Call to a member function json() on null #34

soullivaneuh opened this issue Jul 31, 2015 · 1 comment

Comments

@soullivaneuh
Copy link
Contributor

Behat config:

default:
    calls:
        error_reporting: 14335 # E_ALL & ~E_USER_DEPRECATED
    extensions:
        Behat\Symfony2Extension: ~
        Behat\WebApiExtension: ~
        Behat\MinkExtension:
            sessions:
                default:
                    symfony2: ~
    suites:
        default:
            contexts:
             - Behat\WebApiExtension\Context\WebApiContext
             - \FeatureContext

Behat feature:

Feature: api/security
  In order to fully or partially access the api
  I need to have the good rights

  Scenario: API as anonymous
    Given I am on "/api/user"
    And the response status code should be 401
    And the response should contain json:
    """
    {
       "error" : "invalid_grant",
       "error_description" : "No API key given."
    }
    """

Result:

$ behat features/api/security.feature 
Feature: api/security
  In order to fully or partially access the api
  I need to have the good rights

  Scenario: API as anonymous                   # features/api/security.feature:5
    Given I am on "/api/user"                  # FeatureContext::visit()
    And the response status code should be 401 # FeatureContext::assertResponseStatus()
PHP Fatal error:  Call to a member function json() on null in project/vendor/behat/web-api-extension/src/Context/WebApiContext.php on line 244
[...]

Is that an issue or a misconfiguration?

Thanks.

@soullivaneuh
Copy link
Contributor Author

I think I have a clue:

/**
 * @var \GuzzleHttp\Message\ResponseInterface
 */
private $response;

AFAIK, if Guzzle got a 4xx or a 5xx error, it throw an exception instead of returning the response.

I don't know if guzzle is the best for it or if we just have to configure it, but a 401 code with response could be possible:

$ curl http://localhost:8000/api/user | json_pp 
{
   "error" : "invalid_grant",
   "error_description" : "No API key given."
}

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

No branches or pull requests

1 participant