Add support for BrowserKit driver

This commit is contained in:
thePanz
2022-01-07 16:00:02 +01:00
parent df04efb3e8
commit 760868b9e5
3 changed files with 91 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
<?php
namespace spec\Behat\MinkExtension\ServiceContainer\Driver;
use PhpSpec\ObjectBehavior;
use Behat\MinkExtension\ServiceContainer\Driver\DriverFactory;
class BrowserKitFactorySpec extends ObjectBehavior
{
function it_is_a_driver_factory()
{
$this->shouldHaveType(DriverFactory::class);
}
function it_is_named_browserkit()
{
$this->getDriverName()->shouldReturn('browserkit_http');
}
function it_does_not_support_javascript()
{
$this->supportsJavascript()->shouldBe(false);
}
}

View File

@@ -0,0 +1,65 @@
<?php
/*
* This file is part of the Behat MinkExtension.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Behat\MinkExtension\ServiceContainer\Driver;
use Behat\Mink\Driver\BrowserKitDriver;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\BrowserKit\HttpBrowser;
use Symfony\Component\HttpClient\HttpClient;
class BrowserKitFactory implements DriverFactory
{
/**
* {@inheritdoc}
*/
public function getDriverName()
{
return 'browserkit_http';
}
/**
* {@inheritdoc}
*/
public function supportsJavascript()
{
return false;
}
/**
* {@inheritdoc}
*/
public function configure(ArrayNodeDefinition $builder)
{
}
/**
* {@inheritdoc}
*/
public function buildDriver(array $config)
{
if (!class_exists(BrowserKitDriver::class)) {
throw new \RuntimeException('Install behat/mink-browserkit-driver in order to use the browserkit_http driver.');
}
if (!class_exists(HttpClient::class)) {
throw new \RuntimeException(sprintf('Class %s not found, did you install symfony/http-client?', HttpClient::class));
}
if (!class_exists(HttpBrowser::class)) {
throw new \RuntimeException(sprintf('Class %s not found, did you install symfony/browser-kit 4.4+?', HttpBrowser::class));
}
return new Definition(BrowserKitDriver::class, [
new Definition(HttpBrowser::class),
'%mink.base_url%',
]);
}
}

View File

@@ -12,6 +12,7 @@ namespace Behat\MinkExtension\ServiceContainer;
use Behat\Behat\Context\ServiceContainer\ContextExtension; use Behat\Behat\Context\ServiceContainer\ContextExtension;
use Behat\MinkExtension\ServiceContainer\Driver\AppiumFactory; use Behat\MinkExtension\ServiceContainer\Driver\AppiumFactory;
use Behat\MinkExtension\ServiceContainer\Driver\BrowserKitFactory;
use Behat\MinkExtension\ServiceContainer\Driver\BrowserStackFactory; use Behat\MinkExtension\ServiceContainer\Driver\BrowserStackFactory;
use Behat\MinkExtension\ServiceContainer\Driver\DriverFactory; use Behat\MinkExtension\ServiceContainer\Driver\DriverFactory;
use Behat\MinkExtension\ServiceContainer\Driver\GoutteFactory; use Behat\MinkExtension\ServiceContainer\Driver\GoutteFactory;
@@ -51,6 +52,7 @@ class MinkExtension implements ExtensionInterface
public function __construct() public function __construct()
{ {
$this->registerDriverFactory(new GoutteFactory()); $this->registerDriverFactory(new GoutteFactory());
$this->registerDriverFactory(new BrowserKitFactory());
$this->registerDriverFactory(new SahiFactory()); $this->registerDriverFactory(new SahiFactory());
$this->registerDriverFactory(new SeleniumFactory()); $this->registerDriverFactory(new SeleniumFactory());
$this->registerDriverFactory(new Selenium2Factory()); $this->registerDriverFactory(new Selenium2Factory());