From e9477f3e9bf143b2118c7a8ca4ece40ea95cdd8e Mon Sep 17 00:00:00 2001 From: Andreas Hennings Date: Mon, 1 May 2023 18:00:02 +0200 Subject: [PATCH] Compatibility with guzzle 7. --- .../ServiceContainer/Driver/GoutteFactory.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Behat/MinkExtension/ServiceContainer/Driver/GoutteFactory.php b/src/Behat/MinkExtension/ServiceContainer/Driver/GoutteFactory.php index fb10d889..d5ba424c 100644 --- a/src/Behat/MinkExtension/ServiceContainer/Driver/GoutteFactory.php +++ b/src/Behat/MinkExtension/ServiceContainer/Driver/GoutteFactory.php @@ -10,6 +10,7 @@ namespace Behat\MinkExtension\ServiceContainer\Driver; +use GuzzleHttp\ClientInterface; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\DependencyInjection\Definition; @@ -116,7 +117,8 @@ private function isGoutte1() { $refl = new \ReflectionParameter(array('Goutte\Client', 'setClient'), 0); - if ($refl->getClass() && 'Guzzle\Http\ClientInterface' === $refl->getClass()->getName()) { + $type = $refl->getType(); + if ($type instanceof \ReflectionNamedType && 'Guzzle\Http\ClientInterface' === $type->getName()) { return true; } @@ -125,7 +127,18 @@ private function isGoutte1() private function isGuzzle6() { - return interface_exists('GuzzleHttp\ClientInterface') && - version_compare(\GuzzleHttp\ClientInterface::VERSION, '6.0.0', '>='); + if (!interface_exists(ClientInterface::class)) { + return false; + } + $rc = new \ReflectionClass(ClientInterface::class); + // This constant was removed in Guzzle 7. + if ($rc->hasConstant('VERSION')) { + return version_compare(ClientInterface::VERSION, '6.0.0', '>='); + } + // This constant was added in Guzzle 7. + if ($rc->hasConstant('MAJOR_VERSION')) { + ClientInterface::MAJOR_VERSION >= 6; + } + return false; } }