|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sylius\Behat\MultiContainerExtension; |
|
13
|
|
|
|
|
14
|
|
|
use Behat\Behat\EventDispatcher\Event\ExampleTested; |
|
15
|
|
|
use Behat\Behat\EventDispatcher\Event\ScenarioTested; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
17
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Kamil Kokot <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
final class ScopeManipulator implements EventSubscriberInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var ContainerInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
private $container; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param ContainerInterface $container |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(ContainerInterface $container) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->container = $container; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* {@inheritdoc} |
|
39
|
|
|
*/ |
|
40
|
|
|
public static function getSubscribedEvents() |
|
41
|
|
|
{ |
|
42
|
|
|
return [ |
|
43
|
|
|
ScenarioTested::BEFORE => ['enterScope', 128], |
|
44
|
|
|
ExampleTested::BEFORE => ['enterScope', 128], |
|
45
|
|
|
ScenarioTested::AFTER => ['leaveScope', -128], |
|
46
|
|
|
ExampleTested::AFTER => ['leaveScope', -128], |
|
47
|
|
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function enterScope() |
|
51
|
|
|
{ |
|
52
|
|
|
if (!$this->container->isScopeActive('scenario')) { |
|
53
|
|
|
$this->container->enterScope('scenario'); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function leaveScope() |
|
58
|
|
|
{ |
|
59
|
|
|
if ($this->container->isScopeActive('scenario')) { |
|
60
|
|
|
$this->container->leaveScope('scenario'); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|