33 lines
683 B
PHP
33 lines
683 B
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use App\Config\Config;
|
|
|
|
class ConfigTest extends TestCase
|
|
{
|
|
public function testLoadsValidJson()
|
|
{
|
|
$tmp = tempnam(sys_get_temp_dir(), 'cfg_');
|
|
file_put_contents($tmp, json_encode(["foo" => "bar"]));
|
|
|
|
$config = new Config($tmp);
|
|
|
|
$this->assertSame("bar", $config->get("foo"));
|
|
}
|
|
|
|
public function testThrowsOnMissingFile()
|
|
{
|
|
$this->expectException(RuntimeException::class);
|
|
new Config("/nonexistent/file.json");
|
|
}
|
|
|
|
public function testThrowsOnInvalidJson()
|
|
{
|
|
$tmp = tempnam(sys_get_temp_dir(), 'cfg_');
|
|
file_put_contents($tmp, "{invalid json");
|
|
|
|
$this->expectException(RuntimeException::class);
|
|
new Config($tmp);
|
|
}
|
|
}
|