diff --git a/composer.json b/composer.json index 7ddb795..af2c81c 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "behat/mink-extension": "self.version" }, "require-dev": { - "behat/mink-goutte-driver": "^1.1", + "behat/mink-goutte-driver": "^1.1 || ^2.0", "phpspec/phpspec": "^6.0 || ^7.0 || 7.1.x-dev" }, "extra": { diff --git a/src/Behat/MinkExtension/ServiceContainer/Driver/GoutteFactory.php b/src/Behat/MinkExtension/ServiceContainer/Driver/GoutteFactory.php index 03741bc..2e5f6eb 100644 --- a/src/Behat/MinkExtension/ServiceContainer/Driver/GoutteFactory.php +++ b/src/Behat/MinkExtension/ServiceContainer/Driver/GoutteFactory.php @@ -68,7 +68,20 @@ class GoutteFactory implements DriverFactory ); } - if ($this->isGoutte1()) { + $clientArguments = array( + $config['server_parameters'], + ); + $guzzleClient = null; + + if ($this->isGoutte4()) { + $clientArguments = array(); + + if (class_exists('Symfony\Component\HttpClient\HttpClient')) { + $clientArguments = array( + \Symfony\Component\HttpClient\HttpClient::create($config['server_parameters']) + ); + } + } elseif ($this->isGoutte1()) { $guzzleClient = $this->buildGuzzle3Client($config['guzzle_parameters']); } elseif ($this->isGuzzle6()) { $guzzleClient = $this->buildGuzzle6Client($config['guzzle_parameters']); @@ -76,10 +89,11 @@ class GoutteFactory implements DriverFactory $guzzleClient = $this->buildGuzzle4Client($config['guzzle_parameters']); } - $clientDefinition = new Definition('Behat\Mink\Driver\Goutte\Client', array( - $config['server_parameters'], - )); - $clientDefinition->addMethodCall('setClient', array($guzzleClient)); + $clientDefinition = new Definition('Behat\Mink\Driver\Goutte\Client', $clientArguments); + + if (null !== $guzzleClient) { + $clientDefinition->addMethodCall('setClient', array($guzzleClient)); + } return new Definition('Behat\Mink\Driver\GoutteDriver', array( $clientDefinition, @@ -112,6 +126,13 @@ class GoutteFactory implements DriverFactory return new Definition('Guzzle\Http\Client', array(null, $parameters)); } + private function isGoutte4() + { + $client = 'Goutte\Client'; + + return class_exists($client) && is_a($client, 'Symfony\Component\BrowserKit\HttpBrowser', true); + } + private function isGoutte1() { $refl = new \ReflectionParameter(array('Goutte\Client', 'setClient'), 0);