Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

Commit

Permalink
Merge branch 'main' into jd-feat-jsonDx
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau authored Nov 14, 2022
2 parents 1f986cd + 63aca61 commit 5de51bb
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 29 deletions.
33 changes: 22 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
language: php

dist: trusty

addons:
chrome: stable

Expand All @@ -10,8 +12,7 @@ cache:
env:
global:
- DISPLAY=:99.0
- CHROME_DRIVER_VERSION=2.36
- SELENIUM_VERSION=3.6.0
- SELENIUM_VERSION=3.9.1
matrix:
- DEPS=high PROFILE=default
- DEPS=low PROFILE=default
Expand All @@ -21,31 +22,41 @@ env:
php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- nightly

matrix:
exclude:
- php: 7.4
env: DEPS=low PROFILE=default
- php: 7.4
env: DEPS=low PROFILE=symfony2
- php: nightly
env: DEPS=low PROFILE=default
- php: nightly
env: DEPS=low PROFILE=symfony2
allow_failures:
- php: nightly
- php: hhvm
- php: hhvm-nightly
fast_finish: true

before_script:
- Xvfb $DISPLAY -extension RANDR &> /dev/null &

- wget "https://chromedriver.storage.googleapis.com/${CHROME_DRIVER_VERSION}/chromedriver_linux64.zip"
- unzip chromedriver_linux64.zip
- LATEST_CHROMEDRIVER_VERSION=`curl http://chromedriver.storage.googleapis.com/LATEST_RELEASE`
- wget --no-verbose https://chromedriver.storage.googleapis.com/$LATEST_CHROMEDRIVER_VERSION/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip -d ~/bin

- wget "https://selenium-release.storage.googleapis.com/${SELENIUM_VERSION%%.[[:digit:]]}/selenium-server-standalone-${SELENIUM_VERSION}.jar" -O selenium.jar
- java -jar -Dwebdriver.chrome.driver=./chromedriver selenium.jar &> /dev/null &
- java -jar selenium.jar &> /dev/null &

- php -S localhost:8080 -t tests/fixtures/www &> /dev/null &
- cp behat.yml{.dist,}
- composer install
- COMPOSER_PATH="/home/travis/.phpenv/versions/$TRAVIS_PHP_VERSION/bin/composer"
- php -d memory_limit=-1 $COMPOSER_PATH install

- test "$DEPS" == "low" || composer update --prefer-lowest
- test "$DEPS" == "high" || php -d memory_limit=-1 $COMPOSER_PATH update --prefer-lowest
- test ${TRAVIS_PHP_VERSION:0:1} -lt 7 || composer update atoum/atoum

script:
Expand Down
11 changes: 10 additions & 1 deletion behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ default:
base_url: 'http://localhost:8080'
files_path: 'tests/fixtures/files'
goutte: ~
selenium2: ~
selenium2:
capabilities:
chrome:
switches:
- "--headless"
- "--disable-gpu"
- "--no-sandbox"
extra_capabilities:
"goog:chromeOptions":
w3c: false
browser_name: 'chrome'
sessions:
default:
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "behatch/contexts",
"name": "soyuka/contexts",
"description": "Behatch contexts",
"keywords": ["BDD", "Behat", "Symfony2", "Context"],
"type": "library",
Expand All @@ -8,17 +8,17 @@
"require": {
"php": ">=5.5",
"behat/behat": "^3.0.13",
"behat/mink-extension": "^2.3.1",
"friends-of-behat/mink-extension": "^2.3.1",
"justinrainbow/json-schema": "^5.0",
"symfony/property-access": "^2.3|^3.0|^4.0",
"symfony/http-foundation": "^2.3|^3.0|^4.0",
"symfony/dom-crawler": "^2.4|^3.0|^4.0"
"symfony/property-access": "^2.3|^3.0|^4.0|^5.0|^6.0",
"symfony/http-foundation": "^2.3|^3.0|^4.0|^5.0|^6.0",
"symfony/dom-crawler": "^2.4|^3.0|^4.0|^5.0|^6.0"
},

