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\Tester;
13 use Behat\Gherkin\Node\FeatureNode;
14 use Behat\Gherkin\Node\StepContainerInterface;
15 use Behat\Testwork\Environment\Environment;
16 use Behat\Testwork\Tester\Result\IntegerTestResult;
17 use Behat\Testwork\Tester\Result\TestResult;
18 use Behat\Testwork\Tester\Result\TestWithSetupResult;
21 * Tests provided collection of steps against provided environment.
23 * @author Konstantin Kudryashov <ever.zet@gmail.com>
25 final class StepContainerTester
35 * @param StepTester $stepTester
37 public function __construct(StepTester $stepTester)
39 $this->stepTester = $stepTester;
45 * @param Environment $env
46 * @param FeatureNode $feature
47 * @param StepContainerInterface $container
48 * @param Boolean $skip
50 * @return TestResult[]
52 public function test(Environment $env, FeatureNode $feature, StepContainerInterface $container, $skip)
55 foreach ($container->getSteps() as $step) {
56 $setup = $this->stepTester->setUp($env, $feature, $step, $skip);
57 $skipSetup = !$setup->isSuccessful() || $skip;
59 $testResult = $this->stepTester->test($env, $feature, $step, $skipSetup);
60 $skip = !$testResult->isPassed() || $skip;
62 $teardown = $this->stepTester->tearDown($env, $feature, $step, $skipSetup, $testResult);
63 $skip = $skip || $skipSetup || !$teardown->isSuccessful();
65 $integerResult = new IntegerTestResult($testResult->getResultCode());
66 $results[] = new TestWithSetupResult($setup, $integerResult, $teardown);