Skip to content

Commit

Permalink
Merge pull request #20 from ngmy/feature/do-not-load-when-config-is-c…
Browse files Browse the repository at this point in the history
…ached

Do not load when the configuration is cached
  • Loading branch information
antonioribeiro authored May 21, 2020
2 parents 5877c6e + 6c56cad commit 9f2b44c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/package/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions tests/CommonYamlTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PragmaRX\Yaml\Tests;

use App;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use PragmaRX\Yaml\Package\Exceptions\InvalidYamlFile;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9f2b44c

Please sign in to comment.