1 | <?php |
||
25 | class IsolatedSessionStrategy implements ISessionStrategy |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * Session factory. |
||
30 | * |
||
31 | * @var ISessionFactory |
||
32 | */ |
||
33 | private $_sessionFactory; |
||
34 | |||
35 | /** |
||
36 | * Creates isolated session strategy instance. |
||
37 | * |
||
38 | * @param ISessionFactory $session_factory Session factory. |
||
39 | */ |
||
40 | 5 | public function __construct(ISessionFactory $session_factory) |
|
44 | |||
45 | /** |
||
46 | * Returns an array of event names this subscriber wants to listen to. |
||
47 | * |
||
48 | * @return array The event names to listen to |
||
49 | */ |
||
50 | 5 | public static function getSubscribedEvents() |
|
51 | { |
||
52 | return array( |
||
53 | 5 | BrowserTestCase::TEST_ENDED_EVENT => array('onTestEnd', 0), |
|
54 | ); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Sets event dispatcher. |
||
59 | * |
||
60 | * @param EventDispatcherInterface $event_dispatcher Event dispatcher. |
||
61 | * |
||
62 | * @return void |
||
63 | */ |
||
64 | 5 | public function setEventDispatcher(EventDispatcherInterface $event_dispatcher) |
|
68 | |||
69 | /** |
||
70 | * Returns Mink session with given browser configuration. |
||
71 | * |
||
72 | * @param BrowserConfiguration $browser Browser configuration for a session. |
||
73 | * |
||
74 | * @return Session |
||
75 | */ |
||
76 | 1 | public function session(BrowserConfiguration $browser) |
|
80 | |||
81 | /** |
||
82 | * Called, when test ends. |
||
83 | * |
||
84 | * @param TestEvent $event Test event. |
||
85 | * |
||
86 | * @return void |
||
87 | */ |
||
88 | 1 | public function onTestEnd(TestEvent $event) |
|
89 | { |
||
90 | 1 | if ( !$this->_isEventForMe($event) ) { |
|
91 | return; |
||
92 | } |
||
93 | |||
94 | 1 | $session = $event->getSession(); |
|
95 | |||
96 | 1 | if ( $session !== null && $session->isStarted() ) { |
|
97 | 1 | $session->stop(); |
|
98 | } |
||
99 | 1 | } |
|
100 | |||
101 | /** |
||
102 | * Checks, that event can be handled by this class. |
||
103 | * |
||
104 | * @param TestEvent $event Test event. |
||
105 | * |
||
106 | * @return boolean |
||
107 | */ |
||
108 | 1 | private function _isEventForMe(TestEvent $event) |
|
112 | |||
113 | } |
||
114 |