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
 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;
 }
Exemplo n.º 3
0
 /**
  * Adds parameters to config
  *
  * @param array $config
  * @return array
  */
 public static function append(array $config = [])
 {
     return self::$config = self::mergeConfigs(self::$config, $config);
 }