Codeception: REST module, headers set on YML file not sent

Created on 24 Sep 2015  路  4Comments  路  Source: Codeception/Codeception

We have this configuration on an api suite (api.suite.yml)

class_name: ApiTester

modules:
    enabled:
        - \Helper\Api
        - REST
        - Db
    config:
        REST:
          url: {{url}}
          depends: PhpBrowser
          headers:
            Header-One: {{value_1}}
            Header-Two: {{value_2}}
            Header-Three: {{value_3}}
            Content-Type: application/json
        Db:
          dsn: 'mysql:host=localhost; dbname={{dbname}}'
          user: '{{dbusername}}'
          password: '{{dbpass}}'
          populate: false
          cleanup: false

when we run the suite the headers are not sent

[Request headers] []

headers are loaded on the config property of REST class but never taken into account, they are not traversed and added to the $this->headers property.

Docs REST

Most helpful comment

Please try this config:

    config:
        REST:
          url: {{url}}
          depends: PhpBrowser
        PhpBrowser:
          headers:
            Header-One: {{value_1}}
            Header-Two: {{value_2}}
            Header-Three: {{value_3}}
            Content-Type: application/json
        Db:
          dsn: 'mysql:host=localhost; dbname={{dbname}}'
          user: '{{dbusername}}'
          password: '{{dbpass}}'
          populate: false
          cleanup: false

All 4 comments

Headers parameter should not be documented as a REST parameter, because REST has no support for it.

[Request headers] []

REST module does nothing with headers parameter, PhpBrowser passes it straight to Guzzle, so REST module is not aware of these headers, but they could still be sent to the service.

Check what you get in your application.

https://github.com/Codeception/Codeception/blob/2.1/src/Codeception/Module/PhpBrowser.php#L243

Please try this config:

    config:
        REST:
          url: {{url}}
          depends: PhpBrowser
        PhpBrowser:
          headers:
            Header-One: {{value_1}}
            Header-Two: {{value_2}}
            Header-Three: {{value_3}}
            Content-Type: application/json
        Db:
          dsn: 'mysql:host=localhost; dbname={{dbname}}'
          user: '{{dbusername}}'
          password: '{{dbpass}}'
          populate: false
          cleanup: false

thanks @DavertMik , will try that and let you know; what you propose makes sense.

Ok, that seems to have worked.

Thanks.

Was this page helpful?
0 / 5 - 0 ratings