public function testSteps()
 {
     $outline = new OutlineNode();
     $this->assertEquals(0, count($outline->getSteps()));
     $this->assertFalse($outline->hasSteps());
     $outline->addStep(new StepNode('Given', 'Something'));
     $this->assertEquals(1, count($outline->getSteps()));
     $this->assertTrue($outline->hasSteps());
     $outline->addStep(new StepNode('Then', 'Do'));
     $this->assertEquals(2, count($outline->getSteps()));
     $this->assertTrue($outline->hasSteps());
     $steps = $outline->getSteps();
     $this->assertInstanceOf('Behat\\Gherkin\\Node\\StepNode', $steps[0]);
     $this->assertEquals('Given', $steps[0]->getType());
     $this->assertEquals('Something', $steps[0]->getText());
     $this->assertSame($outline, $steps[0]->getParent());
     $this->assertEquals('Then', $steps[1]->getType());
     $this->assertEquals('Do', $steps[1]->getText());
     $this->assertSame($outline, $steps[1]->getParent());
 }
Example #2
0
 /**
  * Loads outline from provided outline hash.
  *
  * @param array   $hash Outline hash
  * @param integer $line Outline definition line
  *
  * @return OutlineNode
  */
 protected function loadOutlineHash(array $hash, $line = 0)
 {
     $outline = new Node\OutlineNode(null, isset($hash['line']) ? $hash['line'] : $line);
     $outline->setKeyword(isset($hash['keyword']) ? $hash['keyword'] : 'Scenario Outline');
     if (isset($hash['title'])) {
         $outline->setTitle($hash['title']);
     }
     if (isset($hash['tags'])) {
         $outline->setTags($hash['tags']);
     }
     if (isset($hash['examples'])) {
         if (isset($hash['examples']['keyword'])) {
             $keyword = $hash['examples']['keyword'];
             unset($hash['examples']['keyword']);
         } else {
             $keyword = 'Examples';
         }
         $table = $this->loadTableHash($hash['examples']);
         $table->setKeyword($keyword);
         $outline->setExamples($table);
     }
     if (isset($hash['steps'])) {
         foreach ($hash['steps'] as $stepIterator => $stepHash) {
             $outline->addStep($this->loadStepHash($stepHash, $stepIterator));
         }
     }
     return $outline;
 }
    public function testDumpOutlineScenarioReturnsContentAndTableNode()
    {
        $dumper = new Dumper($this->keywords);
        $scenario = new OutlineNode('my scenario');
        $scenario->addStep(new StepNode('Given', 'my example1'));
        // complete table
        $examples = new TableNode();
        $examples->addRow(array('lib1', 'lib2', 'lib3'));
        $examples->addRow(array(1, 2, 3));
        $examples->addRow(array(4, 5, 6));
        $scenario->setExamples($examples);
        $expected = '
  Scenario Outline: my scenario
    Given my example1

  Examples:
    | lib1 | lib2 | lib3 |
    | 1    | 2    | 3    |
    | 4    | 5    | 6    |';
        $this->assertEquals($expected, $dumper->dumpScenario($scenario));
    }