Example #1
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $filename = $input->getArgument('test');
     $config = \Codeception\Configuration::config();
     $suiteconf = \Codeception\Configuration::suiteSettings($suite, $config);
     $guy = $suiteconf['class_name'];
     $file = sprintf($this->template, $guy);
     if (file_exists($suiteconf['path'] . DIRECTORY_SEPARATOR . $filename)) {
         $output->writeln("<comment>Test {$filename} already exists</comment>");
         return;
     }
     if (strpos(strrev($filename), strrev('Cept')) === 0) {
         $filename .= '.php';
     }
     if (strpos(strrev($filename), strrev('Cept.php')) !== 0) {
         $filename .= 'Cept.php';
     }
     if (strpos(strrev($filename), strrev('.php')) !== 0) {
         $filename .= '.php';
     }
     $filename = str_replace('\\', '/', $filename);
     $dirs = explode('/', $filename);
     array_pop($dirs);
     $path = $suiteconf['path'] . DIRECTORY_SEPARATOR;
     foreach ($dirs as $dir) {
         $path .= $dir . DIRECTORY_SEPARATOR;
         @mkdir($path);
     }
     file_put_contents($suiteconf['path'] . DIRECTORY_SEPARATOR . $filename, $file);
     $output->writeln("<info>Test was generated in {$filename}</info>");
 }
Example #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");
     }
 }
Example #3
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suiteName = $input->getArgument('suite');
     $this->output = $output;
     $config = Configuration::config($input->getOption('config'));
     $settings = Configuration::suiteSettings($suiteName, $config);
     $options = $input->getOptions();
     $options['debug'] = true;
     $options['steps'] = true;
     $this->codecept = new Codecept($options);
     $dispatcher = $this->codecept->getDispatcher();
     $this->test = (new Cept())->configDispatcher($dispatcher)->configName('interactive')->config('file', 'interactive')->initConfig();
     $suiteManager = new SuiteManager($dispatcher, $suiteName, $settings);
     $suiteManager->initialize();
     $this->suite = $suiteManager->getSuite();
     $scenario = new Scenario($this->test);
     $actor = $settings['class_name'];
     $I = new $actor($scenario);
     $this->listenToSignals();
     $output->writeln("<info>Interactive console started for suite {$suiteName}</info>");
     $output->writeln("<info>Try Codeception commands without writing a test</info>");
     $output->writeln("<info>type 'exit' to leave console</info>");
     $output->writeln("<info>type 'actions' to see all available actions for this suite</info>");
     $suiteEvent = new SuiteEvent($this->suite, $this->codecept->getResult(), $settings);
     $dispatcher->dispatch(Events::SUITE_BEFORE, $suiteEvent);
     $dispatcher->dispatch(Events::TEST_PARSED, new TestEvent($this->test));
     $dispatcher->dispatch(Events::TEST_BEFORE, new TestEvent($this->test));
     $output->writeln("\n\n\$I = new {$settings['class_name']}(\$scenario);");
     $scenario->run();
     $this->executeCommands($output, $I, $settings['bootstrap']);
     $dispatcher->dispatch(Events::TEST_AFTER, new TestEvent($this->test));
     $dispatcher->dispatch(Events::SUITE_AFTER, new SuiteEvent($this->suite));
     $output->writeln("<info>Bye-bye!</info>");
 }
