Пример #1
1
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $options = $input->getOptions();
     if ($input->getArgument('test')) {
         $options['steps'] = true;
     }
     $suite = $input->getArgument('suite');
     $test = $input->getArgument('test');
     $codecept = new \Codeception\Codecept((array) $options);
     $suites = $suite ? array($suite) : \Codeception\Configuration::suites();
     $output->writeln(\Codeception\Codecept::versionString() . "\nPowered by " . \PHPUnit_Runner_Version::getVersionString());
     if ($suite and $test) {
         $codecept->runSuite($suite, $test);
     }
     if (!$test) {
         foreach ($suites as $suite) {
             $codecept->runSuite($suite);
         }
     }
     $codecept->printResult();
     if (!$input->getOption('no-exit')) {
         if ($codecept->getResult()->failureCount() or $codecept->getResult()->errorCount()) {
             exit(1);
         }
     }
 }
Пример #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = \Codeception\Configuration::config();
     $suites = \Codeception\Configuration::suites();
     foreach ($suites as $suite) {
         $settings = \Codeception\Configuration::suiteSettings($suite, $config);
         $modules = \Codeception\Configuration::modules($settings);
         $phpdoc = array();
         $methodCounter = 0;
         foreach ($modules as $modulename => $module) {
             $class = new \ReflectionClass('\\Codeception\\Module\\' . $modulename);
             $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
             $phpdoc[] = '';
             $phpdoc[] = 'Methods from ' . $modulename;
             foreach ($methods as $method) {
                 if (strpos($method->name, '_') === 0) {
                     continue;
                 }
                 $params = array();
                 foreach ($method->getParameters() as $param) {
                     if ($param->isOptional()) {
                         continue;
                     }
                     $params[] = '$' . $param->name;
                 }
                 $params = implode(', ', $params);
                 $phpdoc[] = '@method ' . $settings['class_name'] . ' ' . $method->name . '(' . $params . ')';
                 $methodCounter++;
             }
         }
         $contents = sprintf($this->template, implode("\r\n * ", $phpdoc), 'class', $settings['class_name'], '\\Codeception\\AbstractGuy');
         file_put_contents($file = $settings['path'] . $settings['class_name'] . '.php', $contents);
         $output->writeln("{$file} generated sucessfully. {$methodCounter} methods added");
     }
 }
Пример #3
0
 protected function runSuites($suites, $skippedSuites = array())
 {
     $executed = 0;
     foreach ($suites as $suite) {
         if (in_array($suite, $skippedSuites)) {
             continue;
         }
         if (!in_array($suite, Configuration::suites())) {
             continue;
         }
         $this->codecept->runSuite($suite);
         $executed++;
     }
     return $executed;
 }
 protected function updateCepts()
 {
     $counter = 0;
     $suites = \Codeception\Configuration::suites();
     $config = \Codeception\Configuration::config();
     foreach ($suites as $suite) {
         $settings = \Codeception\Configuration::suiteSettings($suite, $config);
         $cepts = Finder::create()->files()->name('*Cept.php')->in($settings['path']);
         $prepend_line = "use {$this->namespace}\\{$settings['class_name']};\n\n";
         foreach ($cepts as $cept) {
             $cept_body = file_get_contents($cept);
             $cept_body = str_replace('<?php', '<?php ' . $prepend_line, $cept_body);
             $this->save($cept, $cept_body, true);
             $counter++;
         }
     }
     return $counter;
 }
