Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 /**
  * Adds parameters to config
  *
  * @param array $config
  * @return array
  */
 public static function append(array $config = [])
 {
     return self::$config = self::mergeConfigs(self::$config, $config);
 }
Exemplo n.º 3
0
 protected static function loadSuites()
 {
     $suites = Finder::create()->files()->name('*.{suite,suite.dist}.yml')->in(self::$dir . DIRECTORY_SEPARATOR . self::$testsDir)->depth('< 1');
     self::$suites = array();
     foreach ($suites as $suite) {
         preg_match('~(.*?)(\\.suite|\\.suite\\.dist)\\.yml~', $suite->getFilename(), $matches);
         self::$suites[$matches[1]] = $matches[1];
     }
 }
Exemplo n.º 4
0
 private static function prepareParams($settings)
 {
     self::$params = [];
     foreach ($settings['params'] as $paramStorage) {
         if (is_array($paramStorage)) {
             static::$params = array_merge(self::$params, $paramStorage);
             continue;
         }
         // environment
         if ($paramStorage === 'env' || $paramStorage === 'environment') {
             static::$params = array_merge(self::$params, $_SERVER);
             continue;
         }
         $paramsFile = realpath(self::$dir . '/' . $paramStorage);
         if (!file_exists($paramsFile)) {
             throw new ConfigurationException("Params file {$paramsFile} not found");
         }
         // yaml parameters
         if (preg_match('~\\.yml$~', $paramStorage)) {
             $params = Yaml::parse(file_get_contents($paramsFile));
             if (isset($params['parameters'])) {
                 // Symfony style
                 $params = $params['parameters'];
             }
             static::$params = array_merge(self::$params, $params);
             continue;
         }
         // .env and ini files
         if (preg_match('~(\\.ini$|\\.env(\\.|$))~', $paramStorage)) {
             $params = parse_ini_file($paramsFile);
             static::$params = array_merge(self::$params, $params);
             continue;
         }
         throw new ConfigurationException("Params can't be loaded from `{$paramStorage}`.");
     }
 }