コード例 #1
0
    public function testTokens()
    {
        $table = new TableNode();
        $table->addRow(array('username', 'password'));
        $table->addRow(array('<username>', '<password>'));
        $tableCompare = new TableNode(<<<TABLE
| username | password |
| everzet  | qwerty   |
TABLE
);
        $exampleTable = $table->createExampleRowStepArgument(array('username' => 'everzet', 'password' => 'qwerty'));
        $this->assertNotSame($table, $exampleTable);
        $this->assertSame($tableCompare->getRows(), $exampleTable->getRows());
    }
コード例 #2
0
ファイル: TableNodeTest.php プロジェクト: kingsj/core
    public function testTableFromArrayCreation()
    {
        $table1 = new TableNode();
        $table1->addRow(array('username', 'password'));
        $table1->addRow(array('everzet', 'qwerty'));
        $table1->addRow(array('antono', 'pa$sword'));
        $table2 = new TableNode(<<<TABLE
| username | password |
| everzet  | qwerty   |
| antono   | pa\$sword|
TABLE
);
        $this->assertEquals($table2->getRows(), $table1->getRows());
        $this->assertEquals(array(array('username' => 'everzet', 'password' => 'qwerty'), array('username' => 'antono', 'password' => 'pa$sword')), $table1->getHash());
        $this->assertEquals(array('username' => 'password', 'everzet' => 'qwerty', 'antono' => 'pa$sword'), $table2->getRowsHash());
    }
コード例 #3
0
 /**
  * The assert_entities step should verify that entities have expected values
  *
  * @param \Ingenerator\BeEntity\Factory        $factory the entity factory mock
  * @param \Ingenerator\BeEntity\FactoryManager $manager the factory manager mock
  * @param \Doctrine\ORM\EntityManager $entity_manager the entity manager
  *
  * @return void
  * @see \Ingenerator\BeEntity\Context\BeEntityContext::assert_entities
  */
 public function it_can_verify_that_expected_entities_have_expected_values($factory, $manager, $entity_manager)
 {
     $manager->create_factory('Dummy')->willReturn($factory);
     $this->set_factory_manager($manager);
     // The entity exists but has invalid values
     $factory->matches('not existing dummy', array('active' => 'y', 'foo' => 'bar'))->willReturn(array('foo' => array('exp' => 'bar', 'got' => 'foo')));
     // Stub some entity data that would be specified in the table
     $data_1 = array('title' => 'not existing dummy', 'active' => 'y', 'foo' => 'bar');
     $table = new TableNode();
     $table->addRow(array_keys($data_1));
     $table->addRow($data_1);
     // The entity manager should be cleared to ensure values are reloaded from DB
     $entity_manager->clear()->shouldBeCalled();
     $this->shouldThrow('\\Ingenerator\\BeEntity\\Exception\\ExpectationException')->during('assert_entities', array('Dummy', $table));
 }
コード例 #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;
 }
コード例 #5
0
 /**
  * Helper function to modify #count#, #refcount# and #repeatcount# in table.
  *
  * @param TableNode $data Data to be passed to the resource.
  * @throws
  */
 protected function fix_data_counter(TableNode $data)
 {
     $datanodes = array();
     $rows = $data->getRows();
     // Get table keys and remove instances and reference
     $firstrow = array_shift($rows);
     if (($instancekey = array_search('instances', $firstrow)) !== false) {
         unset($firstrow[$instancekey]);
     }
     if (($refkey = array_search('referencecount', $firstrow)) !== false) {
         unset($firstrow[$refkey]);
     }
     if (($repeatkey = array_search('repeat', $firstrow)) !== false) {
         unset($firstrow[$repeatkey]);
     }
     // Create all instances.
     foreach ($rows as $row) {
         // Get count and unset instances key.
         $instances = $row[$instancekey];
         unset($row[$instancekey]);
         // Check if there is an refrence which needs to be met.
         // Reference is like how many categories to use to create given instances of sub-category.
         $reference = 0;
         if ($refkey) {
             $reference = $row[$refkey];
             unset($row[$refkey]);
             // We want sequential filling of data so keep track of counter.
             $referencecounter = 1;
             $maxperreference = ceil($instances / $reference);
         }
         // Check if repeat is given to repeat process.
         $repeat = 1;
         if ($repeatkey) {
             $repeat = $row[$repeatkey];
             unset($row[$repeatkey]);
         }
         for ($repeatcounter = 1; $repeatcounter <= $repeat; $repeatcounter++) {
             for ($i = 1; $i <= $instances; $i++) {
                 $rowtoadd = $row;
                 $datanode = new TableNode();
                 $datanode->addRow($firstrow);
                 foreach ($rowtoadd as $key => $value) {
                     if ($reference) {
                         $rowtoadd[$key] = str_replace("#count#", $referencecounter, $value);
                     } else {
                         $rowtoadd[$key] = str_replace("#count#", $i, $value);
                     }
                     $rowtoadd[$key] = str_replace("#refcount#", $i, $rowtoadd[$key]);
                     $rowtoadd[$key] = str_replace("#repeatcount#", $repeatcounter, $rowtoadd[$key]);
                 }
                 $datanode->addRow($rowtoadd);
                 // Call generator function.
                 //$contexttouse->$function($elementname, $datanode);
                 $datanodes[] = $datanode;
                 // We want sequential filling of data so increment reference counter.
                 if ($reference && $i % $maxperreference == 0) {
                     $referencecounter++;
                 }
             }
         }
     }
     return $datanodes;
 }
コード例 #6
0
ファイル: ArrayLoader.php プロジェクト: unkerror/Budabot
 /**
  * Loads table from provided hash.
  *
  * @param array $hash Table hash
  *
  * @return TableNode
  */
 protected function loadTableHash(array $hash)
 {
     $table = new Node\TableNode();
     foreach ($hash as $line => $row) {
         $table->addRow($row, $line);
     }
     return $table;
 }
コード例 #7
0
    public function translationTestDataProvider()
    {
        $keywords = $this->getKeywords();
        $lexer = new Lexer($keywords);
        $parser = new Parser($lexer);
        $dumper = new KeywordsDumper($keywords);
        $data = array();
        foreach ($this->getKeywordsArray() as $lang => $i18nKeywords) {
            $features = array();
            foreach (explode('|', $i18nKeywords['feature']) as $transNum => $featureKeyword) {
                $line = 1;
                if ('en' !== $lang) {
                    $line = 2;
                }
                $feature = new Node\FeatureNode('Internal operations', <<<DESC
In order to stay secret
As a secret organization
We need to be able to erase past agents' memory
DESC
, $lang . '_' . ($transNum + 1) . '.feature', $line);
                $feature->setLanguage($lang);
                $feature->setKeyword($featureKeyword);
                $line += 5;
                $background = new Node\BackgroundNode(null, $line);
                $keywords = explode('|', $i18nKeywords['background']);
                $background->setKeyword($keywords[0]);
                $line += 1;
                $line = $this->addSteps($background, $i18nKeywords['given'], 'there is agent A', $line);
                $line = $this->addSteps($background, $i18nKeywords['and'], 'there is agent B', $line);
                $feature->setBackground($background);
                $line += 1;
                foreach (explode('|', $i18nKeywords['scenario']) as $scenarioKeyword) {
                    $scenario = new Node\ScenarioNode('Erasing agent memory', $line);
                    $scenario->setKeyword($scenarioKeyword);
                    $line += 1;
                    $line = $this->addSteps($scenario, $i18nKeywords['given'], 'there is agent J', $line);
                    $line = $this->addSteps($scenario, $i18nKeywords['and'], 'there is agent K', $line);
                    $line = $this->addSteps($scenario, $i18nKeywords['when'], 'I erase agent K\'s memory', $line);
                    $line = $this->addSteps($scenario, $i18nKeywords['then'], 'there should be agent J', $line);
                    $line = $this->addSteps($scenario, $i18nKeywords['but'], 'there should not be agent K', $line);
                    $feature->addScenario($scenario);
                    $line += 1;
                }
                foreach (explode('|', $i18nKeywords['scenario_outline']) as $outlineKeyword) {
                    $outline = new Node\OutlineNode('Erasing other agents\' memory', $line);
                    $outline->setKeyword($outlineKeyword);
                    $line += 1;
                    $line = $this->addSteps($outline, $i18nKeywords['given'], 'there is agent <agent1>', $line);
                    $line = $this->addSteps($outline, $i18nKeywords['and'], 'there is agent <agent2>', $line);
                    $line = $this->addSteps($outline, $i18nKeywords['when'], 'I erase agent <agent2>\'s memory', $line);
                    $line = $this->addSteps($outline, $i18nKeywords['then'], 'there should be agent <agent1>', $line);
                    $line = $this->addSteps($outline, $i18nKeywords['but'], 'there should not be agent <agent2>', $line);
                    $line += 1;
                    $examples = new Node\TableNode();
                    $examples->addRow('                      | agent1 | agent2 |', ++$line);
                    $examples->addRow('                      | D      | M      |', ++$line);
                    $outline->setExamples($examples);
                    $keywords = explode('|', $i18nKeywords['examples']);
                    $examples->setKeyword($keywords[0]);
                    $line += 1;
                    $feature->addScenario($outline);
                    $line += 1;
                }
                $features[] = $feature;
            }
            $dumped = $dumper->dump($lang, false);
            $parsed = array();
            try {
                foreach ($dumped as $num => $dumpedFeature) {
                    $parsed[] = $parser->parse($dumpedFeature, $lang . '_' . ($num + 1) . '.feature');
                }
            } catch (\Exception $e) {
                throw new \Exception($e->getMessage() . ":\n" . $dumped, 0, $e);
            }
            $data[] = array($lang, $features, $parsed);
        }
        return $data;
    }
コード例 #8
0
ファイル: Parser.php プロジェクト: kingsj/core
 /**
  * Parses table token & returns it's node.
  *
  * @return  Behat\Gherkin\Node\TableNode
  */
 protected function parseTable()
 {
     $token = $this->expectTokenType('TableRow');
     $node = new Node\TableNode();
     $node->addRow($token->columns);
     $this->skipExtraChars();
     while ('TableRow' === $this->predictTokenType()) {
         $token = $this->expectTokenType('TableRow');
         $node->addRow($token->columns);
         $this->skipExtraChars();
     }
     return $node;
 }
コード例 #9
0
    public function providerTableNode()
    {
        // complete table
        $node1 = new TableNode();
        $node1->addRow(array('lib1', 'lib2', 'lib3'));
        $node1->addRow(array(1, 2, 3));
        $node1->addRow(array(4, 5, 6));
        $expected1 = '
| lib1 | lib2 | lib3 |
| 1    | 2    | 3    |
| 4    | 5    | 6    |';
        // empty table
        $node2 = new TableNode();
        $expected2 = '';
        return array(array($node1, $expected1), array($node2, $expected2));
    }