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
1 change: 0 additions & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ filter:
excluded_paths:
- 'tests/*'
- 'bin/*'

checks:
php:
excluded_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ cache:
- $HOME/.composer/cache

php:
- 5.4
- 5.5
- 5.6
- 7.0
Expand Down Expand Up @@ -37,3 +36,4 @@ before_script:
script:
- ./bin/atoum
- ./bin/behat -fprogress --tags='~@user' --no-interaction
- ./bin/behat -fprogress --tags='~@user' --no-interaction --profile=symfony2
16 changes: 15 additions & 1 deletion behat.yml.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
default:
calls:
error_reporting: 16383 # E_ALL & ~E_USER_DREPRECATED
suites:
default:
paths: [ %paths.base%/tests/features ]
Expand All @@ -21,4 +23,16 @@ default:
files_path: 'tests/fixtures/files'
goutte: ~
selenium2: ~
Sanpi\Behatch\Extension: ~
sessions:
default:
goutte: ~
symfony2:
goutte: ~
Behatch\Extension: ~

symfony2:
calls:
error_reporting: 16383 # E_ALL & ~E_USER_DREPRECATED
extensions:
Behat\MinkExtension\ServiceContainer\MinkExtension:
default_session: symfony2
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "beerware",

"require": {
"php": ">=5.4",
"php": ">=5.5",
"behat/behat": "~3.0",
"behat/mink-extension": "~2.0",
"justinrainbow/json-schema": "~5.0",
Expand All @@ -17,7 +17,8 @@
"require-dev": {
"behat/mink-goutte-driver": "~1.1",
"behat/mink-selenium2-driver": "~1.2",
"atoum/atoum": "~2.8|~3.0"
"atoum/atoum": "~2.8|~3.0",
"fabpot/goutte": "~3.2"
},

"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion src/Context/ContextClass/ClassResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function resolveClass($contextClass)
E_USER_DEPRECATED
);

return "\\Sanpi\\Behatch\\Context\\{$className}Context";
return "\\Behatch\\Context\\{$className}Context";
} else {
$className = preg_replace_callback('/(^\w|:\w)/', function ($matches) {
return str_replace(':', '\\', strtoupper($matches[0]));
Expand Down
14 changes: 9 additions & 5 deletions src/HttpCall/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Request
* @var Mink
*/
private $mink;
private $client;

/**
* Request constructor.
Expand All @@ -35,11 +36,14 @@ public function __call($name, $arguments)
*/
private function getClient()
{
if ($this->mink->getDefaultSessionName() === 'symfony2') {
return new Request\Goutte($this->mink);
}
else {
return new Request\BrowserKit($this->mink);
if (null === $this->client) {
if ('symfony2' === $this->mink->getDefaultSessionName()) {
$this->client = new Request\Goutte($this->mink);
} else {
$this->client = new Request\BrowserKit($this->mink);
}
}

return $this->client;
}
}
14 changes: 14 additions & 0 deletions src/HttpCall/Request/BrowserKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Behatch\HttpCall\Request;

use Behat\Mink\Driver\Goutte\Client as GoutteClient;
use Behat\Mink\Mink;
use Symfony\Component\BrowserKit\Client as BrowserKitClient;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class BrowserKit
Expand Down Expand Up @@ -68,6 +70,7 @@ public function send($method, $url, $parameters = [], $files = [], $content = nu
$client->followRedirects(false);
$client->request($method, $url, $parameters, $files, $headers, $content);
$client->followRedirects(true);
$this->resetHttpHeaders();

return $this->mink->getSession()->getPage();
}
Expand Down Expand Up @@ -127,4 +130,15 @@ public function getHttpRawHeader($name)
}
return $value;
}

protected function resetHttpHeaders()
{
/** @var GoutteClient|BrowserKitClient $client */
$client = $this->mink->getSession()->getDriver()->getClient();

$client->setServerParameters([]);
if ($client instanceof GoutteClient) {
$client->restart();
}
}
}
4 changes: 2 additions & 2 deletions src/HttpCall/Request/Goutte.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Goutte extends BrowserKit

public function send($method, $url, $parameters = [], $files = [], $content = null, $headers = [])
{
$page = parent::send($method, $url, $parameters, $files, $content, $this->requestHeaders);
$page = parent::send($method, $url, $parameters, $files, $content, array_merge($headers, $this->requestHeaders));
$this->resetHttpHeaders();

return $page;
Comment thread
vincentchalamon marked this conversation as resolved.
Expand All @@ -38,7 +38,7 @@ public function setHttpHeader($name, $value)
$this->requestHeaders[$name] = $value;
}

private function resetHttpHeaders()
protected function resetHttpHeaders()
{
$this->requestHeaders = [];
}
Expand Down
4 changes: 4 additions & 0 deletions tests/features/rest.feature
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Feature: Testing RESTContext
When I send a GET request to "/rest/index.php"
Then I should see "HTTP_XXX : yyy"

Scenario: Header should not be cross-scenarios persistent
When I send a GET request to "/rest/index.php"
Then I should not see "HTTP_XXX : yyy"

Scenario: Case-insensitive header name
Like describe in the rfc2614 §4.2
https://tools.ietf.org/html/rfc2616#section-4.2
Expand Down