Refactored the configuration of sessions

The configuration now makes sessions a first-class citizen instead of
being centered around drivers. This allows defining several session based
on the same driver type.
Instead of allowing other extensions to register their own sessions to add
new drivers, they can now register a DriverFactory in the MinkExtension
during the extension initialization to make a new driver type available.
This commit is contained in:
Christophe Coevoet
2014-01-11 00:04:23 +01:00
parent 589cd05897
commit 3ee16c4b87
18 changed files with 943 additions and 399 deletions

View File

@@ -6,13 +6,14 @@ use Behat\Behat\Tester\Event\ScenarioTested;
use Behat\Gherkin\Node\FeatureNode;
use Behat\Gherkin\Node\ScenarioNode;
use Behat\Mink\Mink;
use Behat\Testwork\ServiceContainer\Exception\ProcessingException;
use PhpSpec\ObjectBehavior;
class SessionsListenerSpec extends ObjectBehavior
{
function let(Mink $mink, ScenarioTested $event, FeatureNode $feature, ScenarioNode $scenario)
{
$this->beConstructedWith($mink, array('default_session' => 'goutte', 'javascript_session' => 'selenium2'));
$this->beConstructedWith($mink, 'goutte', 'selenium2');
$event->getFeature()->willReturn($feature);
$event->getScenario()->willReturn($scenario);
@@ -54,6 +55,15 @@ class SessionsListenerSpec extends ObjectBehavior
$this->prepareDefaultMinkSession($event);
}
function it_fails_when_the_javascript_session_is_used_but_not_defined($event, $mink, $feature)
{
$this->beConstructedWith($mink, 'goutte', null);
$feature->getTags()->willReturn(array('javascript'));
$this->shouldThrow(new ProcessingException('The @javascript tag cannot be used without enabling a javascript session'))
->duringPrepareDefaultMinkSession($event);
}
function it_switches_to_a_named_session($event, $mink, $scenario)
{
$scenario->getTags()->willReturn(array('mink:test'));

View File

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

View File

@@ -0,0 +1,24 @@
<?php
namespace spec\Behat\MinkExtension\ServiceContainer\Driver;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SahiFactorySpec extends ObjectBehavior
{
function it_is_a_driver_factory()
{
$this->shouldHaveType('Behat\MinkExtension\ServiceContainer\Driver\DriverFactory');
}
function it_is_named_sahi()
{
$this->getDriverName()->shouldReturn('sahi');
}
function it_supports_javascript()
{
$this->supportsJavascript()->shouldBe(true);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace spec\Behat\MinkExtension\ServiceContainer\Driver;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SaucelabsFactorySpec extends ObjectBehavior
{
function it_is_a_driver_factory()
{
$this->shouldHaveType('Behat\MinkExtension\ServiceContainer\Driver\DriverFactory');
}
function it_is_named_saucelabs()
{
$this->getDriverName()->shouldReturn('saucelabs');
}
function it_supports_javascript()
{
$this->supportsJavascript()->shouldBe(true);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace spec\Behat\MinkExtension\ServiceContainer\Driver;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class Selenium2FactorySpec extends ObjectBehavior
{
function it_is_a_driver_factory()
{
$this->shouldHaveType('Behat\MinkExtension\ServiceContainer\Driver\DriverFactory');
}
function it_is_named_selenium2()
{
$this->getDriverName()->shouldReturn('selenium2');
}
function it_supports_javascript()
{
$this->supportsJavascript()->shouldBe(true);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace spec\Behat\MinkExtension\ServiceContainer\Driver;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SeleniumFactorySpec extends ObjectBehavior
{
function it_is_a_driver_factory()
{
$this->shouldHaveType('Behat\MinkExtension\ServiceContainer\Driver\DriverFactory');
}
function it_is_named_selenium()
{
$this->getDriverName()->shouldReturn('selenium');
}
function it_supports_javascript()
{
$this->supportsJavascript()->shouldBe(true);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace spec\Behat\MinkExtension\ServiceContainer\Driver;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ZombieFactorySpec extends ObjectBehavior
{
function it_is_a_driver_factory()
{
$this->shouldHaveType('Behat\MinkExtension\ServiceContainer\Driver\DriverFactory');
}
function it_is_named_zombie()
{
$this->getDriverName()->shouldReturn('zombie');
}
function it_supports_javascript()
{
$this->supportsJavascript()->shouldBe(true);
}
}