"require-dev": {
"behat/mink-goutte-driver": "^1.1",
"guzzlehttp/guzzle": "^6.3",
"behat/mink-selenium2-driver": "^1.3",
"behat/mink-selenium2-driver": "^1.4@dev",
"atoum/atoum": "^2.8|^3.0",
"fabpot/goutte": "^3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Context/JsonContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public function theJsonShouldBeValidAccordingToTheSchema($filename)
$this->getJson(),
new JsonSchema(
file_get_contents($filename),
'file://' . realpath($filename)
'file://' . str_replace(DIRECTORY_SEPARATOR, '/', realpath($filename))
)
);
}
Expand Down
12 changes: 7 additions & 5 deletions src/HttpCall/HttpCallResultPoolResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Behatch\HttpCall;

use Behat\Behat\Context\Argument\ArgumentResolver;
use ReflectionClass;

class HttpCallResultPoolResolver implements ArgumentResolver
{
Expand All @@ -23,11 +24,12 @@ public function resolveArguments(\ReflectionClass $classReflection, array $argum
if ($constructor !== null) {
$parameters = $constructor->getParameters();
foreach ($parameters as $parameter) {
if (
null !== $parameter->getType()
&& isset($this->dependencies[$parameter->getType()->getName()])
) {
$arguments[$parameter->name] = $this->dependencies[$parameter->getType()->getName()];
$class = PHP_VERSION_ID < 80000 ? $parameter->getClass() : ($parameter->getType() && !$parameter->getType()->isBuiltin()
? new ReflectionClass($parameter->getType()->getName())
: null
);
if (null !== $class && isset($this->dependencies[$class->name])) {
$arguments[$parameter->name] = $this->dependencies[$class->name];
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/HttpCall/Request/BrowserKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ public function send($method, $url, $parameters = [], $files = [], $content = nu
$client = $this->mink->getSession()->getDriver()->getClient();

$client->followRedirects(false);

// Workaround for https://github.com/symfony/symfony/issues/33393: prevent a default Accept header to be set
if (!isset($headers['HTTP_ACCEPT']) && '' === $client->getServerParameter('HTTP_ACCEPT')) {
$headers['HTTP_ACCEPT'] = null;
}

$client->request($method, $url, $parameters, $files, $headers, $content);
$client->followRedirects(true);
$this->resetHttpHeaders();
Expand All @@ -78,11 +84,15 @@ public function send($method, $url, $parameters = [], $files = [], $content = nu
public function setHttpHeader($name, $value)
{
$client = $this->mink->getSession()->getDriver()->getClient();
// Goutte\Client
if (method_exists($client, 'setHeader')) {
/**
* @var \Goutte\Client $client
*/
$client->setHeader($name, $value);
} else {
// Symfony\Component\BrowserKit\Client
/**
* @var \Symfony\Component\BrowserKit\HttpBrowser $client
*/

/* taken from Behat\Mink\Driver\BrowserKitDriver::setRequestHeader */
$contentHeaders = ['CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true];
Expand Down
11 changes: 10 additions & 1 deletion src/Json/JsonInspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@ class JsonInspector

public function __construct($evaluationMode)
{
$magicMethods = defined(PropertyAccessor::class.'::DISALLOW_MAGIC_METHODS')
? PropertyAccessor::MAGIC_GET | PropertyAccessor::MAGIC_SET
: false
;
$throwException = defined(PropertyAccessor::class.'::DO_NOT_THROW')
? PropertyAccessor::THROW_ON_INVALID_INDEX | PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH
: true
;

$this->evaluationMode = $evaluationMode;
$this->accessor = new PropertyAccessor(false, true);
$this->accessor = new PropertyAccessor($magicMethods, $throwException);
}

public function evaluate(Json $json, $expression)
Expand Down
6 changes: 5 additions & 1 deletion tests/features/rest.feature
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ Feature: Testing RESTContext
Congratulations, you've correctly set up your apache environment.
"""

@>php5.5
Scenario: Accept header should not be set by dfault
When I send a GET request to "/rest/index.php"
Then I should not see "HTTP_ACCEPT"

@>php5.5
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:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/fixtures/www/rest/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
You have sent a <?php print $_SERVER['REQUEST_METHOD']; ?> request.

<?php print sizeof($_SERVER); ?> header(s) received.
<?php foreach($_SERVER as $key => $value): ?>
<?php foreach(array_filter($_SERVER) as $key => $value): ?>
<br /><?php print $key ?> : <?php print $value; ?>
<?php endforeach; ?>

Expand Down

0 comments on commit 5de51bb

Please sign in to comment.