Пример #5
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln(\Codeception\Codecept::versionString() . "\nPowered by " . \PHPUnit_Runner_Version::getVersionString());
     $options = $input->getOptions();
     if ($options['group']) {
         $output->writeln(sprintf("[Groups] <info>%s</info> ", implode(', ', $options['group'])));
     }
     if ($input->getArgument('test') && strtolower(substr($input->getArgument('test'), -4)) === '.php') {
         $options['steps'] = true;
     }
     if ($input->getOption('debug')) {
         $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
     }
     $suite = $input->getArgument('suite');
     $test = $input->getArgument('test');
     $codecept = new \Codeception\Codecept((array) $options);
     $config = \Codeception\Configuration::config();
     if (strpos($suite, $config['paths']['tests']) === 0) {
         $matches = $this->matchTestFromFilename($suite, $config['paths']['tests']);
         $suite = $matches[1];
         $test = $matches[2];
     }
     $suites = $suite ? array($suite) : \Codeception\Configuration::suites();
     if ($suite and $test) {
         $codecept->runSuite($suite, $test);
     }
     if (!$test) {
         foreach ($suites as $suite) {
             $codecept->runSuite($suite);
         }
     }
     $codecept->printResult();
     if (!$input->getOption('no-exit')) {
         if ($codecept->getResult()->failureCount() or $codecept->getResult()->errorCount()) {
             exit(1);
         }
     }
 }
Пример #6
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;
 }
Пример #7
0
 protected function getSuites($conf)
 {
     Configuration::config($conf);
     return Configuration::suites();
 }
 /**
  * @group core
  */
 public function testSuites()
 {
     $suites = \Codeception\Configuration::suites();
     $this->assertContains('unit', $suites);
     $this->assertContains('cli', $suites);
 }
Пример #9
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = \Codeception\Configuration::config($input->getOption('config'));
     $suites = \Codeception\Configuration::suites();
     foreach ($suites as $suite) {
         $settings = \Codeception\Configuration::suiteSettings($suite, $config);
         $modules = \Codeception\Configuration::modules($settings);
         $code = array();
         $methodCounter = 0;
         $aliases = array();
         $methods[] = array();
         foreach ($modules as $modulename => $module) {
             $className = '\\Codeception\\Module\\' . $modulename;
             $class = new \ReflectionClass($className);
             $aliases[] = 'use ' . ltrim($className, '\\') . ';';
             $refMethods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
             foreach ($refMethods as $refMethod) {
                 if (strpos($refMethod->name, '_') === 0) {
                     continue;
                 }
                 if (in_array($refMethod->name, $methods)) {
                     continue;
                 }
                 $params = array();
                 foreach ($refMethod->getParameters() as $param) {
                     if ($param->isOptional()) {
                         $params[] = '$' . $param->name . ' = null';
                     } else {
                         $params[] = '$' . $param->name;
                     }
                 }
                 if (0 === strpos($refMethod->name, 'see')) {
                     $type = 'assertion';
                 } elseif (0 === strpos($refMethod->name, 'am')) {
                     $type = 'condition';
                 } else {
                     $type = 'action';
                 }
                 $doc = $refMethod->getDocComment();
                 if (!$doc) {
                     $interfaces = $class->getInterfaces();
                     foreach ($interfaces as $interface) {
                         $i = new \ReflectionClass($interface->name);
                         if ($i->hasMethod($refMethod->name)) {
                             $doc = $i->getMethod($refMethod->name)->getDocComment();
                             break;
                         }
                     }
                 }
                 if (!$doc) {
                     $parent = new \ReflectionClass($class->getParentClass()->name);
                     if ($parent->hasMethod($refMethod->name)) {
                         $doc = $parent->getMethod($refMethod->name)->getDocComment();
                     }
                 }
                 $doc = str_replace('/**', '', $doc);
                 $doc = trim(str_replace('*/', '', $doc));
                 if (!$doc) {
                     $doc = "*";
                 }
                 $params = implode(', ', $params);
                 $code[] = sprintf($this->methodTemplate, $doc, $modulename, $refMethod->name, $refMethod->name, $params, $type, $refMethod->name);
                 $methodCounter++;
                 $methods[] = $refMethod->name;
             }
         }
         // append PHPDoc for abstractGuy methods
         $className = '\\Codeception\\AbstractGuy';
         $class = new \ReflectionClass($className);
         $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
         $inherited = array();
         foreach ($methods as $method) {
             if (strpos($method->name, '_') === 0) {
                 continue;
             }
             if (in_array($method->name, $methods)) {
                 continue;
             }
             $params = array();
             foreach ($method->getParameters() as $param) {
                 if ($param->isOptional()) {
                     $params[] = '$' . $param->name . ' = null';
                 } else {
                     $params[] = '$' . $param->name;
                 }
             }
             $params = implode(', ', $params);
             $inherited[] = sprintf($this->inheritedMethodTemplate, $method->name, $params);
         }
         $aliases[] = "\n/**\n * Inherited methods";
         $aliases[] = implode("\n", $inherited);
         $aliases[] = '*/';
         $contents = sprintf($this->template, implode("\n", $aliases), 'class', $settings['class_name'], '\\Codeception\\AbstractGuy', implode("\n\n ", $code));
         file_put_contents($file = $settings['path'] . $settings['class_name'] . '.php', $contents);
         $output->writeln("{$file} generated successfully. {$methodCounter} methods added");
     }
 }
