Skip to content

Commit

Permalink
[BUGFIX] Load variables from file with getByPath (#816)
Browse files Browse the repository at this point in the history
Currently, JSONVariableProvider doesn’t load the JSON file if
getByPath() is used, in contrast to get(), getAll(), or getAllIdentifiers().

Co-authored-by: Christian Kuhn <[email protected]>
  • Loading branch information
s2b and lolli42 authored Oct 30, 2023
1 parent 6b935df commit aa17b62
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Core/Variables/JSONVariableProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ public function get($identifier)
return parent::get($identifier);
}

/**
* @param string $path
* @return mixed
*/
public function getByPath($path)
{
$this->load();
return parent::getByPath($path);
}

/**
* @return array
*/
Expand Down
40 changes: 40 additions & 0 deletions tests/Unit/Core/Variables/JSONVariableProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,44 @@ public function provideVariables(string $input, array $expected): void
self::assertEquals($value, $provider->get($key));
}
}

/**
* @test
*/
public function getAllLoadJsonFile(): void
{
$provider = new JSONVariableProvider();
$provider->setSource(__DIR__ . '/Fixtures/test.json');
self::assertEquals(['foo' => 'bar'], $provider->getAll());
}

/**
* @test
*/
public function getAllIdentifiersLoadJsonFile(): void
{
$provider = new JSONVariableProvider();
$provider->setSource(__DIR__ . '/Fixtures/test.json');
self::assertEquals(['foo'], $provider->getAllIdentifiers());
}

/**
* @test
*/
public function getLoadJsonFile(): void
{
$provider = new JSONVariableProvider();
$provider->setSource(__DIR__ . '/Fixtures/test.json');
self::assertEquals('bar', $provider->get('foo'));
}

/**
* @test
*/
public function getByPathLoadJsonFile(): void
{
$provider = new JSONVariableProvider();
$provider->setSource(__DIR__ . '/Fixtures/test.json');
self::assertEquals('bar', $provider->getByPath('foo'));
}
}

0 comments on commit aa17b62

Please sign in to comment.