@@ -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