Восстановлен запуск тестов

Загрузчик конфигов выделен в отдельный класс
authserverHost выделена в params
Исправлены некоторые common.unit тесты, т.к. наследовались не от того базового класса
This commit is contained in:
ErickSkrauch
2016-09-19 01:01:19 +03:00
parent 54485b2271
commit df6d319187
35 changed files with 147 additions and 190 deletions

View File

@@ -1 +1 @@
main-local.php
config-local.php

View File

@@ -0,0 +1,65 @@
<?php
namespace common\config;
use yii\helpers\ArrayHelper;
class ConfigLoader {
/*
* TODO: В PHP 7.1 следует сделать её protected
*/
const ROOT_PATH = __DIR__ . '/../..';
private $application;
public function __construct(string $application) {
$this->application = $application;
}
public function getEnvironment() : string {
return YII_ENV;
}
public function getConfig() : array {
$toMerge = [
require __DIR__ . '/config.php',
];
// Общие окружение-зависимые настройки
$path = __DIR__ . '/config-' . YII_ENV . '.php';
if (file_exists($path)) {
$toMerge[] = require $path;
}
// Общие локальные настройки
$path = __DIR__ . '/config-local.php';
if (file_exists($path)) {
$toMerge[] = require $path;
}
// Настройки конкретного приложения
$path = self::ROOT_PATH . '/' . $this->application . '/config/config.php';
if (file_exists($path)) {
$toMerge[] = require $path;
}
// Настройки конкретного приложения для действующего окружения
$path = self::ROOT_PATH . '/' . $this->application . '/config/main-' . YII_ENV . '.php';
if (file_exists($path)) {
$toMerge[] = require $path;
}
// Локальные настройки конкретного приложения
$path = self::ROOT_PATH . '/' . $this->application . '/config/config-local.php';
if (file_exists($path)) {
$toMerge[] = require $path;
}
return ArrayHelper::merge(...$toMerge);
}
public static function load(string $application) : array {
return (new static($application))->getConfig();
}
}

View File

@@ -1,43 +0,0 @@
<?php
use yii\helpers\ArrayHelper;
$rootPath = __DIR__ . '/../..';
$toMerge = [
require __DIR__ . '/main.php',
];
// Общие окружение-зависимые настройки
$path = __DIR__ . '/common-' . YII_ENV . '.php';
if (file_exists($path)) {
$toMerge[] = require $path;
}
// Общие локальные настройки
$path = __DIR__ . '/common-local.php';
if (file_exists($path)) {
$toMerge[] = require $path;
}
// Настройки конкретного приложения
$path = $rootPath . '/' . YII_APPLICATION_MODULE . '/config/main.php';
if (file_exists($path)) {
$toMerge[] = require $path;
}
// Настройки конкретного приложения для действующего окружения
$path = $rootPath . '/' . YII_APPLICATION_MODULE . '/config/main-' . YII_ENV . '.php';
if (file_exists($path)) {
$toMerge[] = require $path;
}
// Локальные настройки конкретного приложения
$path = $rootPath . '/' . YII_APPLICATION_MODULE . '/config/main-local.php';
if (file_exists($path)) {
$toMerge[] = require $path;
}
// не оставляем глобальных переменных, ну кроме $toMerge, хех
unset($path, $rootPath);
return ArrayHelper::merge(...$toMerge);