How to use FireOnlySiblingsListener class

Best Behat code snippet using .FireOnlySiblingsListener

Run Behat automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

FireOnlySiblingsListener.php

Source: FireOnlySiblingsListener.php Github

copy
1<?php
2
3/*
4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <[email protected]>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11namespace Behat\Behat\Output\Node\EventListener\Flow;
12
13use Behat\Testwork\Output\Formatter;
14use Behat\Testwork\Output\Node\EventListener\EventListener;
15use Symfony\Component\EventDispatcher\Event;
16
17/**
18 * Behat fire only siblings listener.
19 *
20 * This listener catches all events, but proxies them to further listeners only if they
21 * live inside specific event lifecycle (between BEFORE and AFTER events).
22 *
23 * @author Konstantin Kudryashov <ever.zet@gmail.com>
24 */
25class FireOnlySiblingsListener implements EventListener
26{
27    /**
28     * @var string
29     */
30    private $beforeEventName;
31    /**
32     * @var string
33     */
34    private $afterEventName;
35    /**
36     * @var EventListener
37     */
38    private $descendant;
39    /**
40     * @var Boolean
41     */
42    private $inContext = false;
43
44    /**
45     * Initializes listener.
46     *
47     * @param string        $beforeEventName
48     * @param string        $afterEventName
49     * @param EventListener $descendant
50     */
51    public function __construct($beforeEventName, $afterEventName, EventListener $descendant)
52    {
53        $this->beforeEventName = $beforeEventName;
54        $this->afterEventName = $afterEventName;
55        $this->descendant = $descendant;
56    }
57
58    /**
59     * {@inheritdoc}
60     */
61    public function listenEvent(Formatter $formatter, Event $event, $eventName)
62    {
63        if ($this->beforeEventName === $eventName) {
64            $this->inContext = true;
65        }
66
67        if ($this->inContext) {
68            $this->descendant->listenEvent($formatter, $event, $eventName);
69        }
70
71        if ($this->afterEventName === $eventName) {
72            $this->inContext = false;
73        }
74    }
75}
76
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used methods in FireOnlySiblingsListener

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)