Example #4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $output->writeln('Warning: this command may affect your Helper classes');
     $config = Configuration::config($input->getOption('config'));
     $suiteconf = Configuration::suiteSettings($suite, $config);
     $dispatcher = new EventDispatcher();
     $suiteManager = new 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 = 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 Cept) {
             continue;
         }
         $analyzed++;
         $test->testCodecept(false);
         $scenario = $test->getScenario();
         foreach ($scenario->getSteps() as $step) {
             if ($step->getName() == 'Comment') {
                 continue;
             }
             $action = $step->getAction();
             if (isset(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);
             $this->save($helper_file, $contents, true);
             $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 #5
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suiteName = $input->getArgument('suite');
     $this->output = $output;
     $config = \Codeception\Configuration::config($input->getOption('config'));
     $settings = \Codeception\Configuration::suiteSettings($suiteName, $config);
     $options = $input->getOptions();
     $options['debug'] = true;
     $options['steps'] = true;
     $this->codecept = new \Codeception\Codecept($options);
     $dispatcher = $this->codecept->getDispatcher();
     $suiteManager = new SuiteManager($dispatcher, $suiteName, $settings);
     $this->suite = $suiteManager->getSuite();
     $this->test = new Cept($dispatcher, array('name' => 'interactive', 'file' => 'interactive'));
     $guy = $settings['class_name'];
     $scenario = new Scenario($this->test);
     $I = new $guy($scenario);
     $this->listenToSignals();
     $output->writeln("<info>Interactive console started for suite {$suiteName}</info>");
     $output->writeln("<info>Try Codeception commands without writing a test</info>");
     $output->writeln("<info>type 'exit' to leave console</info>");
     $output->writeln("<info>type 'actions' to see all available actions for this suite</info>");
     $dispatcher->dispatch('suite.before', new Suite($this->suite, $this->codecept->getResult(), $settings));
     $dispatcher->dispatch('test.parsed', new \Codeception\Event\Test($this->test));
     $dispatcher->dispatch('test.before', new \Codeception\Event\Test($this->test));
     $output->writeln("\n\n\$I = new {$settings['class_name']}(\$scenario);");
     $scenario->run();
     $this->executeCommands($output, $I, $settings['bootstrap']);
     $dispatcher->dispatch('test.after', new \Codeception\Event\Test($this->test));
     $dispatcher->dispatch('suite.after', new Suite($this->suite));
     $output->writeln("<info>Bye-bye!</info>");
 }
 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 #7
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 #8
0
 public function __construct()
 {
     //grab the global config file
     $config = Configuration::config();
     //get  the unit settings
     $settings = Configuration::suiteSettings("unit", $config);
     //get the settings for the db module
     $dbConfig = (isset($settings['modules']['config']['Db'])) ? $settings['modules']['config']['Db'] : array();
     //set the config for the helper module
     $this->_setConfig($dbConfig);
 }
Example #9
0
 public function runSuite($suite, $test = null)
 {
     $settings = Configuration::suiteSettings($suite, $this->config);
     $suiteManager = new SuiteManager($this->dispatcher, $suite, $settings);
     $test ? $suiteManager->loadTest($settings['path'] . $test) : $suiteManager->loadTests();
     if (!$this->runner->getPrinter()) {
         $printer = new PHPUnit\ResultPrinter\UI($this->dispatcher, $this->options);
         $this->runner->setPrinter($printer);
     }
     $suiteManager->run($this->runner, $this->result, $this->options);
     return $this->result;
 }
 protected function execute($args = [], $isSuite = true)
 {
     $app = new Application();
     $app->add($this->command);
     $default = \Codeception\Configuration::$defaultConfig;
     $default['paths']['tests'] = __DIR__;
     $conf = $isSuite ? \Codeception\Configuration::suiteSettings('unit', $default) : $default;
     $this->config = array_merge($conf, $this->config);
     $commandTester = new CommandTester($app->find($this->commandName));
     $args['command'] = $this->commandName;
     $commandTester->execute($args, ['interactive' => false]);
     $this->output = $commandTester->getDisplay();
 }
Example #11
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 #12
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $class = $input->getArgument('class');
     $config = \Codeception\Configuration::config();
     $suiteconf = \Codeception\Configuration::suiteSettings($suite, $config);
     $guy = $suiteconf['class_name'];
     if (isset($suiteconf['bootstrap'])) {
         if (file_exists($suiteconf['path'] . $suiteconf['bootstrap'])) {
             require_once $suiteconf['path'] . $suiteconf['bootstrap'];
         } else {
             throw new \RuntimeException($suiteconf['path'] . $suiteconf['bootstrap'] . " couldn't be loaded");
         }
     }
     if (!class_exists($class, true)) {
         throw new \Exception("Class {$class} is not loaded. Please, add autoloader to suite bootstrap");
     }
     $namespaces = explode('\\', $class);
     $classname = array_pop($namespaces);
     $use = '';
     $path = $suiteconf['path'];
     foreach ($namespaces as $namespace) {
         $path .= DIRECTORY_SEPARATOR . $namespace;
         @mkdir($path);
     }
     if (!empty($namespaces)) {
         $use = 'namespace ' . implode('\\', $namespaces) . ";\n";
     }
     $reflected = new \ReflectionClass($class);
     $filename = $path . DIRECTORY_SEPARATOR . $classname . 'Cest.php';
     if (file_exists($filename)) {
         $output->writeln("<error>Test {$filename} already exists</error>");
         exit;
     }
     $tests = array();
     $methods = $reflected->getMethods(\ReflectionMethod::IS_PUBLIC);
     foreach ($methods as $method) {
         if ($method->getDeclaringClass()->name != $class) {
             continue;
         }
         if ($method->isConstructor() or $method->isDestructor()) {
             continue;
         }
         $tests[] = sprintf($this->methodTemplate, $classname, $method->name, $method->name, $guy, '$I');
     }
     $tests = implode("\n\n", $tests);
     file_put_contents($filename, sprintf($this->template, $use, 'class', $classname, '$class', $class, $tests));
     $output->writeln("<info>Cest for {$class} was created in {$filename}</info>");
 }
