Skip to content

Commit 530117e

Browse files
ACPT-1599:
Updating unit tests so that we can verify that the config files don't get reloaded each time we get a key that doesn't exist in config. Also adding test to confirm that we can reload config after reset to load previously unset config key.
1 parent fe1345b commit 530117e

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfigTest.php

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,11 @@ public function testEnvVariablesSubstitution(): void
306306
* @throws FileSystemException
307307
* @throws RuntimeException
308308
*/
309-
public function testReloadDataOnMissingConfig(): void
309+
public function testShouldntReloadDataOnMissingConfig(): void
310310
{
311-
$this->readerMock->expects($this->exactly(2))
311+
$this->readerMock->expects($this->once())
312312
->method('load')
313-
->willReturnOnConsecutiveCalls(
314-
['db' => ['connection' => ['default' => ['host' => 'localhost']]]],
315-
[],
316-
[]
317-
);
313+
->willReturn(['db' => ['connection' => ['default' => ['host' => 'localhost']]]]);
318314
$connectionConfig1 = $this->deploymentConfig->get(
319315
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS . '/' . 'default'
320316
);
@@ -330,4 +326,39 @@ public function testReloadDataOnMissingConfig(): void
330326
$result3 = $this->deploymentConfig->get('missing/key');
331327
$this->assertNull($result3);
332328
}
329+
330+
/**
331+
* @return void
332+
*/
333+
public function testShouldntLoadMultipleTimes() : void
334+
{
335+
$this->readerMock->expects($this->once())->method('load')
336+
->willReturn(['a' => ['a' => ['a' => 1]]]);
337+
$this->deploymentConfig->get('a/a/a');
338+
$this->deploymentConfig->get('a/a/b');
339+
$this->deploymentConfig->get('a/a/c');
340+
$this->deploymentConfig->get('a/b/a');
341+
$this->deploymentConfig->get('a/b/b');
342+
$this->deploymentConfig->get('a/b/c');
343+
}
344+
345+
/**
346+
* @return void
347+
*/
348+
public function testShouldReloadPreviouslyUnsetKeysAfterReset() : void
349+
{
350+
$testValue = 42;
351+
$loadReturn = ['a' => ['a' => ['a' => 1]]];
352+
$this->readerMock->expects($this->any())->method('load')
353+
->will($this->returnCallback(function() use (&$loadReturn) { return $loadReturn;}));
354+
$this->deploymentConfig->get('a/a/a');
355+
$abcReturnValue1 = $this->deploymentConfig->get('a/b/c');
356+
$this->assertNull($abcReturnValue1); // first try, it isn't set yet.
357+
$loadReturn = ['a' => ['a' => ['a' => 1], 'b' => ['c' => $testValue]]];
358+
$this->deploymentConfig->resetData();
359+
$this->deploymentConfig->get('a/a/a');
360+
$abcReturnValue2 = $this->deploymentConfig->get('a/b/c');
361+
$this->assertEquals($testValue, $abcReturnValue2); // second try, it should load the newly set value
362+
}
363+
333364
}

0 commit comments

Comments
 (0)