public function test() { $this->makeContexts(); $description = explode("\n", $this->featureNode->getDescription()); foreach ($description as $line) { $this->getScenario()->runStep(new Comment($line)); } if ($background = $this->featureNode->getBackground()) { foreach ($background->getSteps() as $step) { $this->runStep($step); } } foreach ($this->scenarioNode->getSteps() as $step) { $this->runStep($step); } }
public function testSteps() { $scenario = new ScenarioNode(); $this->assertEquals(0, count($scenario->getSteps())); $this->assertFalse($scenario->hasSteps()); $scenario->addStep(new StepNode('Given', 'Something')); $this->assertEquals(1, count($scenario->getSteps())); $this->assertTrue($scenario->hasSteps()); $scenario->addStep(new StepNode('Then', 'Do')); $this->assertEquals(2, count($scenario->getSteps())); $this->assertTrue($scenario->hasSteps()); $steps = $scenario->getSteps(); $this->assertInstanceOf('Behat\\Gherkin\\Node\\StepNode', $steps[0]); $this->assertEquals('Given', $steps[0]->getType()); $this->assertEquals('Something', $steps[0]->getText()); $this->assertSame($scenario, $steps[0]->getParent()); $this->assertEquals('Then', $steps[1]->getType()); $this->assertEquals('Do', $steps[1]->getText()); $this->assertSame($scenario, $steps[1]->getParent()); }
/** * Runs definition callback. * * @param ContextInterface $context * * @return mixed * * @throws BehaviorException */ public function run(ContextInterface $context) { preg_match($this->getRegex(), $this->getMatchedText(), $matches); $replacements = array(); foreach ($matches as $key => $value) { if (!is_numeric($key)) { $replacements["<{$key}>"] = $value; } } $steps = array(); foreach ($this->scenario->getSteps() as $stepOutline) { /** @var $step StepNode */ $step = clone $stepOutline; $step->setText(strtr($step->getText(), $replacements)); $steps[] = new Step($step); } return $steps; }
public function call($suffix = null) { $this->calls++; $scenario = $this->scenario; if (isset($suffix)) { $scenario = new ScenarioNode($scenario->getTitle() . $suffix, $scenario->getTags(), $scenario->getSteps(), $scenario->getKeyword(), $scenario->getLine()); } $feature = $this->feature; $skip = $this->skip; $isolatedEnvironment = $this->env; $tester = $scenario instanceof OutlineNode ? $this->outlineTester : $this->scenarioTester; $setup = $tester->setUp($isolatedEnvironment, $feature, $scenario, $skip); $localSkip = !$setup->isSuccessful() || $skip; $testResult = $tester->test($isolatedEnvironment, $feature, $scenario, $localSkip); $teardown = $tester->tearDown($isolatedEnvironment, $feature, $scenario, $localSkip, $testResult); $integerResult = new IntegerTestResult($testResult->getResultCode()); $result = new TestWithSetupResult($setup, $integerResult, $teardown); $this->results[] = $result; }
/** * Dumps scenario. * * @param ScenarioNode $scenario Scenario instance * * @return string */ public function dumpScenario(ScenarioNode $scenario) { $keyWordToUse = $scenario instanceof OutlineNode ? $this->keywords->getOutlineKeywords() : $this->keywords->getScenarioKeywords(); $content = '' . (sizeof($scenario->getTags()) > 0 ? PHP_EOL . $this->dumpTags($scenario->getTags(), 1) : '') . PHP_EOL . $this->dumpKeyword($keyWordToUse, $scenario->getTitle(), 1); foreach ($scenario->getSteps() as $step) { $content .= PHP_EOL . $this->dumpIndent(2) . $this->dumpStep($step); } if ($scenario instanceof OutlineNode) { $content .= '' . PHP_EOL . PHP_EOL . $this->dumpKeyword($this->keywords->getExamplesKeywords(), '', 1); $examples = $scenario->getExamples(); $content .= $this->dumpTableNode($examples, 2); } return $content; }
public function testCanFormatStepsWithPyString() { $this->formatter = new Step(Step::ALIGN_TO_LEFT); $expected = <<<EOS Given I am a Java programmer And I am not Kawaii When I start to contribute to a php project: """ This is a pyString Multi-line :D Meh... kawaii hu!? """ Then I start to love php When I go to a php events Then I start to become a Kawaii guy EOS; $tableNode = new PyStringNode(['This is a pyString', 'Multi-line :D', '', 'Meh... kawaii hu!?'], 1); $scenario = new ScenarioNode(' Not all people who program php are becoming kawaii ', [' kawaii ', ' kawaii-bug-12 '], [new StepNode('Given', ' I am a Java programmer ', [], 1, 'Given'), new StepNode('And', ' I am not Kawaii ', [], 2, 'And'), new StepNode('When', ' I start to contribute to a php project: ', [$tableNode], 3, 'And'), new StepNode('Then', ' I start to love php ', [], 4, 'And'), new StepNode('When', ' I go to a php events ', [], 5, 'And'), new StepNode('Then', 'I start to become a Kawaii guy ', [], 5, 'And')], 'Scenario', 1); self::assertSame($expected, $this->formatter->format($scenario->getSteps())); }