Skip to content
This repository was archived by the owner on Apr 20, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ default:
- behatch:context:table
- behatch:context:xml
extensions:
Behat\MinkExtension\ServiceContainer\MinkExtension:
Behat\MinkExtension:
base_url: 'http://localhost:8080'
files_path: 'tests/fixtures/files'
goutte: ~
Expand All @@ -31,5 +31,5 @@ default:

symfony2:
extensions:
Behat\MinkExtension\ServiceContainer\MinkExtension:
Behat\MinkExtension:
default_session: symfony2
24 changes: 17 additions & 7 deletions src/Context/RestContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function theResponseShouldBeEqualTo(PyStringNode $expected)
{
$expected = str_replace('\\"', '"', $expected);
$actual = $this->request->getContent();
$message = "The string '$expected' is not equal to the response of the current page";
$message = "Actual response is '$actual', but expected '$expected'";
$this->assertEquals($expected, $actual, $message);
}

Expand All @@ -99,7 +99,7 @@ public function theResponseShouldBeEqualTo(PyStringNode $expected)
public function theResponseShouldBeEmpty()
{
$actual = $this->request->getContent();
$message = 'The response of the current page is not empty';
$message = "The response of the current page is not empty, it is: $actual";
$this->assertTrue(null === $actual || "" === $actual, $message);
}

Expand All @@ -112,7 +112,7 @@ public function theHeaderShouldBeEqualTo($name, $value)
{
$actual = $this->request->getHttpHeader($name);
$this->assertEquals(strtolower($value), strtolower($actual),
"The header '$name' is equal to '$actual'"
"The header '$name' should be equal to '$value', but it is: '$actual'"
);
}

Expand All @@ -131,15 +131,25 @@ public function theHeaderShouldNotBeEqualTo($name, $value) {
}
}

public function theHeaderShouldBeContains($name, $value)
{
trigger_error(
sprintf('The %s function is deprecated since version 3.1 and will be removed in 4.0. Use the %s::theHeaderShouldContain function instead.', __METHOD__, __CLASS__),
E_USER_DEPRECATED
);
$this->theHeaderShouldContain($name, $value);
}

/**
* Checks, whether the header name contains the given text
*
* @Then the header :name should contain :value
*/
public function theHeaderShouldBeContains($name, $value)
public function theHeaderShouldContain($name, $value)
{
$this->assertContains($value, $this->request->getHttpHeader($name),
"The header '$name' doesn't contain '$value'"
$actual = $this->request->getHttpHeader($name);
$this->assertContains($value, $actual,
"The header '$name' should contain value '$value', but actual value is '$actual'"
);
}

Expand Down Expand Up @@ -207,7 +217,7 @@ public function theResponseShouldBeEncodedIn($encoding)
throw new \Exception("The response is not encoded in $encoding");
}

$this->theHeaderShouldBeContains('Content-Type', "charset=$encoding");
$this->theHeaderShouldContain('Content-Type', "charset=$encoding");
}

/**
Expand Down
11 changes: 10 additions & 1 deletion src/HttpCall/Request/Goutte.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ public function send($method, $url, $parameters = [], $files = [], $content = nu

public function setHttpHeader($name, $value)
{
$name = strtoupper("http_$name");
/* taken from Behat\Mink\Driver\BrowserKitDriver::setRequestHeader */
$contentHeaders = array('CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true);
$name = str_replace('-', '_', strtoupper($name));

// CONTENT_* are not prefixed with HTTP_ in PHP when building $_SERVER
if (!isset($contentHeaders[$name])) {
$name = 'HTTP_' . $name;
}
/* taken from Behat\Mink\Driver\BrowserKitDriver::setRequestHeader */

$this->requestHeaders[$name] = $value;
}

Expand Down
17 changes: 17 additions & 0 deletions tests/features/rest.feature
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,20 @@ Feature: Testing RESTContext
"""
Congratulations, you've correctly set up your apache environment.
"""

Scenario: Set content headers in POST request
When I add "Content-Type" header equal to "xxx"
When I send a "POST" request to "rest/index.php" with body:
"""
{"name": "test"}
"""
Then the response should contain ">CONTENT_TYPE : xxx"
Then the response should contain ">HTTP_CONTENT_TYPE : xxx"

Scenario: Content header is clear in different scenario
When I send a "POST" request to "rest/index.php" with body:
"""
{"name": "test"}
"""
Then the response should not contain ">CONTENT_TYPE : xxx"
Then the response should not contain ">HTTP_CONTENT_TYPE : xxx"