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 _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); }
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 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); } } } }
/** * @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 _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; } }
/** * 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); }
/** * @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 _initialize() { $cwd = getcwd(); chdir(Configuration::projectDir()); $this->container = (require Configuration::projectDir() . $this->config['container']); chdir($cwd); $this->application = $this->container->get('Zend\\Expressive\\Application'); $this->initResponseCollector(); }
public function _before(\Codeception\TestCase $test) { $this->client = new \Codeception\Lib\Connector\Yii2(); $this->client->configFile = \Codeception\Configuration::projectDir() . $this->config['configFile']; $this->app = $this->client->startApp(); if ($this->config['cleanup'] and isset($this->app->db)) { $this->transaction = $this->app->db->beginTransaction(); } }
public function _initialize() { require Configuration::projectDir() . 'init_autoloader.php'; $this->applicationConfig = (require Configuration::projectDir() . $this->config['config']); if (isset($applicationConfig['module_listener_options']['config_cache_enabled'])) { $applicationConfig['module_listener_options']['config_cache_enabled'] = false; } Console::overrideIsConsole(false); }
/** * Constructor. * * @param ModuleContainer $container * @param null $config */ public function __construct(ModuleContainer $container, $config = null) { $this->config = array_merge(['cleanup' => true, 'unit' => true, 'environment' => 'testing', 'start' => 'bootstrap' . DIRECTORY_SEPARATOR . 'start.php', 'root' => '', 'filters' => false], (array) $config); $projectDir = explode('workbench', Configuration::projectDir())[0]; $projectDir .= $this->config['root']; $this->config['project_dir'] = $projectDir; $this->config['start_file'] = $projectDir . $this->config['start']; parent::__construct($container, null); }
/** * Constructor. * * @param ModuleContainer $container * @param array|null $config */ public function __construct(ModuleContainer $container, $config = null) { $this->config = array_merge(['cleanup' => true, 'environment_file' => '.env', 'bootstrap' => 'bootstrap' . DIRECTORY_SEPARATOR . 'app.php', 'root' => '', 'packages' => 'workbench', 'disable_middleware' => false, 'disable_events' => false], (array) $config); $projectDir = explode($this->config['packages'], \Codeception\Configuration::projectDir())[0]; $projectDir .= $this->config['root']; $this->config['project_dir'] = $projectDir; $this->config['bootstrap_file'] = $projectDir . $this->config['bootstrap']; parent::__construct($container); }
/** * Constructor. * * @param $config */ public function __construct($config = null) { $this->config = array_merge(array('cleanup' => true, 'environment_file' => '.env', 'bootstrap' => 'bootstrap' . DIRECTORY_SEPARATOR . 'app.php', 'root' => '', 'packages' => 'workbench'), (array) $config); $projectDir = explode($this->config['packages'], \Codeception\Configuration::projectDir())[0]; $projectDir .= $this->config['root']; $this->config['project_dir'] = $projectDir; $this->config['bootstrap_file'] = $projectDir . $this->config['bootstrap']; parent::__construct(); }
public function _before(TestCase $test) { $index = \Codeception\Configuration::projectDir() . $this->config['index']; $this->client = new UniversalRunkitConnector(); $this->client->setIndex($index); $this->client->setEnvModifier(function ($sandbox) use($index) { $sandbox->eval('function is_cli() { return false; }'); $sandbox->chdir(dirname($index)); }); }
public function __construct($dsn, $user, $password) { $filename = substr($dsn, 7); if ($filename === ':memory:') { throw new ModuleException(__CLASS__, ':memory: database is not supported'); } $this->filename = Configuration::projectDir() . $filename; $this->dsn = 'sqlite:' . $this->filename; parent::__construct($this->dsn, $user, $password); }
public function _initialize() { require Configuration::projectDir() . 'init_autoloader.php'; $this->applicationConfig = (require Configuration::projectDir() . $this->config['config']); if (isset($this->applicationConfig['module_listener_options']['config_cache_enabled'])) { $this->applicationConfig['module_listener_options']['config_cache_enabled'] = false; } Console::overrideIsConsole(false); //grabServiceFromContainer may need client in beforeClass hooks of modules or helpers $this->client = new ZF2Connector(); $this->client->setApplicationConfig($this->applicationConfig); }
/** * Class constructor. * * @param array $config * @param array $options * @param PhireMockProcess $process optional PhiremockProcess object */ public function __construct(array $config, array $options, PhiremockProcess $process = null) { $this->config['bin_path'] = Config::projectDir() . '../vendor/bin/phiremock'; $this->config['logs_path'] = Config::logDir(); parent::__construct($config, $options); $this->initProcess($process); list($ip, $port) = explode(':', $this->config['listen']); $this->process->start($ip, $port, $this->config['bin_path'], $this->config['logs_path'], $this->config['debug']); if ($this->config['startDelay']) { sleep($this->config['startDelay']); } }
public function _before(\Codeception\TestCase $test) { $applicationConfig = (require \Codeception\Configuration::projectDir() . $this->config['config']); if (isset($applicationConfig['module_listener_options']['config_cache_enabled'])) { $applicationConfig['module_listener_options']['config_cache_enabled'] = false; } Console::overrideIsConsole(false); $this->application = Application::init($applicationConfig); $events = $this->application->getEventManager(); $events->detach($this->application->getServiceManager()->get('SendResponseListener')); $this->client->setApplication($this->application); }
public function execute(InputInterface $input, OutputInterface $output) { $output->writeln(\Codeception\Codecept::versionString() . "\nPowered by " . \PHPUnit_Runner_Version::getVersionString()); $options = $input->getOptions(); if ($options['debug']) { $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); } $options['verbosity'] = $output->getVerbosity(); if (!extension_loaded('curl')) { throw new \Exception("Codeception requires CURL extension installed to make tests run\n" . "If you are not sure, how to install CURL, pls refer to StackOverflow\n\n" . "Notice: PHP for Apache/Nginx and CLI can have different php.ini files.\n" . "Please make sure that your PHP you run from console has CURL enabled."); } $config = Configuration::config($options['config']); $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 ($options['group']) { $output->writeln(sprintf("[Groups] <info>%s</info> ", implode(', ', $options['group']))); } if ($input->getArgument('test')) { $options['steps'] = true; } if ($test) { $filter = $this->matchFilteredTestName($test); $options['filter'] = $filter; } $this->codecept = new \Codeception\Codecept((array) $options); if ($suite and $test) { $this->codecept->run($suite, $test); } if (!$test) { $suites = $suite ? explode(',', $suite) : Configuration::suites(); $current_dir = Configuration::projectDir(); $executed = $this->runSuites($suites, $options['skip']); foreach ($config['include'] as $included_config_file) { Configuration::config($full_path = $current_dir . $included_config_file); $namespace = $this->currentNamespace(); $output->writeln("\n<fg=white;bg=magenta>\n[{$namespace}]: tests from {$full_path}\n</fg=white;bg=magenta>"); $suites = $suite ? explode(',', $suite) : Configuration::suites(); $executed += $this->runSuites($suites, $options['skip']); } if (!$executed) { throw new \RuntimeException(sprintf("Suite '%s' could not be found", implode(', ', $suites))); } } $this->codecept->printResult(); if (!$input->getOption('no-exit')) { if ($this->codecept->getResult()->failureCount() or $this->codecept->getResult()->errorCount()) { exit(1); } } }
/** * Drupal8Module constructor. */ public function __construct(ModuleContainer $container, $config = null) { $this->config = array_merge(['drupal_root' => Configuration::projectDir() . 'web', 'site_path' => 'sites/test', 'create_users' => true, 'destroy_users' => true, 'test_user_pass' => 'test'], (array) $config); // Bootstrap a bare minimum Kernel so we can interact with Drupal. $autoloader = (require $this->config['drupal_root'] . '/autoload.php'); $kernel = new TestDrupalKernel('prod', $autoloader, $this->config['drupal_root']); $kernel->bootTestEnvironment($this->config['site_path']); // Allow for setting some basic info output. $this->output = new ConsoleOutput(); // Get our role definitions as we use them a lot. $this->roles = Role::loadMultiple(); parent::__construct($container); }
public function testOneFileWithHtml() { $this->config['path'] = 'tests/data/claypit/tests/skipped/'; $this->config['class_name'] = 'SkipGuy'; $this->execute(array('suite' => 'skipped', '--single-file' => true, '--format' => 'html')); $this->assertEquals(\Codeception\Configuration::projectDir() . 'tests/data/scenarios/skipped.html', $this->filename); $this->assertContains('<h3>I WANT TO MAKE IT INCOMPLETE</h3>', $this->content); $this->assertContains('<h3>I WANT TO SKIP IT</h3>', $this->content); $this->assertContains('<body><h3>', $this->content); $this->assertContains('</body></html>', $this->content); $this->assertContains('* Skip_Me rendered', $this->output); $this->assertContains('* Incomplete_Me rendered', $this->output); }
public function _before(TestCase $test) { $this->client = new Yii2Connector(); $this->client->configFile = Configuration::projectDir() . $this->config['configFile']; $mainConfig = Configuration::config()['config']; if (isset($mainConfig['test_entry_url'])) { $this->client->setServerParameter('HTTPS', parse_url($mainConfig['test_entry_url'], PHP_URL_SCHEME) === 'https'); } $this->app = $this->client->startApp(); if ($this->config['cleanup'] && isset($this->app->db)) { $this->transaction = $this->app->db->beginTransaction(); } }
public function _initialize() { $projectDir = \Codeception\Configuration::projectDir(); require $projectDir . '/vendor/autoload.php'; \Illuminate\Support\ClassLoader::register(); if (is_dir($workbench = $projectDir . 'workbench')) { \Illuminate\Workbench\Starter::start($workbench); } $unitTesting = true; $testEnvironment = 'testing'; $app = (require $projectDir . 'bootstrap/start.php'); $this->kernel = $app; $this->revertErrorHandler(); }
public function _before(TestCase $test) { $this->app = (require Configuration::projectDir() . $this->config['app']); // if $app is not returned but exists if (isset($app)) { $this->app = $app; } if (!isset($this->app)) { throw new ModuleConfigException(__CLASS__, "\$app instance was not received from bootstrap file"); } // some silex apps (like bolt) may rely on global $app variable $GLOBALS['app'] = $this->app; $this->client = new \Symfony\Component\HttpKernel\Client($this->app); }
public function testBasic() { $this->execute(array('suite' => 'shire', 'actor' => 'Hobbit')); $this->assertEquals(\Codeception\Configuration::projectDir() . 'tests/shire.suite.yml', $this->filename); $conf = \Symfony\Component\Yaml\Yaml::parse($this->content); $this->assertEquals('HobbitGuy', $conf['class_name']); $this->assertContains('HobbitHelper', $conf['modules']['enabled']); $this->assertContains('Suite shire generated', $this->output); $helper = $this->log[1]; $this->assertEquals(\Codeception\Configuration::helpersDir() . 'HobbitHelper.php', $helper['filename']); $this->assertContains('class HobbitHelper extends \\Codeception\\Module', $helper['content']); $bootstrap = $this->log[0]; $this->assertEquals(\Codeception\Configuration::projectDir() . 'tests/shire/_bootstrap.php', $bootstrap['filename']); }
protected function updateConfigs() { $config_file = \Codeception\Configuration::projectDir() . 'codeception.dist.yml'; if (!file_exists($config_file)) { $config_file = \Codeception\Configuration::projectDir() . 'codeception.yml'; if (!file_exists($config_file)) { throw new \RuntimeException("Config file {$config_file} does not exists"); } } $config_body = file_get_contents($config_file); $prepend_line = "namespace: {$this->namespace}\n"; $config_body = $prepend_line . $config_body; $this->save($config_file, $config_body, true); }
public function _before(\Codeception\TestCase $test) { $this->client = new \Codeception\Lib\Connector\Yii2(); $this->client->configFile = \Codeception\Configuration::projectDir() . $this->config['configFile']; $mainConfig = \Codeception\Configuration::config(); if (isset($mainConfig['config']) && isset($mainConfig['config']['test_entry_url'])) { $this->client->setServerParameter('HTTP_HOST', (string) parse_url($mainConfig['config']['test_entry_url'], PHP_URL_HOST)); $this->client->setServerParameter('HTTPS', (string) parse_url($mainConfig['config']['test_entry_url'], PHP_URL_SCHEME) === 'https'); } $this->app = $this->client->startApp(); if ($this->config['cleanup'] and isset($this->app->db)) { $this->transaction = $this->app->db->beginTransaction(); } }
/** * @codeCoverageIgnore * @ignore Codeception specific */ public function _initialize() { if (isset($this->config['StrictHostKeyChecking'])) { static::$strictHostKeyChecking = (bool) $this->config['StrictHostKeyChecking']; } if (isset($this->config['KnownHostsFile'])) { static::$knownHostsFile = $this->config['KnownHostsFile']; } elseif (static::$strictHostKeyChecking) { // default KnownHostsFile if StrictHostKeyChecking enabled static::$knownHostsFile = Configuration::projectDir() . 'known_hosts'; } // check that a KnownHostsFile exists if StrictHostKeyChecking enabled if (static::$strictHostKeyChecking && !file_exists(static::$knownHostsFile)) { throw new ModuleConfigException(__CLASS__, 'KnownHostsFile "' . static::$knownHostsFile . '" not found'); } }
public function testBasic() { $this->execute(array('namespace' => 'MiddleEarth', '--force' => true)); $this->assertContains('adds namespaces to your Helper and Guy classes and Cepts', $this->output); $config = $this->log[0]; $this->assertContains('Config file updated', $this->output); $this->assertContains('namespace: MiddleEarth', $config['content']); $this->assertEquals(\Codeception\Configuration::projectDir() . 'codeception.yml', (string) $config['filename']); $helper = $this->log[1]; $this->assertContains('namespace MiddleEarth\\Codeception\\Module', $helper['content']); $this->assertRegExp('~' . \Codeception\Configuration::helpersDir() . '.*?Helper~', (string) $helper['filename']); // log[2] is helper, log[3] ... are helpers too $cept = $this->log[7]; $this->assertRegExp('~<?php use MiddleEarth\\\\.*Guy~', $cept['content']); $this->assertIsValidPhp($cept['content']); }