Behatch / contexts

Behat extension with most custom helper steps
Other
394 stars 203 forks source link

Not possible to set content-type header #217

Closed razbakov closed 6 years ago

razbakov commented 7 years ago

Steps to reproduce:

behatch/contexts: dev-master (version 20c5910)

Scenario:

  Scenario: Create a Project                                    
    When I add "Accept" header equal to "application/json"
    And I add "Accept-Language" header equal to "xx"
    And I add "Content-Type" header equal to "application/json"
    And I send a "POST" request to "/projects" with body:
      """
      {"name": "test"}
      """

There is controller in the application with Request $request object. There is call in controller: dump($request->headers).

Actual result: Output is:

Symfony\Component\HttpFoundation\HeaderBag {#4548
  #headers: array:7 [
    "host" => array:1 [
      0 => "127.0.0.1"
    ]
    "user-agent" => array:1 [
      0 => "Symfony BrowserKit"
    ]
    "accept" => array:1 [
      0 => "application/json"
    ]
    "accept-language" => array:1 [
      0 => "xx"
    ]
    "accept-charset" => array:1 [
      0 => "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
    ]
    "content-type" => array:1 [
      0 => "application/x-www-form-urlencoded"
    ]
    "x-php-ob-level" => array:1 [
      0 => 1
    ]
  ]

Expected result: Output is:

Symfony\Component\HttpFoundation\HeaderBag {#4548
  #headers: array:7 [
    "host" => array:1 [
      0 => "127.0.0.1"
    ]
    "user-agent" => array:1 [
      0 => "Symfony BrowserKit"
    ]
    "accept" => array:1 [
      0 => "application/json"
    ]
    "accept-language" => array:1 [
      0 => "xx"
    ]
    "accept-charset" => array:1 [
      0 => "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
    ]
    "content-type" => array:1 [
      0 => "application/json"
    ]
    "x-php-ob-level" => array:1 [
      0 => 1
    ]
  ]

Notes:

As you see all headers, except content-type are set correctly.

Might be related:

elkangaroo commented 7 years ago

This issues has already been addressed with MR #212, which is waiting to be merged. Ping @sanpii

razbakov commented 7 years ago

@elkangaroo in my PR there are also tests present and some improvements.