From c0aa3e776e6d4a2ac14cbe37a011caeda0081af4 Mon Sep 17 00:00:00 2001 From: Swen van Zanten Date: Mon, 11 Apr 2022 15:02:41 +0200 Subject: [PATCH 1/2] add goutte/client 4 compatibility --- composer.json | 2 +- .../ServiceContainer/Driver/GoutteFactory.php | 31 ++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) 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); From 98e9aa9266cb33526c9df66e3c1997586af64a5b Mon Sep 17 00:00:00 2001 From: Swen van Zanten Date: Mon, 10 Oct 2022 11:50:07 +0200 Subject: [PATCH 2/2] change the way http client is initiated --- .../ServiceContainer/Driver/GoutteFactory.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Behat/MinkExtension/ServiceContainer/Driver/GoutteFactory.php b/src/Behat/MinkExtension/ServiceContainer/Driver/GoutteFactory.php index 2e5f6eb..73d4020 100644 --- a/src/Behat/MinkExtension/ServiceContainer/Driver/GoutteFactory.php +++ b/src/Behat/MinkExtension/ServiceContainer/Driver/GoutteFactory.php @@ -77,9 +77,10 @@ class GoutteFactory implements DriverFactory $clientArguments = array(); if (class_exists('Symfony\Component\HttpClient\HttpClient')) { - $clientArguments = array( - \Symfony\Component\HttpClient\HttpClient::create($config['server_parameters']) - ); + $httpClient = new Definition('Symfony\Component\HttpClient\HttpClient'); + $httpClient->setFactory('Symfony\Component\HttpClient\HttpClient::create'); + $httpClient->setArgument(0, $config['server_parameters']); + $clientArguments = array($httpClient); } } elseif ($this->isGoutte1()) { $guzzleClient = $this->buildGuzzle3Client($config['guzzle_parameters']);