public static function config($config_file = null) { if (self::$config) { return self::$config; } if ($config_file === null) { $config_file = getcwd() . DIRECTORY_SEPARATOR . 'codeception.yml'; } if (is_dir($config_file)) { $config_file = $config_file . DIRECTORY_SEPARATOR . 'codeception.yml'; } $dir = dirname($config_file); $config = file_exists($config_file) ? Yaml::parse($config_file) : array(); $distConfig = file_exists('codeception.dist.yml') ? Yaml::parse('codeception.dist.yml') : array(); $config = array_merge($distConfig, $config); if (empty($config)) { throw new \Codeception\Exception\Configuration("Configuration file is invalid"); } if (!isset($config['paths'])) { throw new \Codeception\Exception\Configuration('Paths are not defined'); } if (!isset($config['paths']['tests'])) { throw new \Codeception\Exception\Configuration('Tests directory path is not defined'); } if (!isset($config['paths']['data'])) { throw new \Codeception\Exception\Configuration('Data path is not defined'); } if (!isset($config['paths']['log'])) { throw new \Codeception\Exception\Configuration('Log path is not defined'); } if (isset($config['paths']['helpers'])) { // Helpers $helpers = Finder::create()->files()->name('*Helper.php')->in($dir . DIRECTORY_SEPARATOR . $config['paths']['helpers']); foreach ($helpers as $helper) { include_once $helper; } } if (!isset($config['suites'])) { $suites = Finder::create()->files()->name('*.suite.yml')->in($dir . DIRECTORY_SEPARATOR . $config['paths']['tests'])->depth('< 1'); $config['suites'] = array(); foreach ($suites as $suite) { preg_match('~(.*?)(\\.suite|\\.suite\\.dist)\\.yml~', $suite->getFilename(), $matches); $config['suites'][] = $matches[1]; } } ini_set('memory_limit', isset($config['settings']['memory_limit']) ? $config['settings']['memory_limit'] : '1024M'); self::$suites = $config['suites']; self::$config = $config; self::$dataDir = $config['paths']['data']; self::$logDir = $config['paths']['log']; self::$helpersDir = $config['paths']['helpers']; self::$dir = $dir; return $config; }
public static function config($configFile = null) { if (!$configFile && self::$config) { return self::$config; } if (self::$config && self::$lock) { return self::$config; } if ($configFile === null) { $configFile = getcwd() . DIRECTORY_SEPARATOR . 'codeception.yml'; } if (is_dir($configFile)) { $configFile = $configFile . DIRECTORY_SEPARATOR . 'codeception.yml'; } $dir = dirname($configFile); $configDistFile = $dir . DIRECTORY_SEPARATOR . 'codeception.dist.yml'; if (!(file_exists($configDistFile) || file_exists($configFile))) { throw new ConfigurationException("Configuration file could not be found"); } $config = self::loadConfigFile($configDistFile, self::$defaultConfig); $config = self::loadConfigFile($configFile, $config); if ($config == self::$defaultConfig) { throw new ConfigurationException("Configuration file is invalid"); } self::$dir = $dir; self::$config = $config; if (!isset($config['paths']['log'])) { throw new ConfigurationException('Log path is not defined by key "paths: log"'); } self::$logDir = $config['paths']['log']; // config without tests, for inclusion of other configs if (count($config['include']) and !isset($config['paths']['tests'])) { return $config; } if (!isset($config['paths']['tests'])) { throw new ConfigurationException('Tests directory is not defined in Codeception config by key "paths: tests:"'); } if (!isset($config['paths']['data'])) { throw new ConfigurationException('Data path is not defined Codeception config by key "paths: data"'); } if (!isset($config['paths']['helpers'])) { throw new ConfigurationException('Helpers path is not defined by key "paths: helpers"'); } self::$dataDir = $config['paths']['data']; self::$helpersDir = $config['paths']['helpers']; self::$testsDir = $config['paths']['tests']; self::loadBootstrap($config['settings']['bootstrap']); self::autoloadHelpers(); self::loadSuites(); return $config; }
/** * Loads global config file which is `codeception.yml` by default. * When config is already loaded - returns it. * * @param null $configFile * @return array * @throws Exception\ConfigurationException */ public static function config($configFile = null) { if (!$configFile && self::$config) { return self::$config; } if (self::$config && self::$lock) { return self::$config; } if ($configFile === null) { $configFile = getcwd() . DIRECTORY_SEPARATOR . 'codeception.yml'; } if (is_dir($configFile)) { $configFile = $configFile . DIRECTORY_SEPARATOR . 'codeception.yml'; } $dir = realpath(dirname($configFile)); $configDistFile = $dir . DIRECTORY_SEPARATOR . 'codeception.dist.yml'; if (!(file_exists($configDistFile) || file_exists($configFile))) { throw new ConfigurationException("Configuration file could not be found.\nRun `bootstrap` to initialize Codeception."); } $config = self::loadConfigFile($configDistFile, self::$defaultConfig); $config = self::loadConfigFile($configFile, $config); if ($config == self::$defaultConfig) { throw new ConfigurationException("Configuration file is invalid"); } self::$dir = $dir; self::$config = $config; if (!isset($config['paths']['log'])) { throw new ConfigurationException('Log path is not defined by key "paths: log"'); } self::$logDir = $config['paths']['log']; // fill up includes with wildcard expansions $config['include'] = self::expandWildcardedIncludes($config['include']); // config without tests, for inclusion of other configs if (count($config['include']) and !isset($config['paths']['tests'])) { return $config; } if (!isset($config['paths']['tests'])) { throw new ConfigurationException('Tests directory is not defined in Codeception config by key "paths: tests:"'); } if (!isset($config['paths']['data'])) { throw new ConfigurationException('Data path is not defined Codeception config by key "paths: data"'); } // compatibility with 1.x, 2.0 if (!isset($config['paths']['support']) and isset($config['paths']['helpers'])) { $config['paths']['support'] = $config['paths']['helpers']; } if (!isset($config['paths']['support'])) { throw new ConfigurationException('Helpers path is not defined by key "paths: support"'); } self::$dataDir = $config['paths']['data']; self::$supportDir = $config['paths']['support']; self::$testsDir = $config['paths']['tests']; if (isset($config['paths']['envs'])) { self::$envsDir = $config['paths']['envs']; } self::loadBootstrap($config['settings']['bootstrap']); self::autoloadHelpers(); self::loadSuites(); return $config; }
/** * Loads global config file which is `codeception.yml` by default. * When config is already loaded - returns it. * * @param null $configFile * @return array * @throws Exception\ConfigurationException */ public static function config($configFile = null) { if (!$configFile && self::$config) { return self::$config; } if (self::$config && self::$lock) { return self::$config; } if ($configFile === null) { $configFile = getcwd() . DIRECTORY_SEPARATOR . 'codeception.yml'; } if (is_dir($configFile)) { $configFile = $configFile . DIRECTORY_SEPARATOR . 'codeception.yml'; } $dir = realpath(dirname($configFile)); self::$dir = $dir; $configDistFile = $dir . DIRECTORY_SEPARATOR . 'codeception.dist.yml'; if (!(file_exists($configDistFile) || file_exists($configFile))) { throw new ConfigurationException("Configuration file could not be found.\nRun `bootstrap` to initialize Codeception.", 404); } // Preload config to retrieve params such that they are applied to codeception config file below $tempConfig = self::$defaultConfig; $distConfigContents = ""; if (file_exists($configDistFile)) { $distConfigContents = file_get_contents($configDistFile); $tempConfig = self::mergeConfigs($tempConfig, self::getConfFromContents($distConfigContents)); } $configContents = ""; if (file_exists($configFile)) { $configContents = file_get_contents($configFile); $tempConfig = self::mergeConfigs($tempConfig, self::getConfFromContents($configContents)); } self::prepareParams($tempConfig); $config = self::mergeConfigs(self::$defaultConfig, self::getConfFromContents($distConfigContents)); $config = self::mergeConfigs($config, self::getConfFromContents($configContents)); if ($config == self::$defaultConfig) { throw new ConfigurationException("Configuration file is invalid"); } self::$config = $config; if (!isset($config['paths']['log'])) { throw new ConfigurationException('Log path is not defined by key "paths: log"'); } self::$logDir = $config['paths']['log']; // fill up includes with wildcard expansions $config['include'] = self::expandWildcardedIncludes($config['include']); // config without tests, for inclusion of other configs if (count($config['include']) and !isset($config['paths']['tests'])) { return self::$config = $config; } if (!isset($config['paths']['tests'])) { throw new ConfigurationException('Tests directory is not defined in Codeception config by key "paths: tests:"'); } if (!isset($config['paths']['data'])) { throw new ConfigurationException('Data path is not defined Codeception config by key "paths: data"'); } // compatibility with 1.x, 2.0 if (!isset($config['paths']['support']) and isset($config['paths']['helpers'])) { $config['paths']['support'] = $config['paths']['helpers']; } if (!isset($config['paths']['support'])) { throw new ConfigurationException('Helpers path is not defined by key "paths: support"'); } self::$dataDir = $config['paths']['data']; self::$supportDir = $config['paths']['support']; self::$testsDir = $config['paths']['tests']; if (isset($config['paths']['envs'])) { self::$envsDir = $config['paths']['envs']; } Autoload::addNamespace(self::$config['namespace'], self::supportDir()); self::loadBootstrap($config['settings']['bootstrap']); self::loadSuites(); return $config; }