Last active
August 29, 2015 14:10
-
-
Save gggeek/f7a27006b9861ec841b9 to your computer and use it in GitHub Desktop.
POC: implement cross-context communication for Behat-3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default: | |
extensions: | |
Kaliop\Behat\KToolsExtension: ~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Kaliop\Behat\KToolsExtension\Listener; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
use Behat\Behat\EventDispatcher\Event\ScenarioTested; | |
use Behat\Behat\EventDispatcher\Event\OutlineTested; | |
use Behat\Behat\EventDispatcher\Event\ScenarioLikeTested; | |
use Kaliop\Behat\KToolsExtension\Context\SharedContext; | |
/** | |
* Will hold all the necessary event listeners | |
*/ | |
class EventListener implements EventSubscriberInterface | |
{ | |
protected $sharedContext; | |
/** | |
* @param SharedContext $sharedContext | |
*/ | |
public function __construct($sharedContext) | |
{ | |
$this->sharedContext = $sharedContext; | |
} | |
/** | |
* @return array | |
*/ | |
public static function getSubscribedEvents() | |
{ | |
return array( | |
// these we call after either a single scenario or a scenario-with-examples has finished | |
ScenarioTested::BEFORE_TEARDOWN => array('resetSharedContexts', -10), | |
OutlineTested::BEFORE_TEARDOWN => array('resetSharedContexts', -10), | |
); | |
} | |
public function resetSharedContexts() | |
{ | |
$this->sharedContext->resetContexts(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parameters: | |
kaliop.ktools_extension.context.initializer.class: Kaliop\Behat\KToolsExtension\Context\Initializer\ShareableContextInitializer | |
kaliop.ktools_extension.sharedcontext.container.class: Kaliop\Behat\KToolsExtension\Context\SharedContextContainer | |
kaliop.ktools_extension.event.listener.class: Kaliop\Behat\KToolsExtension\Listener\EventListener | |
services: | |
kaliop.ktools_extension.sharedcontext.container: | |
class: "%kaliop.ktools_extension.sharedcontext.container.class%" | |
kaliop.ktools_extension.context.initializer: | |
class: "%kaliop.ktools_extension.context.initializer.class%" | |
arguments: [@kaliop.ktools_extension.sharedcontext.container] | |
tags: | |
- { name: context.initializer } | |
kaliop.ktools_extension.event.listener: | |
class: "%kaliop.ktools_extension.event.listener.class%" | |
arguments: [@kaliop.ktools_extension.sharedcontext.container] | |
tags: | |
- { name: event_dispatcher.subscriber } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment