Ejemplo n.º 1
0
 /**
  * @Issue #3051
  */
 public function testSimilarSteps()
 {
     $pattern = 'there is a User called :arg1';
     $regex = $this->loader->makePlaceholderPattern($pattern);
     $this->assertRegExp($regex, 'there is a User called "John"');
     $this->assertNotRegExp($regex, 'there is a User called "John" and surname "Smith"');
 }
Ejemplo n.º 2
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $this->addStyles($output);
     $suite = $input->getArgument('suite');
     $config = $this->getSuiteConfig($suite, $input->getOption('config'));
     $config['describe_steps'] = true;
     $loader = new Gherkin($config);
     $steps = $loader->getSteps();
     foreach ($steps as $name => $context) {
         /** @var $table Table  **/
         $table = new Table($output);
         $table->setHeaders(array('Step', 'Implementation'));
         $output->writeln("Steps from <bold>{$name}</bold> context:");
         foreach ($context as $step => $callable) {
             if (count($callable) < 2) {
                 continue;
             }
             $method = $callable[0] . '::' . $callable[1];
             $table->addRow([$step, $method]);
         }
         $table->render();
     }
     if (!isset($table)) {
         $output->writeln("No steps are defined, start creating them by running <bold>gherkin:snippets</bold>");
     }
 }
 public function __construct($settings)
 {
     $loader = new Gherkin($settings);
     $finder = Finder::create()->files()->sortByName()->in($settings['path'])->followLinks()->name($loader->getPattern());
     foreach ($finder as $file) {
         $pathname = str_replace("//", "/", $file->getPathname());
         $loader->loadTests($pathname);
     }
     $availableSteps = $loader->getSteps();
     $allSteps = [];
     foreach ($availableSteps as $stepGroup) {
         $allSteps = array_merge($allSteps, $stepGroup);
     }
     foreach ($loader->getTests() as $test) {
         /** @var $test \Codeception\Test\Gherkin  **/
         $steps = $test->getScenarioNode()->getSteps();
         foreach ($steps as $step) {
             $matched = false;
             $text = $step->getText();
             foreach (array_keys($allSteps) as $pattern) {
                 if (preg_match($pattern, $text)) {
                     $matched = true;
                     break;
                 }
             }
             if (!$matched) {
                 $this->addSnippet($step);
             }
         }
     }
 }
Ejemplo n.º 4
0
 public function testMatchingPatterns()
 {
     $pattern = 'hello :name, are you from :place?';
     $regex = $this->loader->makePlaceholderPattern($pattern);
     $this->assertEquals('/hello "(.*?)", are you from "(.*?)"\\?/', $regex);
     $pattern = 'hello ":name", how are you';
     $regex = $this->loader->makePlaceholderPattern($pattern);
     $this->assertEquals('/hello "(.*?)", how are you/', $regex);
     $pattern = 'there should be :num cow(s)';
     $regex = $this->loader->makePlaceholderPattern($pattern);
     $this->assertRegExp($regex, 'there should be "1" cow');
     $this->assertRegExp($regex, 'there should be "5" cows');
 }
Ejemplo n.º 5
0
 public function __construct($settings, $test = null)
 {
     $loader = new Gherkin($settings);
     $pattern = $loader->getPattern();
     $path = $settings['path'];
     if (!empty($test)) {
         $path = $settings['path'] . '/' . $test;
         if (preg_match($pattern, $test)) {
             $path = dirname($path);
             $pattern = basename($test);
         }
     }
     $finder = Finder::create()->files()->sortByName()->in($path)->followLinks()->name($pattern);
     foreach ($finder as $file) {
         $pathname = str_replace("//", "/", $file->getPathname());
         $loader->loadTests($pathname);
     }
     $availableSteps = $loader->getSteps();
     $allSteps = [];
     foreach ($availableSteps as $stepGroup) {
         $allSteps = array_merge($allSteps, $stepGroup);
     }
     foreach ($loader->getTests() as $test) {
         /** @var $test \Codeception\Test\Gherkin  **/
         $steps = $test->getScenarioNode()->getSteps();
         if ($test->getFeatureNode()->hasBackground()) {
             $steps = array_merge($steps, $test->getFeatureNode()->getBackground()->getSteps());
         }
         foreach ($steps as $step) {
             $matched = false;
             $text = $step->getText();
             foreach (array_keys($allSteps) as $pattern) {
                 if (preg_match($pattern, $text)) {
                     $matched = true;
                     break;
                 }
             }
             if (!$matched) {
                 $this->addSnippet($step);
                 $file = str_ireplace($settings['path'], '', $test->getFeatureNode()->getFile());
                 if (!in_array($file, $this->features)) {
                     $this->features[] = $file;
                 }
             }
         }
     }
 }