added support for automatic show on failures

This commit is contained in:
everzet
2012-09-10 20:20:10 +02:00
parent 0b8a4d7d10
commit 9e2c34cbd0
6 changed files with 237 additions and 76 deletions

View File

@@ -2,12 +2,8 @@
namespace Behat\MinkExtension\Context\Initializer;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Behat\Behat\Context\Initializer\InitializerInterface,
Behat\Behat\Context\ContextInterface,
Behat\Behat\Event\ScenarioEvent,
Behat\Behat\Event\OutlineEvent;
Behat\Behat\Context\ContextInterface;
use Behat\Mink\Mink;
@@ -27,7 +23,7 @@ use Behat\MinkExtension\Context\MinkAwareInterface;
*
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
class MinkAwareInitializer implements InitializerInterface, EventSubscriberInterface
class MinkAwareInitializer implements InitializerInterface
{
private $mink;
private $parameters;
@@ -44,33 +40,6 @@ class MinkAwareInitializer implements InitializerInterface, EventSubscriberInter
$this->parameters = $parameters;
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * array('eventName' => 'methodName')
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
*
* @return array The event names to listen to
*/
public static function getSubscribedEvents()
{
return array(
'beforeScenario' => array('prepareDefaultMinkSession', 10),
'beforeOutline' => array('prepareDefaultMinkSession', 10),
'afterSuite' => array('tearDownMinkSessions', -10)
);
}
/**
* Checks if initializer supports provided context.
*
@@ -106,47 +75,4 @@ class MinkAwareInitializer implements InitializerInterface, EventSubscriberInter
$context->setMink($this->mink);
$context->setMinkParameters($this->parameters);
}
/**
* Configures default Mink session before each scenario.
* Configuration is based on provided scenario tags:
*
* `@javascript` tagged scenarios will get `javascript_session` as default session
* `@mink:CUSTOM_NAME tagged scenarios will get `CUSTOM_NAME` as default session
* Other scenarios get `default_session` as default session
*
* `@insulated` tag will cause Mink to stop current sessions before scenario
* instead of just soft-resetting them
*
* @param ScenarioEvent|OutlineEvent $event
*/
public function prepareDefaultMinkSession($event)
{
$scenario = $event instanceof ScenarioEvent ? $event->getScenario() : $event->getOutline();
$session = $this->parameters['default_session'];
foreach ($scenario->getTags() as $tag) {
if ('javascript' === $tag) {
$session = $this->parameters['javascript_session'];
} elseif (preg_match('/^mink\:(.+)/', $tag, $matches)) {
$session = $matches[1];
}
}
if ($scenario->hasTag('insulated')) {
$this->mink->stopSessions();
} else {
$this->mink->resetSessions();
}
$this->mink->setDefaultSessionName($session);
}
/**
* Stops all started Mink sessions.
*/
public function tearDownMinkSessions()
{
$this->mink->stopSessions();
}
}