Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }