protected function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $config = \Codeception\Configuration::config();
     $suiteconf = \Codeception\Configuration::suiteSettings($suite, $config);
     @mkdir($path = \Codeception\Configuration::dataDir() . 'scenarios');
     @mkdir($path = $path . DIRECTORY_SEPARATOR . $suite);
     $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
     $suiteManager = new \Codeception\SuiteManager($dispatcher, $suite, $suiteconf);
     if (isset($suiteconf['bootstrap'])) {
         if (file_exists($suiteconf['path'] . $suiteconf['bootstrap'])) {
             require_once $suiteconf['path'] . $suiteconf['bootstrap'];
         }
     }
     $suiteManager->loadTests();
     $tests = $suiteManager->getSuite()->tests();
     foreach ($tests as $test) {
         if (!$test instanceof \Codeception\TestCase\Cept) {
             continue;
         }
         $test->loadScenario();
         $features = $test->getScenarioText();
         $name = $this->underscore(substr($test->getFileName(), 0, -8));
         $output->writeln("* {$name} generated");
         file_put_contents($path . DIRECTORY_SEPARATOR . $name . '.txt', $features);
     }
 }
Example #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $output->writeln('Warning: this command may affect your Helper classes');
     $config = \Codeception\Configuration::config($input->getOption('config'));
     $suiteconf = \Codeception\Configuration::suiteSettings($suite, $config);
     $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
     $suiteManager = new \Codeception\SuiteManager($dispatcher, $suite, $suiteconf);
     if (isset($suiteconf['bootstrap'])) {
         if (file_exists($suiteconf['path'] . $suiteconf['bootstrap'])) {
             require_once $suiteconf['path'] . $suiteconf['bootstrap'];
         }
     }
     $suiteManager->loadTests();
     $tests = $suiteManager->getSuite()->tests();
     $dialog = $this->getHelperSet()->get('dialog');
     $helper = $this->matchHelper();
     if (!$helper) {
         $output->writeln("<error>No helpers for suite {$suite} is defined. Can't append new methods</error>");
         return;
     }
     if (!file_exists($helper_file = \Codeception\Configuration::helpersDir() . $helper . '.php')) {
         $output->writeln("<error>Helper class {$helper}.php doesn't exist</error>");
         return;
     }
     $replaced = 0;
     $analyzed = 0;
     foreach ($tests as $test) {
         if (!$test instanceof \Codeception\TestCase\Cept) {
             continue;
         }
         $analyzed++;
         $test->testCodecept(false);
         $scenario = $test->getScenario();
         foreach ($scenario->getSteps() as $step) {
             if ($step->getName() == 'Comment') {
                 continue;
             }
             $action = $step->getAction();
             if (isset(\Codeception\SuiteManager::$actions[$action])) {
                 continue;
             }
             if (!$dialog->askConfirmation($output, "<question>\nAction '{$action}' is missing. Do you want to add it to helper class?\n</question>\n", false)) {
                 continue;
             }
             $example = sprintf('$I->%s(%s);', $action, $step->getArguments(true));
             $args = array_map(function ($a) {
                 return '$arg' . $a;
             }, range(1, count($step->getArguments())));
             $stub = sprintf($this->methodTemplate, $example, $action, implode(', ', $args));
             $contents = file_get_contents($helper_file);
             $contents = preg_replace('~}(?!.*})~ism', $stub, $contents);
             file_put_contents($helper_file, $contents);
             $output->writeln("Action '{$action}' added to helper {$helper}");
             $replaced++;
         }
     }
     $output->writeln("<info>Analysis finished. {$analyzed} tests analyzed. {$replaced} methods added</info>");
     $output->writeln("Run the 'build' command to finish");
 }
Example #3
0
 public function runSuite($suite, $test = null)
 {
     $settings = \Codeception\Configuration::suiteSettings($suite, $this->config);
     $suiteManager = new \Codeception\SuiteManager($this->dispatcher, $suite, $settings);
     $test ? $suiteManager->loadTest($settings['path'] . $test) : $suiteManager->loadTests();
     $this->runner = $suiteManager->run($this->result, $this->options);
     return $this->result;
 }
Example #4
0
 /**
  * When running multiple environments, getClassesFromFile() method in SuiteManager is called once for each env.
  * See \Codeception\Codecept::runSuite() - for each env new SuiteManager is created and tests loaded.
  * Make sure that calling getClassesFromFile() multiple times will always return the same classes.
  *
  * @group core
  */
 public function testAddCestWithEnv()
 {
     $file = \Codeception\Configuration::dataDir() . 'SimpleNamespacedTest.php';
     $this->suiteman->loadTests($file);
     $this->assertEquals(3, $this->suiteman->getSuite()->count());
     $newSuiteMan = new \Codeception\SuiteManager($this->dispatcher, 'suite', \Codeception\Configuration::$defaultSuiteSettings);
     $newSuiteMan->loadTests($file);
     $this->assertEquals(3, $newSuiteMan->getSuite()->count());
 }
Example #5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $config = \Codeception\Configuration::config($input->getOption('config'));
     $suiteconf = \Codeception\Configuration::suiteSettings($suite, $config);
     if ($input->getOption('path')) {
         $path = $input->getOption('path');
     } else {
         $path = \Codeception\Configuration::dataDir() . 'scenarios';
     }
     @mkdir($path);
     if (!is_writable($path)) {
         throw new \Codeception\Exception\Configuration("Path for logs is not writable. Please, set appropriate access mode for log path.");
     }
     $path = $path . DIRECTORY_SEPARATOR . $suite;
     if ($input->getOption('single-file')) {
         file_put_contents($path . '.txt', '');
     } else {
         @mkdir($path);
     }
     $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
     $suiteManager = new \Codeception\SuiteManager($dispatcher, $suite, $suiteconf);
     if ($suiteconf['bootstrap']) {
         if (file_exists($suiteconf['path'] . $suiteconf['bootstrap'])) {
             require_once $suiteconf['path'] . $suiteconf['bootstrap'];
         }
     }
     $suiteManager->loadTests();
     $tests = $suiteManager->getSuite()->tests();
     if ($input->getOption('format')) {
         $format = $input->getOption('format');
     } else {
         $format = 'text';
     }
     foreach ($tests as $test) {
         if (!$test instanceof \Codeception\TestCase\Cept) {
             continue;
         }
         $test->preload();
         $features = $test->getScenarioText($format);
         $name = $this->underscore(substr($test->getFileName(), 0, -8));
         if ($input->getOption('single-file')) {
             file_put_contents($path . '.txt', $features . PHP_EOL, FILE_APPEND);
             $output->writeln("* {$name} rendered");
         } else {
             file_put_contents($path . DIRECTORY_SEPARATOR . $name . '.txt', $features);
             $output->writeln("* {$name} generated");
         }
     }
 }
Example #6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $suiteconf = $this->getSuiteConfig($suite, $input->getOption('config'));
     $path = $input->getOption('path') ? $input->getOption('path') : Configuration::dataDir() . 'scenarios';
     $format = $input->getOption('format');
     @mkdir($path);
     if (!is_writable($path)) {
         throw new ConfigurationException("Path {$path} is not writable. Please, set valid permissions for folder to store scenarios.");
     }
     $path = $path . DIRECTORY_SEPARATOR . $suite;
     if (!$input->getOption('single-file')) {
         @mkdir($path);
     }
     $suiteManager = new \Codeception\SuiteManager(new EventDispatcher(), $suite, $suiteconf);
     if ($suiteconf['bootstrap']) {
         if (file_exists($suiteconf['path'] . $suiteconf['bootstrap'])) {
             require_once $suiteconf['path'] . $suiteconf['bootstrap'];
         }
     }
     $suiteManager->loadTests();
     $tests = $suiteManager->getSuite()->tests();
     $scenarios = "";
     foreach ($tests as $test) {
         if (!$test instanceof \Codeception\TestCase\Cept) {
             continue;
         }
         $feature = $test->getScenarioText($format);
         $name = $this->underscore(substr($test->getFileName(), 0, -8));
         if ($input->getOption('single-file')) {
             $scenarios .= $feature;
             $output->writeln("* {$name} rendered");
         } else {
             $feature = $this->decorate($feature, $format);
             $this->save($path . DIRECTORY_SEPARATOR . $name . $this->formatExtension($format), $feature);
             $output->writeln("* {$name} generated");
         }
     }
     if ($input->getOption('single-file')) {
         $this->save($path . $this->formatExtension($format), $this->decorate($scenarios, $format) . PHP_EOL);
     }
 }
Example #7
0
 protected function getTestsPerClass($config)
 {
     $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
     $suites = \Codeception\Configuration::suites();
     $testedClasses = array();
     foreach ($suites as $suite) {
         $suiteconf = \Codeception\Configuration::suiteSettings($suite, $config);
         $suiteManager = new \Codeception\SuiteManager($dispatcher, $suite, $suiteconf);
         $suiteManager->loadTests();
         $tests = $suiteManager->getSuite()->tests();
         foreach ($tests as $test) {
             if (!$test instanceof \Codeception\TestCase\Cest) {
                 continue;
             }
             $class = $test->getCoveredClass();
             if (!$class) {
                 continue;
             }
             isset($testedClasses[$class]) ? $testedClasses[$class][] = $test : ($testedClasses[$class] = array($test));
         }
     }
     return $testedClasses;
 }
 protected function tearDown()
 {
     \Codeception\SuiteManager::$modules = $this->modules;
     \Codeception\SuiteManager::$actions = $this->actions;
 }