Ejemplo n.º 1
0
 /**
  * Loads feature from provided feature hash.
  *
  * @param array   $hash Feature hash
  * @param integer $line Feature definition line
  *
  * @return FeatureNode
  */
 protected function loadFeatureHash(array $hash, $line = 0)
 {
     $feature = new Node\FeatureNode(null, null, null, isset($hash['line']) ? $hash['line'] : $line);
     $feature->setKeyword(isset($hash['keyword']) ? $hash['keyword'] : 'Feature');
     if (isset($hash['title'])) {
         $feature->setTitle($hash['title']);
     }
     if (isset($hash['description'])) {
         $feature->setDescription($hash['description']);
     }
     if (isset($hash['tags'])) {
         $feature->setTags($hash['tags']);
     }
     if (isset($hash['language'])) {
         $feature->setLanguage($hash['language']);
     }
     if (isset($hash['background'])) {
         $feature->setBackground($this->loadBackgroundHash($hash['background']));
     }
     if (isset($hash['scenarios'])) {
         foreach ($hash['scenarios'] as $scenarioIterator => $scenarioHash) {
             if (isset($scenarioHash['type']) && 'outline' === $scenarioHash['type']) {
                 $feature->addScenario($this->loadOutlineHash($scenarioHash, $scenarioIterator));
             } else {
                 $feature->addScenario($this->loadScenarioHash($scenarioHash, $scenarioIterator));
             }
         }
     }
     return $feature;
 }
Ejemplo n.º 2
0
 public function testTitle()
 {
     $feature = new FeatureNode();
     $this->assertNull($feature->getTitle());
     $feature->setTitle('test title 1');
     $this->assertEquals('test title 1', $feature->getTitle());
     $feature = new FeatureNode('test title 2');
     $this->assertEquals('test title 2', $feature->getTitle());
 }
Ejemplo n.º 3
0
 public function testIsScenarioMatchFilter()
 {
     $feature = new Node\FeatureNode();
     $scenario = new Node\ScenarioNode();
     $feature->addScenario($scenario);
     $feature->setTitle('random feature title');
     $scenario->setTitle('UNKNOWN');
     $filter = new NameFilter('feature1');
     $this->assertFalse($filter->isScenarioMatch($scenario));
     $feature->setTitle('feature1');
     $this->assertTrue($filter->isScenarioMatch($scenario));
     $feature->setTitle('feature1 title');
     $this->assertTrue($filter->isScenarioMatch($scenario));
     $feature->setTitle('some feature1 title');
     $this->assertTrue($filter->isScenarioMatch($scenario));
     $feature->setTitle('some feature title');
     $this->assertFalse($filter->isScenarioMatch($scenario));
     $filter = new NameFilter('/fea.ure/');
     $this->assertTrue($filter->isScenarioMatch($scenario));
     $feature->setTitle('some feaSure title');
     $scenario->setTitle('some feature title');
     $this->assertTrue($filter->isScenarioMatch($scenario));
     $feature->setTitle('some feture title');
     $scenario->setTitle('unk');
     $this->assertFalse($filter->isScenarioMatch($scenario));
     $feature->setTitle('unknown');
     $scenario->setTitle('simple scenario title');
     $filter = new NameFilter('scenario');
     $this->assertTrue($filter->isScenarioMatch($scenario));
     $scenario->setTitle('simple feature title');
     $this->assertFalse($filter->isScenarioMatch($scenario));
     $scenario->setTitle('simple scenerio title');
     $this->assertFalse($filter->isScenarioMatch($scenario));
     $filter = new NameFilter('/scen.rio/');
     $this->assertTrue($filter->isScenarioMatch($scenario));
 }
