Giter VIP home page Giter VIP logo

webapiextension's Introduction

Behat

Behat is a BDD framework for PHP to help you test business expectations.

Gitter chat License Build Status

Installing Behat

The easiest way to install Behat is by using Composer:

$> composer require --dev behat/behat

After that you'll be able to run Behat via:

$> vendor/bin/behat

Installing Development Version

Clone the repository and install dependencies via Composer:

$> composer install

After that you will be able to run development version of Behat via:

$> bin/behat

Contributing

Before contributing to Behat, please take a look at the CONTRIBUTING.md document.

Versioning

Starting from v3.0.0, Behat is following Semantic Versioning v2.0.0. This basically means that if all you do is implement interfaces (like this one) and use service constants (like this one), you would not have any backwards compatibility issues with Behat up until v4.0.0 (or later major) is released. Exception could be an extremely rare case where BC break is introduced as a measure to fix a serious issue.

You can read detailed guidance on what BC means in Symfony BC guide.

Useful Links

Contributors

webapiextension's People

Contributors

dantleech avatar fgm avatar ifdattic avatar soullivaneuh avatar stof avatar swop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webapiextension's Issues

Is it possible to configure the guzzle client ?

I'm testing an API that I just moved to https, and since I'm using a self-signed-certificate, guzzle gives me errors. Maybe the verify option should be set to false by default, and maybe it should even be configurable (not sure why though).

Here is how I worked around this problem.

Stable release

Would you please consider tagging a stable release ?
Is there anything preventing it ?

Incompatibility with guzzle 5

Due to the requirements, one cannot use guzzle 5 and the web api extension on the same project. Solution : suggest instead of require guzzle, then detect the guzzle version in use ?

iSendARequestWithValues - encoding body?

The following method:

    public function iSendARequestWithValues($method, $url, TableNode $post)
    {
        $url = $this->prepareUrl($url);
        $fields = array();

        foreach ($post->getRowsHash() as $key => $val) {
            $fields[$key] = $this->replacePlaceHolder($val);
        }

        $bodyOption = array(
          'body' => json_encode($fields),
        );
        $this->request = $this->client->createRequest($method, $url, $bodyOption);
        if (!empty($this->headers)) {
            $this->request->addHeaders($this->headers);
        }

        $this->sendRequest();
    }

Does not work, when the $fields is json encoded. When removing that line, it works perfectly. I.e, like this:

    public function iSendARequestWithValues($method, $url, TableNode $post)
    {
        $url = $this->prepareUrl($url);
        $fields = array();

        foreach ($post->getRowsHash() as $key => $val) {
            $fields[$key] = $this->replacePlaceHolder($val);
        }

        $bodyOption = array(
          'body' => $fields,
        );
        $this->request = $this->client->createRequest($method, $url, $bodyOption);
        if (!empty($this->headers)) {
            $this->request->addHeaders($this->headers);
        }

        $this->sendRequest();
    }

Now, before I submit a pull request, I want to make sure I am not getting something wrong? The bug seems too obvious.

I am testing with this data:

        When I send a POST request to "/items" with values:
            | attributes    | {"size":"1", "size_length":5} |
            | category      | 1      |

Remove dependency on PHPUnit

This has been raised before (#8), but I would like to see it revisited. PHPUnit assertions are currently used, but this involves pulling 17 (I think) other packages for just 6 assertions. We're not using PHPUnit in a project, so this is dramatically increasing the number of dependencies.

As PHPUnit doesn't provide its assertions in a standalone library, I think something else should be used, or they could just be replaced with internal ones (less convenient, but there's not that many).

Response headers are unavailable outside the WebApiContext

Since $response has been set to private and $headers is currently only used for request headers, contexts inheriting WebApiContext have no way to access the response headers.

Suggested change:

  • either mark $response as protected instead of private
  • or add $this->headers = $this->response->getHeaders(); at the end of sendRequest(), making headers usable for both request and response
  • or provide separate properties+accessors for request and response headers.

It's this repository dead?

I've being using this repo for a long time but, there is no activity and lot of PR pending.
If there is no plan to maintain this repo?
Why not ask for maintainers if there is no time for the actuals?

It's a cool tool, and I don't wanna lose it.

Thanks in advance

Check only one value in jsonArray

I'm using the And the response should contain json: step, this is working when I check a json body with { "foo": "bar" }
But when my body is a jsonArray like this[{ "foo": "bar", "bar": "foo" }] I must send all the correct datas of the first element of the jsonArray to have this step valid. This is problematic when you have a DataTime that change at every data fixtures loading...

