4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Behat\EventDispatcher\Tester;
13 use Behat\Behat\EventDispatcher\Event\AfterBackgroundSetup;
14 use Behat\Behat\EventDispatcher\Event\AfterBackgroundTested;
15 use Behat\Behat\EventDispatcher\Event\BackgroundTested;
16 use Behat\Behat\EventDispatcher\Event\BeforeBackgroundTeardown;
17 use Behat\Behat\EventDispatcher\Event\BeforeBackgroundTested;
18 use Behat\Behat\Tester\BackgroundTester;
19 use Behat\Gherkin\Node\FeatureNode;
20 use Behat\Testwork\Environment\Environment;
21 use Behat\Testwork\Tester\Result\TestResult;
22 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
25 * Background tester dispatching BEFORE/AFTER events.
27 * @author Konstantin Kudryashov <ever.zet@gmail.com>
29 final class EventDispatchingBackgroundTester implements BackgroundTester
32 * @var BackgroundTester
36 * @var EventDispatcherInterface
38 private $eventDispatcher;
43 * @param BackgroundTester $baseTester
44 * @param EventDispatcherInterface $eventDispatcher
46 public function __construct(BackgroundTester $baseTester, EventDispatcherInterface $eventDispatcher)
48 $this->baseTester = $baseTester;
49 $this->eventDispatcher = $eventDispatcher;
55 public function setUp(Environment $env, FeatureNode $feature, $skip)
57 $event = new BeforeBackgroundTested($env, $feature, $feature->getBackground());
58 $this->eventDispatcher->dispatch($event::BEFORE, $event);
60 $setup = $this->baseTester->setUp($env, $feature, $skip);
62 $event = new AfterBackgroundSetup($env, $feature, $feature->getBackground(), $setup);
63 $this->eventDispatcher->dispatch($event::AFTER_SETUP, $event);
71 public function test(Environment $env, FeatureNode $feature, $skip)
73 return $this->baseTester->test($env, $feature, $skip);
79 public function tearDown(Environment $env, FeatureNode $feature, $skip, TestResult $result)
81 $event = new BeforeBackgroundTeardown($env, $feature, $feature->getBackground(), $result);
82 $this->eventDispatcher->dispatch(BackgroundTested::BEFORE_TEARDOWN, $event);
84 $teardown = $this->baseTester->tearDown($env, $feature, $skip, $result);
86 $event = new AfterBackgroundTested($env, $feature, $feature->getBackground(), $result, $teardown);
87 $this->eventDispatcher->dispatch(BackgroundTested::AFTER, $event);