Ejemplo n.º 4
0
 public function translationTestDataProvider()
 {
     $data = array();
     $translator = $this->getTranslator();
     $parser = $this->getParser();
     $finder = new Finder();
     $i18ns = $finder->files()->name('*.xliff')->in(__DIR__ . '/../Fixtures/i18n');
     foreach ($i18ns as $i18n) {
         $language = basename($i18n, '.xliff');
         $translator->addResource('xliff', $i18n, $language, 'gherkin');
         $etalon = array();
         $features = array();
         foreach ($this->getTranslatedKeywords('Feature', $language) as $featureNum => $featureKeyword) {
             $gherkin = "# language: {$language}";
             $lineNum = 1;
             $feature = new Node\FeatureNode(null, null, null, ++$lineNum);
             $feature->setLanguage($language);
             $feature->setKeyword($featureKeyword);
             $feature->setTitle($title = "title of the feature N{$featureNum}");
             $feature->setDescription($description = "some\nfeature\ndescription");
             $gherkin .= "\n{$featureKeyword}: {$title}";
             $gherkin .= "\n{$description}";
             $lineNum += 3;
             $stepKeywords = $this->getTranslatedKeywords('Given|When|Then|And|But', $language);
             $backgroundKeywords = $this->getTranslatedKeywords('Background', $language);
             $examplesKeywords = $this->getTranslatedKeywords('Examples', $language);
             // Background
             $backgroundKeyword = $backgroundKeywords[0];
             $background = new Node\BackgroundNode(null, ++$lineNum);
             $background->setKeyword($backgroundKeyword);
             $feature->setBackground($background);
             $gherkin .= "\n{$backgroundKeyword}:";
             foreach ($stepKeywords as $stepNum => $stepKeyword) {
                 $step = new Node\StepNode($stepKeyword, $text = "text of the step N{$stepNum}", ++$lineNum);
                 $background->addStep($step);
                 $gherkin .= "\n{$stepKeyword} {$text}";
             }
             // Scenarios
             foreach ($this->getTranslatedKeywords('Scenario', $language) as $scenarioNum => $scenarioKeyword) {
                 $scenario = new Node\ScenarioNode($title = "title of the scenario N{$scenarioNum}", ++$lineNum);
                 $scenario->setKeyword($scenarioKeyword);
                 $feature->addScenario($scenario);
                 $gherkin .= "\n{$scenarioKeyword}: {$title}";
                 foreach ($stepKeywords as $stepNum => $stepKeyword) {
                     $step = new Node\StepNode($stepKeyword, $text = "text of the step N{$stepNum}", ++$lineNum);
                     $scenario->addStep($step);
                     $gherkin .= "\n{$stepKeyword} {$text}";
                 }
             }
             // Scenario Outlines
             foreach ($this->getTranslatedKeywords('Scenario Outline', $language) as $outlineNum => $outlineKeyword) {
                 $outline = new Node\OutlineNode($title = "title of the outline N{$outlineNum}", ++$lineNum);
                 $outline->setKeyword($outlineKeyword);
                 $feature->addScenario($outline);
                 $gherkin .= "\n{$outlineKeyword}: {$title}";
                 $stepKeyword = $stepKeywords[0];
                 $step = new Node\StepNode($stepKeyword, $text = "text of the step <num>", ++$lineNum);
                 $outline->addStep($step);
                 $gherkin .= "\n{$stepKeyword} {$text}";
                 $examplesKeyword = $examplesKeywords[0];
                 $examples = new Node\TableNode();
                 $examples->setKeyword($examplesKeyword);
                 $examples->addRow(array('num'));
                 $examples->addRow(array(2));
                 $outline->setExamples($examples);
                 $gherkin .= "\n{$examplesKeyword}:";
                 $gherkin .= "\n  | num |";
                 $gherkin .= "\n  | 2   |";
                 $lineNum += 3;
             }
             $etalon[] = $feature;
             $features[] = $this->getParser()->parse($gherkin);
         }
         $data[] = array($language, $etalon, $features);
     }
     return $data;
 }
Ejemplo n.º 5
0
 public function setTitle($title)
 {
     return $this->featureNode->setTitle($title);
 }