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()); }
public function testTokens() { $step = new StepNode('When', 'Some "<text>" in <string>'); $scenario = new ScenarioNode(); $scenario->addStep($step); $feature = new FeatureNode(); $feature->addScenario($scenario); $feature->freeze(); $step1 = $step->createExampleRowStep(array('text' => 'change')); $this->assertNotSame($step, $step1); $this->assertEquals('Some "change" in <string>', $step1->getText()); $this->assertEquals('Some "<text>" in <string>', $step1->getCleanText()); $step2 = $step->createExampleRowStep(array('text' => 'change', 'string' => 'browser')); $this->assertNotSame($step, $step2); $this->assertEquals('Some "change" in browser', $step2->getText()); $this->assertEquals('Some "<text>" in <string>', $step2->getCleanText()); }
/** * Loads scenario from provided scenario hash. * * @param array $hash Scenario hash * @param integer $line Scenario definition line * * @return ScenarioNode */ protected function loadScenarioHash(array $hash, $line = 0) { $scenario = new Node\ScenarioNode(null, isset($hash['line']) ? $hash['line'] : $line); $scenario->setKeyword(isset($hash['keyword']) ? $hash['keyword'] : 'Scenario'); if (isset($hash['title'])) { $scenario->setTitle($hash['title']); } if (isset($hash['tags'])) { $scenario->setTags($hash['tags']); } if (isset($hash['steps'])) { foreach ($hash['steps'] as $stepIterator => $stepHash) { $scenario->addStep($this->loadStepHash($stepHash, $stepIterator)); } } return $scenario; }
public function testDumpScenarioWithTagsAddTagsToTheContent() { $dumper = new Dumper($this->keywords); $scenario = new ScenarioNode('my scenario'); $scenario->addStep(new StepNode('Given', 'my example1')); $scenario->addTag('tag1'); $scenario->addTag('tag2'); $expected = ' @tag1 @tag2 Scenario: my scenario Given my example1'; $this->assertEquals($expected, $dumper->dumpScenario($scenario)); }