/** * @return Route[] */ public function getRoutesFromFile(string $path) : array { $fileContentsAsArray = $this->configFileParser->parseConfigFile($path); $routes = []; foreach ($fileContentsAsArray['routes'] as $name => $routeArray) { $routes[] = new Route($name, $routeArray); } return $routes; }
/** * @dataProvider provideFilenames * * @param string $filename * @param string $errorMessage */ public function testReadingFileContents($filename, $errorMessage) { // ARRANGE $configFileParser = new ConfigFileParser(); $expectedArray = ['node1' => ['node2' => 'value']]; // ACT $arrayReadFromFile = $configFileParser->parseConfigFile(TEST_DIR . '/fixtures/file_formats/' . $filename); // ASSERT $this->assertEquals($expectedArray, $arrayReadFromFile, $errorMessage); }
function it_can_build_route_objects(ConfigFileParser $configFileParser) { $configFileParser->parseConfigFile('routing.php')->willReturn(['routes' => ['route-name' => ['http-verb' => 'GET', 'path' => '/person/:id', 'controller-service-id' => 'example-controller-service-id', 'action-method-name' => 'exampleAction']]]); $expectedRoute = new Route('route-name', ['http-verb' => 'GET', 'path' => '/person/:id', 'controller-service-id' => 'example-controller-service-id', 'action-method-name' => 'exampleAction']); $this->getRoutesFromFile('routing.php')->shouldBeLike([$expectedRoute]); }