diff --git a/tests/Functional/Infrastructure/Config/JsonConfigProviderTest.php b/tests/Functional/Infrastructure/Config/JsonConfigProviderTest.php new file mode 100644 index 0000000..3b038f7 --- /dev/null +++ b/tests/Functional/Infrastructure/Config/JsonConfigProviderTest.php @@ -0,0 +1,70 @@ +mapper = (new MapperBuilder())->mapper(); + + $this->tmpFile = tempnam(sys_get_temp_dir(), 'cfg_'); + $configExample = __DIR__ . '/../../../../config/config.example.json'; + + if (false === $this->tmpFile) { + $this->markTestSkipped('Unable to create temporary config file.'); + } + + copy($configExample, $this->tmpFile); + } + + protected function tearDown(): void + { + if (is_file($this->tmpFile)) { + unlink($this->tmpFile); + } + } + + public function testThrowsIfFileNotReadable(): void + { + $provider = new JsonConfigProvider('/non/existent/path.json', $this->mapper); + + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('not found'); + + $provider->getConfig(); + } + + public function testThrowsOnMappingError(): void + { + file_put_contents($this->tmpFile, '{"foo":"bar"}'); + + $provider = new JsonConfigProvider($this->tmpFile, $this->mapper); + + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Failed to map'); + + $provider->getConfig(); + } + + public function testReturnsConfigOnSuccess(): void + { + $provider = new JsonConfigProvider($this->tmpFile, $this->mapper); + $config = $provider->getConfig(); + + self::assertInstanceOf(Config::class, $config); + } +}