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); } } }
public function __construct($options) { $this->options = $options; $this->logDir = Configuration::outputDir(); $this->settings = array_merge($this->settings, Configuration::config()['coverage']); self::$coverage = new \PHP_CodeCoverage(); }
protected function execute(InputInterface $input, OutputInterface $output) { $suites = $this->getSuites($input->getOption('config')); $output->writeln("<info>Building Guy classes for suites: " . implode(', ', $suites) . '</info>'); foreach ($suites as $suite) { $settings = $this->getSuiteConfig($suite, $input->getOption('config')); $namespace = rtrim($settings['namespace'], '\\'); $modules = \Codeception\Configuration::modules($settings); $code = array(); $methodCounter = 0; $output->writeln('<info>' . $settings['class_name'] . "</info> includes modules: " . implode(', ', array_keys($modules))); $docblock = array(); foreach ($modules as $module) { $docblock[] = "use " . get_class($module) . ";"; } $methods = array(); $actions = \Codeception\Configuration::actions($modules); foreach ($actions as $action => $moduleName) { if (in_array($action, $methods)) { continue; } $module = $modules[$moduleName]; $method = new \ReflectionMethod(get_class($module), $action); $code[] = $this->addMethod($method); $methods[] = $action; $methodCounter++; } $docblock = $this->prependAbstractGuyDocBlocks($docblock); $contents = sprintf($this->template, $namespace ? "namespace {$namespace};" : '', implode("\n", $docblock), 'class', $settings['class_name'], '\\Codeception\\AbstractGuy', implode("\n\n ", $code)); $file = $settings['path'] . $this->getClassName($settings['class_name']) . '.php'; $this->save($file, $contents, true); $output->writeln("{$settings['class_name']}.php generated successfully. {$methodCounter} methods added"); } }
public function updateActor(SuiteEvent $e) { $settings = $e->getSettings(); $modules = $e->getSuite()->getModules(); $actorFile = Configuration::supportDir() . '_generated' . DIRECTORY_SEPARATOR . $settings['class_name'] . 'Actions.php'; // load guy class to see hash $handle = @fopen($actorFile, "r"); if ($handle and is_writable($actorFile)) { $line = @fgets($handle); if (preg_match('~\\[STAMP\\] ([a-f0-9]*)~', $line, $matches)) { $hash = $matches[1]; $currentHash = Actions::genHash($modules, $settings); // regenerate guy class when hashes do not match if ($hash != $currentHash) { codecept_debug("Rebuilding {$settings['class_name']}..."); $actionsGenerator = new Actions($settings); @fclose($handle); $generated = $actionsGenerator->produce(); @file_put_contents($actorFile, $generated); return; } } @fclose($handle); } }
public function execute(InputInterface $input, OutputInterface $output) { $suite = $input->getArgument('suite'); $guy = $input->getArgument('guy'); $config = \Codeception\Configuration::config($input->getOption('config')); $dir = \Codeception\Configuration::projectDir() . $config['paths']['tests'] . DIRECTORY_SEPARATOR; if (file_exists($dir . DIRECTORY_SEPARATOR . $suite)) { throw new \Exception("Directory {$suite} already exists."); } if (file_exists($dir . $suite . '.suite.yml')) { throw new \Exception("Suite configuration file '{$suite}.suite.yml' already exists."); } @mkdir($dir . DIRECTORY_SEPARATOR . $suite); // generate bootstrap file_put_contents($dir . DIRECTORY_SEPARATOR . $suite . '/_bootstrap.php', "<?php\n// Here you can initialize variables that will for your tests\n"); if (strpos(strrev($guy), 'yuG') !== 0) { $guy = $guy . 'Guy'; } $guyname = substr($guy, 0, -3); // generate helper file_put_contents(\Codeception\Configuration::projectDir() . $config['paths']['helpers'] . DIRECTORY_SEPARATOR . $guyname . 'Helper.php', "<?php\nnamespace Codeception\\Module;\n\n// here you can define custom functions for {$guy} \n\nclass {$guyname}Helper extends \\Codeception\\Module\n{\n}\n"); $conf = array('class_name' => $guy, 'modules' => array('enabled' => array($guyname . 'Helper'))); file_put_contents($dir . $suite . '.suite.yml', Yaml::dump($conf, 2)); $output->writeln("<info>Suite {$suite} generated</info>"); }
public function execute(InputInterface $input, OutputInterface $output) { $suite = ucfirst($input->getArgument('suite')); $actor = $input->getArgument('actor'); if ($this->containsInvalidCharacters($suite)) { $output->writeln("<error>Suite name '{$suite}' contains invalid characters. ([A-Za-z0-9_]).</error>"); return; } $config = \Codeception\Configuration::config($input->getOption('config')); if (!$actor) { $actor = $suite . $config['actor']; } $config['class_name'] = $actor; $dir = \Codeception\Configuration::testsDir(); if (file_exists($dir . $suite . '.suite.yml')) { throw new \Exception("Suite configuration file '{$suite}.suite.yml' already exists."); } $this->buildPath($dir . $suite . DIRECTORY_SEPARATOR, 'bootstrap.php'); // generate bootstrap $this->save($dir . $suite . DIRECTORY_SEPARATOR . 'bootstrap.php', "<?php\n// Here you can initialize variables that will be available to your tests\n", true); $actorName = $this->removeSuffix($actor, $config['actor']); // generate helper $this->save(\Codeception\Configuration::helpersDir() . $actorName . 'Helper.php', (new Helper($actorName, $config['namespace']))->produce()); $enabledModules = ['Cake\\Codeception\\Helper', 'App\\TestSuite\\Codeception\\' . $actorName . 'Helper']; if ('Unit' === $suite) { array_shift($enabledModules); } $conf = ['class_name' => $actorName . $config['actor'], 'modules' => ['enabled' => $enabledModules]]; $this->save($dir . $suite . '.suite.yml', Yaml::dump($conf, 2)); $output->writeln("<info>Suite {$suite} generated</info>"); }
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>"); }
public function _before(\Codeception\TestCase $test) { require_once \Codeception\Configuration::projectDir() . 'src/includes/autoload.php'; require_once \Codeception\Configuration::projectDir() . 'src/includes/classmap.php'; require_once \Codeception\Configuration::projectDir() . 'src/Vendor/autoload.php'; spl_autoload_register('autoloadlitpi'); include_once \Codeception\Configuration::projectDir() . 'src/libs/smarty/Smarty.class.php'; //Overwrite remoteaddr $_SERVER['REMOTE_ADDR'] = $this->config['remoteaddr']; //INIT REGISTRY VARIABLE - MAIN STORAGE OF APPLICATION $registry = \Litpi\Registry::getInstance(); $request = \Litpi\Request::createFromGlobals(); $response = new \Litpi\Response(); $session = new \Litpi\Session(); $registry->set('request', $request); $registry->set('response', $response); $registry->set('session', $session); require_once \Codeception\Configuration::projectDir() . 'src/includes/conf.php'; require_once \Codeception\Configuration::projectDir() . 'src/includes/config.php'; require_once \Codeception\Configuration::projectDir() . 'src/includes/setting.php'; $registry->set('conf', $conf); $registry->set('setting', $setting); $registry->set('https', PROTOCOL == 'https' ? true : false); require_once \Codeception\Configuration::projectDir() . 'src/includes/permission.php'; $registry->set('groupPermisson', $groupPermisson); require_once \Codeception\Configuration::projectDir() . 'src/includes/rewriterule.php'; require_once \Codeception\Configuration::projectDir() . 'src/includes/startup.php'; $this->registry = $registry; $this->client = new \Codeception\Lib\Connector\LitpiConnectorHelper(); $this->client->setRegistry($this->registry); }
public function setUp() { $this->dispatcher = new Symfony\Component\EventDispatcher\EventDispatcher(); $this->testcase = new \Codeception\TestCase\Cept(); $this->testcase->configDispatcher($this->dispatcher)->configName('mocked test')->configFile(\Codeception\Configuration::dataDir() . 'SimpleCept.php')->initConfig(); \Codeception\SuiteManager::$modules['EmulateModuleHelper']->assertions = 0; }
/** * @inheritdoc */ public function _initialize() { // compute datbase info $match = preg_match("/host=(.*);dbname=(.*)/", env("DB_DSN"), $matches); if (!$match) { return; } $host = $matches[1]; $name = $matches[2] . "_test"; $user = env("DB_USER"); $pass = env("DB_PASS"); // compute dump file $dumpFile = $this->config['dump'] ?: "tests/_data/dump.sql"; $dumpFile = Configuration::projectDir() . $dumpFile; if (!file_exists($dumpFile)) { throw new ModuleException(__CLASS__, "Dump file does not exist [ {$dumpFile} ]"); } // dump $cmd = "mysql -h {$host} -u {$user} -p{$pass} {$name} < {$dumpFile}"; $start = microtime(true); $output = shell_exec($cmd); $end = microtime(true); $diff = round(($end - $start) * 1000, 2); // output debug info $className = get_called_class(); codecept_debug("{$className} - Importing db [ {$name} ] [ {$diff} ms ]"); // check for error if ($output) { throw new ModuleException(__CLASS__, "Failed to import db [ {$cmd} ]"); } }
public function testActions() { $modules = array('EmulateModuleHelper' => new \Codeception\Module\EmulateModuleHelper()); $actions = \Codeception\Configuration::actions($modules); $this->assertArrayHasKey('seeEquals', $actions); $this->assertEquals('EmulateModuleHelper', $actions['seeEquals']); }
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>"); }
public function testCreateInSubpath() { $this->execute(array('suite' => 'shire', 'step' => 'User/Login', '--silent' => true)); $generated = $this->log[0]; $this->assertEquals(\Codeception\Configuration::supportDir() . 'Step/Shire/User/Login.php', $generated['filename']); $this->assertIsValidPhp($this->content); }
protected function buildActorsForConfig($configFile) { $config = $this->getGlobalConfig($configFile); $suites = $this->getSuites($configFile); $path = pathinfo($configFile); $dir = isset($path['dirname']) ? $path['dirname'] : getcwd(); foreach ($config['include'] as $subConfig) { $this->output->writeln("<comment>Included Configuration: {$subConfig}</comment>"); $this->buildActorsForConfig($dir . DIRECTORY_SEPARATOR . $subConfig); } if (!empty($suites)) { $this->output->writeln("<info>Building Actor classes for suites: " . implode(', ', $suites) . '</info>'); } foreach ($suites as $suite) { $settings = $this->getSuiteConfig($suite, $configFile); $actionsGenerator = new ActionsGenerator($settings); $contents = $actionsGenerator->produce(); $actorGenerator = new ActorGenerator($settings); $file = $this->buildPath(Configuration::supportDir() . '_generated', $settings['class_name']) . $this->getClassName($settings['class_name']) . 'Actions.php'; $this->save($file, $contents, true); $this->output->writeln('<info>' . Configuration::config()['namespace'] . '\\' . $actorGenerator->getActorName() . "</info> includes modules: " . implode(', ', $actorGenerator->getModules())); $this->output->writeln(" -> {$settings['class_name']}Actions.php generated successfully. " . $actionsGenerator->getNumMethods() . " methods added"); $contents = $actorGenerator->produce(); $file = $this->buildPath(Configuration::supportDir(), $settings['class_name']) . $this->getClassName($settings['class_name']) . '.php'; if ($this->save($file, $contents)) { $this->output->writeln("{$settings['class_name']}.php created."); } } }
public function __construct() { $this->config = Configuration::config(); $this->logDir = Configuration::outputDir(); // prepare log dir $this->phpUnitOverriders(); parent::__construct(); }
protected function loadConfiguredGroupSettings() { foreach ($this->configuredGroups as $group => $tests) { $this->testsInGroups[$group] = []; if (is_array($tests)) { foreach ($tests as $test) { $file = str_replace(['/', '\\'], [DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR], $test); $this->testsInGroups[$group][] = Configuration::projectDir() . $file; } } elseif (is_file(Configuration::projectDir() . $tests)) { $handle = @fopen(Configuration::projectDir() . $tests, "r"); if ($handle) { while (($test = fgets($handle, 4096)) !== false) { // if the current line is blank then we need to move to the next line // otherwise the current codeception directory becomes part of the group // which causes every single test to run if (trim($test) === '') { continue; } $file = trim(Configuration::projectDir() . $test); $file = str_replace(['/', '\\'], [DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR], $file); $this->testsInGroups[$group][] = $file; } fclose($handle); } } } }
/** * Constructor. * * @param ModuleContainer $container * @param $config */ public function __construct(ModuleContainer $container, $config = null) { $this->config = array_merge(['bootstrap' => 'bootstrap.php', 'application_dir' => 'application', 'modules_dir' => 'modules', 'system_dir' => 'system', 'custom_config_reader' => null], (array) $config); $projectDir = \Codeception\Configuration::projectDir(); if (!defined('EXT')) { define('EXT', '.php'); } if (!defined('DOCROOT')) { define('DOCROOT', realpath($projectDir) . DIRECTORY_SEPARATOR); } if (!defined('APPPATH')) { define('APPPATH', realpath(DOCROOT . $this->config['application_dir']) . DIRECTORY_SEPARATOR); } if (!defined('MODPATH')) { define('MODPATH', realpath(DOCROOT . $this->config['modules_dir']) . DIRECTORY_SEPARATOR); } if (!defined('SYSPATH')) { define('SYSPATH', realpath(DOCROOT . $this->config['system_dir']) . DIRECTORY_SEPARATOR); } if (!defined('KOHANA_START_TIME')) { define('KOHANA_START_TIME', microtime(TRUE)); } if (!defined('KOHANA_START_MEMORY')) { define('KOHANA_START_MEMORY', memory_get_usage()); } if (!defined('API_MODE')) { define('API_MODE', true); } $this->config['bootstrap_file'] = APPPATH . $this->config['bootstrap']; parent::__construct($container); }
public function execute(InputInterface $input, OutputInterface $output) { $suite = $input->getArgument('suite'); $step = $input->getArgument('step'); $config = $this->getSuiteConfig($suite, $input->getOption('config')); $class = $this->getClassName($step); $path = $this->buildPath(Configuration::supportDir() . 'Step' . DIRECTORY_SEPARATOR . ucfirst($suite), $step); $dialog = $this->getHelperSet()->get('question'); $filename = $path . $class . '.php'; $helper = $this->getHelper('question'); $question = new Question("Add action to StepObject class (ENTER to exit): "); $gen = new StepObjectGenerator($config, ucfirst($suite) . '\\' . $step); if (!$input->getOption('silent')) { do { $question = new Question('Add action to StepObject class (ENTER to exit): ', null); $action = $dialog->ask($input, $output, $question); if ($action) { $gen->createAction($action); } } while ($action); } $res = $this->save($filename, $gen->produce()); if (!$res) { $output->writeln("<error>StepObject {$filename} already exists</error>"); exit; } $output->writeln("<info>StepObject was created in {$filename}</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); } }
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>"); }
/** * @return \Symfony\Component\Finder\Finder|\Symfony\Component\Finder\SplFileInfo[] */ private function getBundleTransferSchemas() { $testBundleSchemaDirectory = Configuration::projectDir() . DIRECTORY_SEPARATOR . 'src'; $finder = new Finder(); $finder->files()->in($testBundleSchemaDirectory)->name('*.transfer.xml'); return $finder; }
public function __construct() { $this->config = Configuration::config(); $this->log_dir = Configuration::logDir(); // prepare log dir parent::__construct(); }
public function _initialize() { if ($this->config['dump'] && ($this->config['cleanup'] or $this->config['populate'])) { if (!file_exists(Configuration::projectDir() . $this->config['dump'])) { throw new \Codeception\Exception\ModuleConfig(__CLASS__, "\n File with dump doesn't exist.\n\n Please, check path for dump file: " . $this->config['dump']); } $this->dumpFile = Configuration::projectDir() . $this->config['dump']; $this->isDumpFileEmpty = false; $content = file_get_contents($this->dumpFile); $content = trim(preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $content)); if (!sizeof(explode("\n", $content))) { $this->isDumpFileEmpty = true; } } try { $this->driver = MongoDbDriver::create($this->config['dsn'], $this->config['user'], $this->config['password']); } catch (\MongoConnectionException $e) { throw new \Codeception\Exception\Module(__CLASS__, $e->getMessage() . ' while creating Mongo connection'); } // starting with loading dump if ($this->config['populate']) { $this->cleanup(); $this->loadDump(); $this->populated = true; } }
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"); } }
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"); }
public function execute(InputInterface $input, OutputInterface $output) { $suite = lcfirst($input->getArgument('suite')); $actor = $input->getArgument('actor'); if ($this->containsInvalidCharacters($suite)) { $output->writeln("<error>Suite name '{$suite}' contains invalid characters. ([A-Za-z0-9_]).</error>"); return; } $config = \Codeception\Configuration::config($input->getOption('config')); if (!$actor) { $actor = ucfirst($suite) . $config['actor']; } $config['class_name'] = $actor; $dir = \Codeception\Configuration::testsDir(); if (file_exists($dir . $suite . '.suite.yml')) { throw new \Exception("Suite configuration file '{$suite}.suite.yml' already exists."); } $this->buildPath($dir . $suite . DIRECTORY_SEPARATOR, $config['settings']['bootstrap']); // generate bootstrap $this->save($dir . $suite . DIRECTORY_SEPARATOR . $config['settings']['bootstrap'], "<?php\n// Here you can initialize variables that will be available to your tests\n", true); $actorName = $this->removeSuffix($actor, $config['actor']); $file = $this->buildPath(\Codeception\Configuration::supportDir() . "Helper", "{$actorName}.php") . "{$actorName}.php"; $gen = new Helper($actorName, $config['namespace']); // generate helper $this->save($file, $gen->produce()); $conf = <<<EOF class_name: {{actor}} modules: enabled: - {{helper}} EOF; $this->save($dir . $suite . '.suite.yml', (new Template($conf))->place('actor', $actorName . $config['actor'])->place('helper', $gen->getHelperName())->produce()); $output->writeln("<info>Suite {$suite} generated</info>"); }
protected function pathToGlobalPageObject($config, $class) { $path = $this->buildPath(Configuration::projectDir() . $config['paths']['tests'] . '/_pages/', $class); $filename = $this->completeSuffix($class, 'Page'); $this->introduceAutoloader(Configuration::projectDir() . $config['paths']['tests'] . DIRECTORY_SEPARATOR . $config['settings']['bootstrap'], 'Page', '_pages'); return $path . $filename; }
protected function execute(InputInterface $input, OutputInterface $output) { $this->getGlobalConfig($input->getOption('config')); $output->writeln("<info>Cleaning up " . Configuration::outputDir() . "...</info>"); FileSystem::doEmptyDir(Configuration::outputDir()); $output->writeln("Done"); }
protected function initializeModules() { self::$modules = Configuration::modules($this->settings); self::$actions = Configuration::actions(self::$modules); foreach (self::$modules as $module) { $module->_initialize(); } }
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; }