diff --git a/src/package/Yaml.php b/src/package/Yaml.php index f7e24bf..6303fe5 100644 --- a/src/package/Yaml.php +++ b/src/package/Yaml.php @@ -2,6 +2,7 @@ namespace PragmaRX\Yaml\Package; +use App; use Illuminate\Support\Collection; use PragmaRX\Yaml\Package\Exceptions\MethodNotFound; use PragmaRX\Yaml\Package\Support\File; @@ -108,6 +109,10 @@ protected function instantiateClass($instance, $property, $class = null, $argume */ public function loadToConfig($path, $configKey) { + if (App::configurationIsCached()) { + return collect(); + } + $loaded = $this->file->isYamlFile($path) ? $this->loadFile($path) : $this->loadFromDirectory($path); diff --git a/tests/CommonYamlTests.php b/tests/CommonYamlTests.php index b59ab12..6faf43e 100644 --- a/tests/CommonYamlTests.php +++ b/tests/CommonYamlTests.php @@ -2,6 +2,7 @@ namespace PragmaRX\Yaml\Tests; +use App; use Illuminate\Support\Arr; use Illuminate\Support\Collection; use PragmaRX\Yaml\Package\Exceptions\InvalidYamlFile; @@ -123,6 +124,15 @@ public function test_method_not_found() $this->yaml->inexistentMethod(); } + public function test_do_not_load_when_configuration_is_cached() + { + App::shouldReceive('configurationIsCached')->andReturn(true); + + $loaded = $this->yaml->loadToConfig(__DIR__.'/stubs/conf/single', 'single'); + + $this->assertEmpty($loaded); + } + public function cleanYamlString($string) { return str_replace(