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\Hook\Tester;
13 use Behat\Behat\Hook\Scope\AfterFeatureScope;
14 use Behat\Behat\Hook\Scope\BeforeFeatureScope;
15 use Behat\Testwork\Environment\Environment;
16 use Behat\Testwork\Hook\HookDispatcher;
17 use Behat\Testwork\Hook\Tester\Setup\HookedSetup;
18 use Behat\Testwork\Hook\Tester\Setup\HookedTeardown;
19 use Behat\Testwork\Tester\Result\TestResult;
20 use Behat\Testwork\Tester\SpecificationTester;
23 * Feature tester which dispatches hooks during its execution.
25 * @author Konstantin Kudryashov <ever.zet@gmail.com>
27 final class HookableFeatureTester implements SpecificationTester
30 * @var SpecificationTester
36 private $hookDispatcher;
41 * @param SpecificationTester $baseTester
42 * @param HookDispatcher $hookDispatcher
44 public function __construct(SpecificationTester $baseTester, HookDispatcher $hookDispatcher)
46 $this->baseTester = $baseTester;
47 $this->hookDispatcher = $hookDispatcher;
53 public function setUp(Environment $env, $spec, $skip)
55 $setup = $this->baseTester->setUp($env, $spec, $skip);
61 $scope = new BeforeFeatureScope($env, $spec);
62 $hookCallResults = $this->hookDispatcher->dispatchScopeHooks($scope);
64 return new HookedSetup($setup, $hookCallResults);
70 public function test(Environment $env, $spec, $skip)
72 return $this->baseTester->test($env, $spec, $skip);
78 public function tearDown(Environment $env, $spec, $skip, TestResult $result)
80 $teardown = $this->baseTester->tearDown($env, $spec, $skip, $result);
86 $scope = new AfterFeatureScope($env, $spec, $result);
87 $hookCallResults = $this->hookDispatcher->dispatchScopeHooks($scope);
89 return new HookedTeardown($teardown, $hookCallResults);