Example #13
0
    public function __construct()
    {
        //grab the global config file
        $config = Configuration::config();
        //get  the unit settings
        $settings = Configuration::suiteSettings("import", $config);
        //get the settings for the db module
        $dbConfig = (isset($settings['modules']['config']['Db'])) ? $settings['modules']['config']['Db'] : array();
        $dbConfig['user'] = $_ENV['db_user'];
        $dbConfig['password'] = $_ENV['db_password'];
        $this->_reconfigure($dbConfig);

        //$this->_setConfig($dbConfig);
        //$this->_initialize();
    }
Example #14
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $filename = $input->getArgument('test');
     $config = \Codeception\Configuration::config($input->getOption('config'));
     $suiteconf = \Codeception\Configuration::suiteSettings($suite, $config);
     $guy = $suiteconf['class_name'];
     $file = sprintf($this->template, $guy);
     $filename = $this->completeSuffix($filename, 'Cept');
     $this->buildPath($suiteconf['path'], $filename);
     $res = $this->save($suiteconf['path'] . DIRECTORY_SEPARATOR . $filename, $file);
     if (!$res) {
         $output->writeln("<error>Test {$filename} already exists</error>");
         exit;
     }
     $output->writeln("<info>Test was generated in {$filename}</info>");
 }
Example #15
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $class = $input->getArgument('class');
     $config = \Codeception\Configuration::config($input->getOption('config'));
     $suiteconf = \Codeception\Configuration::suiteSettings($suite, $config);
     $classname = $this->getClassName($class);
     $path = $this->buildPath($suiteconf['path'], $class);
     $ns = $this->getNamespaceString($class);
     $filename = $this->completeSuffix($classname, 'Test');
     $filename = $path . DIRECTORY_SEPARATOR . $filename;
     $res = $this->save($filename, sprintf($this->template, $ns, 'class', $classname));
     if (!$res) {
         $output->writeln("<error>Test {$filename} already exists</error>");
         exit;
     }
     $output->writeln("<info>Test for {$class} was created in {$filename}</info>");
 }
 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;
 }
Example #17
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $class = $input->getArgument('class');
     $config = \Codeception\Configuration::config($input->getOption('config'));
     $suiteconf = \Codeception\Configuration::suiteSettings($suite, $config);
     $guy = $suiteconf['class_name'];
     $classname = $this->getClassName($class);
     $path = $this->buildPath($suiteconf['path'], $class);
     $ns = $this->getNamespaceString($class);
     $filename = $this->completeSuffix($classname, 'Test');
     $filename = $path . $filename;
     if (file_exists($filename)) {
         $output->writeln("<error>Test {$filename} already exists</error>");
         exit;
     }
     file_put_contents($filename, sprintf($this->template, $ns, 'class', $classname, $guy, lcfirst($guy), lcfirst($guy), $guy));
     $output->writeln("<info>Test for {$class} was created in {$filename}</info>");
 }
