function it_can_do_merging(ConfigTree $anotherConfigTree) { $otherConfigAsArray = ['node1' => ['node2' => 'value-that-should-override-other', 'node4' => 'value-that-should-be-added']]; $expectedMergeResult = ['node1' => ['node2' => 'value-that-should-override-other', 'node3' => 'value', 'node4' => 'value-that-should-be-added', 'node5' => ['node6' => 'value']]]; $anotherConfigTree->toArray()->willReturn($otherConfigAsArray); $this->withAnotherConfigTreeMergedIn($anotherConfigTree)->shouldBeLike(new ConfigTree($expectedMergeResult)); }
/** * @throws FileFormatNotParsable * @throws FileNotReadable * * @param string $pathToFile */ private function addSettingsFromPath($pathToFile) { $arrayableFile = $this->arrayableFileFactory->getArrayableFileFromPath($pathToFile); $fileContentsAsArray = $arrayableFile->toArray(); $config = new ConfigTree($fileContentsAsArray); $this->configTreeToReturn = $this->configTreeToReturn->withAnotherConfigTreeMergedIn($config); }
/** * @param ConfigTree $config * @return Route[] */ public function buildRoutesFromConfig(ConfigTree $config) { $configArray = $config->toArray(); $routes = []; foreach ($configArray as $routeName => $routeDetails) { $routes[] = new Route($routeName, $routeDetails['route'], $routeDetails['method'], $routeDetails['controller-service-id'], $routeDetails['action-method-name']); } return $routes; }
/** * In $configC = $configA->withAnotherConfigTreeMergedIn($configB), duplicate settings in $configB override $configA * * @param ConfigTree $anotherConfigTree * @return ConfigTree */ public function withAnotherConfigTreeMergedIn(ConfigTree $anotherConfigTree) { $thisAsArray = $this->rawConfigArray; $otherAsArray = $anotherConfigTree->toArray(); return new ConfigTree(array_replace_recursive($thisAsArray, $otherAsArray)); }
/** * @Then I should get a Config Tree object which has been merged correctly */ public function iShouldGetAConfigTreeObjectWhichHasBeenMergedCorrectly() { $expectedResult = ['parameters' => ['node1' => ['node2' => ['node3' => 'value3.2', 'node4' => 'value4.1']]]]; PHPUnit_Framework_Assert::assertEquals($expectedResult, $this->configTree->toArray()); }