I tried to made a custom step in my FeatureContext who will check if there is a jsonArray or not and make the good value check but I need to get the returned response of the request who's not accessible the response in WebApiExtension

Is it possible to check only one value in the first element of a jsonArray with WebApiContext or I must make a custom step ?
If I must made a custom step how can I have access to the request response in my FeatureContext ?

This the type of scenario I'm trying to test and making work :

 Scenario: I find all my DNS zones as customer
   Given I am authenticated as customer
   And I send a GET request to "/api/dns"
   Then the response code should be 200
   And the response should contain json:
   """
   [{
     "name":"club-internet.fr"
   }]
   """

Improvement to iSendARequestWithFormData

Hi!

The Web API Extension is exactly what I was looking for and has been a huge help. When I tried to use iSendARequestWithFormData, however, I found that it was losing any headers I had already added.

I wanted to suggest something like the following at line 198:

        $this->addHeader('Content-Type', 'application/x-www-form-urlencoded');
        $this->request = new Request($method, $url, $this->headers, http_build_query($fields, null, '&'));

Is that reasonable? Many apologies if I'm missing something.

Duplicated Content-Type header provokes invalid request

Hello, I have a problem the following feature:

  Scenario Outline: The POST Code response (Entity)
    Given I set header "Accept" with value "application/json"
    And  I set header "Content-Type" with value "application/json"
    When I send a POST request to "/api/users" with body:
    """
      <json>
    """
    Then the response code should be 201

    Examples:
      | json                                             |
      | {"first_name" : "Leigh", "last_name" : "Oros"}   |
      | {"first_name" : "Hope", "last_name" : "Perron"}  |
      | {"first_name" : "Allena", "last_name" : "Spece"} |

The test is correct for the first user (Leigh Oros), but the API throws an error for Hope Perron and Allena Speece. After introspecting the http request I detected that the error is triggered by the Accept and Content-Type headers.

For the first users the headers are:

Array
(
    [Host] => localhost
    [Accept] => application/json
    [Content-Type] => application/json
    [User-Agent] => Guzzle/5.3.0 curl/7.38.0 PHP/5.6.15
    [Content-Length] => 205
)

Until now API works correctly and everything is ok.

However, the request for the second user have the following headers

Array
(
    [Host] => localhost
    [Accept] => application/json, application/json
    [Content-Type] => application/json, application/json
    [User-Agent] => Guzzle/5.3.0 curl/7.38.0 PHP/5.6.15
    [Content-Length] => 205
)

And for third user:

Array
(
    [Host] => localhost
    [Accept] => application/json, application/json, application/json
    [Content-Type] => application/json, application/json, application/json
    [User-Agent] => Guzzle/5.3.0 curl/7.38.0 PHP/5.6.15
    [Content-Length] => 205
)

For second and third request, the answer from the API is:

{
  "type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
  "title":"Unsupported Media Type",
  "status":415,"detail":"Invalid content-type specified"
}

Cleary the headers are append to the existing ones, even if the value is the same. I was expecting that header would be reset for each Example, but is not the case.

Also I don't think that separating multiple mime times with commas are valid Accept and Content-Type headers.

For instance I have solved the issue checking if the header value is already present before adding it 9c602da however I'm not shure who's responsability is to check the validity of headers (WebApiExtension, Gizzle, Behat??). If the solution seems correct I want to make a pull request.

Any feedback will be appreciated.

Automatically populating $HTTP_RAW_POST_DATA is deprecated

Hi,

I have the following error when I run tests of this extension.

      │ --- Failed steps:
      │ 
      │     And the response should contain json: # features/send_raw.feature:16
      │       Can not convert actual to json:
      │       <br />
      │       <b>Deprecated</b>:  Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in <b>Unknown</b> on line <b>0</b><br />
      │       <br />
      │       <b>Warning</b>:  Cannot modify header information - headers already sent in <b>Unknown</b> on line <b>0</b><br />
      │       {"warning":"Do not expose this service in production : it is intrinsically unsafe","method":"POST","name":"name","pass":"pass","headers":{"user-agent":["GuzzleHttp\/6.2.1 curl\/7.22.0 PHP\/5.6.5"],"host":["localhost:8080"],"content-type":["application\/json"],"content-length":["35"],"x-php-ob-level":[1]},"query":[]} (Assert\InvalidArgumentException)

Could not find package behat/web-api-extension at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability

$ composer require --dev behat/web-api-extension


                                                                                                                                                           
  [InvalidArgumentException]                                                                                                                               
  Could not find package behat/web-api-extension at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability  
                                                                                                                                                           


require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] [<packages>]...


Call to a member function json() on null

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.