Пример #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;
 }
Пример #2
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 = [];
     /** @var SplFileInfo $suite */
     foreach ($suites as $suite) {
         preg_match('~(.*?)(\\.suite|\\.suite\\.dist)\\.yml~', $suite->getFilename(), $matches);
         self::$suites[$matches[1]] = $matches[1];
     }
 }