Example #18
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suiteName = $input->getArgument('suite');
     $this->output = $output;
     $config = Configuration::config($input->getOption('config'));
     $settings = Configuration::suiteSettings($suiteName, $config);
     $options = $input->getOptions();
     $options['debug'] = true;
     $options['silent'] = true;
     $options['interactive'] = false;
     $options['colors'] = true;
     Debug::setOutput(new Output($options));
     $this->codecept = new Codecept($options);
     $dispatcher = $this->codecept->getDispatcher();
     $suiteManager = new SuiteManager($dispatcher, $suiteName, $settings);
     $suiteManager->initialize();
     $this->suite = $suiteManager->getSuite();
     $moduleContainer = $suiteManager->getModuleContainer();
     $this->actions = array_keys($moduleContainer->getActions());
     $this->test = new Cept(null, null);
     $this->test->getMetadata()->setServices(['dispatcher' => $dispatcher, 'modules' => $moduleContainer]);
     $scenario = new Scenario($this->test);
     if (isset($config["namespace"])) {
         $settings['class_name'] = $config["namespace"] . '\\' . $settings['class_name'];
     }
     $actor = $settings['class_name'];
     $I = new $actor($scenario);
     $this->listenToSignals();
     $output->writeln("<info>Interactive console started for suite {$suiteName}</info>");
     $output->writeln("<info>Try Codeception commands without writing a test</info>");
     $output->writeln("<info>type 'exit' to leave console</info>");
     $output->writeln("<info>type 'actions' to see all available actions for this suite</info>");
     $suiteEvent = new SuiteEvent($this->suite, $this->codecept->getResult(), $settings);
     $dispatcher->dispatch(Events::SUITE_BEFORE, $suiteEvent);
     $dispatcher->dispatch(Events::TEST_PARSED, new TestEvent($this->test));
     $dispatcher->dispatch(Events::TEST_BEFORE, new TestEvent($this->test));
     $output->writeln("\n\n<comment>\$I</comment> = new {$settings['class_name']}(\$scenario);");
     $this->executeCommands($input, $output, $I, $settings['bootstrap']);
     $dispatcher->dispatch(Events::TEST_AFTER, new TestEvent($this->test));
     $dispatcher->dispatch(Events::SUITE_AFTER, new SuiteEvent($this->suite));
     $output->writeln("<info>Bye-bye!</info>");
 }
Example #19
0
 /**
  * @param $filename
  * @return null|PHP_CodeCoverage
  */
 function __c3_factory($filename)
 {
     $phpCoverage = is_readable($filename) ? unserialize(file_get_contents($filename)) : new PHP_CodeCoverage();
     if (isset($_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_SUITE'])) {
         $suite = $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_SUITE'];
         try {
             $settings = \Codeception\Configuration::suiteSettings($suite, \Codeception\Configuration::config());
         } catch (Exception $e) {
             __c3_error($e->getMessage());
         }
     } else {
         $settings = \Codeception\Configuration::config();
     }
     try {
         \Codeception\CodeCoverageSettings::setup($phpCoverage)->filterWhiteList($settings)->filterBlackList($settings);
     } catch (Exception $e) {
         __c3_error($e->getMessage());
     }
     return $phpCoverage;
 }
Example #20
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $class = $input->getArgument('class');
     $config = \Codeception\Configuration::config($input->getOption('config'));
     $suiteconf = \Codeception\Configuration::suiteSettings($suite, $config);
     $guy = $suiteconf['class_name'];
     $classname = $this->getClassName($class);
     $path = $this->buildPath($suiteconf['path'], $class);
     $ns = $this->getNamespaceString($class);
     $filename = $this->completeSuffix($classname, 'Cest');
     $filename = $path . DIRECTORY_SEPARATOR . $filename;
     if (file_exists($filename)) {
         $output->writeln("<error>Test {$filename} already exists</error>");
         exit;
     }
     $classname = preg_replace("~Cest\$~", '', $classname);
     $tests = sprintf($this->methodTemplate, "tryToTest", $guy, '$I');
     file_put_contents($filename, sprintf($this->template, $ns, 'class', $classname, $tests));
     $output->writeln("<info>Cest was created in {$filename}</info>");
 }