Пример #10
0
 /**
  * Executes Run command
  *
  * @since 1.0.0
  * @throws \RuntimeException When a suite is not found.
  *
  * @access public
  * @param \Symfony\Component\Console\Input\InputInterface $input The input arguments.
  * @param \Symfony\Component\Console\Output\OutputInterface $output The output interface.
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $this->options = $input->getOptions();
     $this->output = $output;
     $config = Configuration::config($this->options['config']);
     if (!$this->options['colors']) {
         $this->options['colors'] = $config['settings']['colors'];
     }
     if (!$this->options['silent']) {
         $this->output->writeln(Codecept::versionString() . "\nPowered by " . \PHPUnit_Runner_Version::getVersionString());
     }
     if ($this->options['debug']) {
         $this->output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
     }
     $userOptions = array_intersect_key($this->options, array_flip($this->passedOptionKeys($input)));
     $userOptions = array_merge($userOptions, $this->booleanOptions($input, ['xml', 'html', 'json', 'tap', 'coverage', 'coverage-xml', 'coverage-html']));
     $userOptions['verbosity'] = $this->output->getVerbosity();
     $userOptions['interactive'] = !$input->hasParameterOption(array('--no-interaction', '-n'));
     if ($this->options['no-colors']) {
         $userOptions['colors'] = false;
     }
     if ($this->options['group']) {
         $userOptions['groups'] = $this->options['group'];
     }
     if ($this->options['skip-group']) {
         $userOptions['excludeGroups'] = $this->options['skip-group'];
     }
     if ($this->options['report']) {
         $userOptions['silent'] = true;
     }
     if ($this->options['coverage-xml'] || $this->options['coverage-html'] || $this->options['coverage-text']) {
         $this->options['coverage'] = true;
     }
     $suite = $input->getArgument('suite');
     $test = $input->getArgument('test');
     if (!Configuration::isEmpty() && !$test && strpos($suite, $config['paths']['tests']) === 0) {
         list($matches, $suite, $test) = $this->matchTestFromFilename($suite, $config['paths']['tests']);
     }
     if ($this->options['group']) {
         $this->output->writeln(sprintf("[Groups] <info>%s</info> ", implode(', ', $this->options['group'])));
     }
     if ($input->getArgument('test')) {
         $this->options['steps'] = true;
     }
     if ($test) {
         $filter = $this->matchFilteredTestNameEx($test);
         $userOptions['filter'] = $filter;
     }
     $this->codecept = new Codecept($userOptions);
     if ($suite && $test) {
         $this->codecept->run($suite, $test);
     }
     if (!$test) {
         $suites = $suite ? explode(',', $suite) : Configuration::suites();
         $this->executed = $this->runSuites($suites, $this->options['skip']);
         if (!empty($config['include'])) {
             $current_dir = Configuration::projectDir();
             $suites += $config['include'];
             $this->runIncludedSuites($config['include'], $current_dir);
         }
         if ($this->executed === 0) {
             throw new \RuntimeException(sprintf("Suite '%s' could not be found", implode(', ', $suites)));
         }
     }
     $this->codecept->printResult();
     if (!$input->getOption('no-exit')) {
         if (!$this->codecept->getResult()->wasSuccessful()) {
             exit(1);
         }
     }
 }
Пример #11
0
 protected function getSuites($conf)
 {
     \Codeception\Configuration::config($conf);
     return \Codeception\Configuration::suites();
 }