From ad36c46df584125d6d8eb7332c6a57537e313c07 Mon Sep 17 00:00:00 2001 From: thePanz <226021+thePanz@users.noreply.github.com> Date: Fri, 7 Jan 2022 16:00:02 +0100 Subject: [PATCH] Add support for BrowserKit driver --- .../Driver/BrowserKitFactorySpec.php | 24 ++++++ .../Driver/BrowserKitFactory.php | 73 +++++++++++++++++++ .../ServiceContainer/MinkExtension.php | 2 + 3 files changed, 99 insertions(+) create mode 100644 spec/Behat/MinkExtension/ServiceContainer/Driver/BrowserKitFactorySpec.php create mode 100644 src/Behat/MinkExtension/ServiceContainer/Driver/BrowserKitFactory.php diff --git a/spec/Behat/MinkExtension/ServiceContainer/Driver/BrowserKitFactorySpec.php b/spec/Behat/MinkExtension/ServiceContainer/Driver/BrowserKitFactorySpec.php new file mode 100644 index 00000000..3414fdfc --- /dev/null +++ b/spec/Behat/MinkExtension/ServiceContainer/Driver/BrowserKitFactorySpec.php @@ -0,0 +1,24 @@ +shouldHaveType(DriverFactory::class); + } + + function it_is_named_browserkit() + { + $this->getDriverName()->shouldReturn('browserkit'); + } + + function it_does_not_support_javascript() + { + $this->supportsJavascript()->shouldBe(false); + } +} diff --git a/src/Behat/MinkExtension/ServiceContainer/Driver/BrowserKitFactory.php b/src/Behat/MinkExtension/ServiceContainer/Driver/BrowserKitFactory.php new file mode 100644 index 00000000..061ebf2e --- /dev/null +++ b/src/Behat/MinkExtension/ServiceContainer/Driver/BrowserKitFactory.php @@ -0,0 +1,73 @@ +children() + ->scalarNode('class')->cannotBeEmpty()->end() + ->end() + ; + } + + /** + * {@inheritdoc} + */ + public function buildDriver(array $config) + { + if (!class_exists(BrowserKitDriver::class)) { + throw new \RuntimeException( + 'Install BrowserKit in order to use browserkit driver.' + ); + } + + if (class_exists(HttpBrowser::class)) { + $clientDefinition = new Definition(HttpBrowser::class); + } else { + throw new \RuntimeException( + sprintf('No implementation of class %s found.', HttpBrowser::class) + ); + } + + return new Definition(BrowserKitDriver::class, [ + $clientDefinition, + '%mink.base_url%', + ]); + } + +} diff --git a/src/Behat/MinkExtension/ServiceContainer/MinkExtension.php b/src/Behat/MinkExtension/ServiceContainer/MinkExtension.php index ff29b3c9..8c04752a 100644 --- a/src/Behat/MinkExtension/ServiceContainer/MinkExtension.php +++ b/src/Behat/MinkExtension/ServiceContainer/MinkExtension.php @@ -12,6 +12,7 @@ use Behat\Behat\Context\ServiceContainer\ContextExtension; use Behat\MinkExtension\ServiceContainer\Driver\AppiumFactory; +use Behat\MinkExtension\ServiceContainer\Driver\BrowserKitFactory; use Behat\MinkExtension\ServiceContainer\Driver\BrowserStackFactory; use Behat\MinkExtension\ServiceContainer\Driver\DriverFactory; use Behat\MinkExtension\ServiceContainer\Driver\GoutteFactory; @@ -51,6 +52,7 @@ class MinkExtension implements ExtensionInterface public function __construct() { $this->registerDriverFactory(new GoutteFactory()); + $this->registerDriverFactory(new BrowserKitFactory()); $this->registerDriverFactory(new SahiFactory()); $this->registerDriverFactory(new SeleniumFactory()); $this->registerDriverFactory(new Selenium2Factory());