Example #21
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;
 }
Example #22
0
 public function run($suite, $test = null)
 {
     ini_set('memory_limit', isset($this->config['settings']['memory_limit']) ? $this->config['settings']['memory_limit'] : '1024M');
     $settings = Configuration::suiteSettings($suite, Configuration::config());
     $selectedEnvironments = $this->options['env'];
     $environments = Configuration::suiteEnvironments($suite);
     if (!$selectedEnvironments or empty($environments)) {
         $this->runSuite($settings, $suite, $test);
         return;
     }
     foreach (array_unique($selectedEnvironments) as $envList) {
         $envArray = explode(',', $envList);
         $config = [];
         foreach ($envArray as $env) {
             if (isset($environments[$env])) {
                 $currentEnvironment = isset($config['current_environment']) ? [$config['current_environment']] : [];
                 $config = Configuration::mergeConfigs($config, $environments[$env]);
                 $currentEnvironment[] = $config['current_environment'];
                 $config['current_environment'] = implode(',', $currentEnvironment);
             }
         }
         if (empty($config)) {
             continue;
         }
         $suiteToRun = $suite;
         if (!empty($envList)) {
             $suiteToRun .= ' (' . implode(', ', $envArray) . ')';
         }
         $this->runSuite($config, $suiteToRun, $test);
     }
 }
Example #23
0
 protected function getSuiteConfig($suite, $conf)
 {
     $config = Configuration::config($conf);
     return Configuration::suiteSettings($suite, $config);
 }
 /**
  * Returns a configuration value for selected key
  * 
  * @param $configKey string
  */
 protected function getConfig($configKey)
 {
     $config = \Codeception\Configuration::config();
     $suiteSettings = \Codeception\Configuration::suiteSettings('acceptance', $config);
     return $suiteSettings['data'][self::CONFIG_NODE][$configKey];
 }
Example #25
0
 public function runSuite($suite, $test = null)
 {
     ini_set('memory_limit', isset($this->config['settings']['memory_limit']) ? $this->config['settings']['memory_limit'] : '1024M');
     $settings = Configuration::suiteSettings($suite, Configuration::config());
     $suiteManager = new SuiteManager($this->dispatcher, $suite, $settings);
     $test ? $suiteManager->loadTest($settings['path'] . $test) : $suiteManager->loadTests();
     $suiteManager->run($this->runner, $this->result, $this->options);
     return $this->result;
 }
 protected function getProviders()
 {
     return Configuration::suiteSettings('acceptance', Configuration::config())['modules']['config']['providers'];
 }
Example #27
0
 public function run($suite, $test = null)
 {
     ini_set('memory_limit', isset($this->config['settings']['memory_limit']) ? $this->config['settings']['memory_limit'] : '1024M');
     $settings = Configuration::suiteSettings($suite, Configuration::config());
     $selectedEnvironments = $this->options['env'];
     $environments = Configuration::suiteEnvironments($suite);
     if (!$selectedEnvironments or empty($environments)) {
         $this->runSuite($settings, $suite, $test);
         return;
     }
     foreach ($environments as $env => $config) {
         if (!in_array($env, $selectedEnvironments)) {
             continue;
         }
         $suiteToRun = is_int($env) ? $suite : "{$suite}-{$env}";
         $this->runSuite($config, $suiteToRun, $test);
     }
 }
 protected function _before()
 {
     $config = Configuration::config();
     //get  the unit settings
     $settings = Configuration::suiteSettings("unit", $config);
 }
Example #29
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");
     }
 }