114 lines
2.9 KiB
PHP
114 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace com\fwdekker\deathnotifier;
|
|
|
|
use com\fwdekker\deathnotifier\Config;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
/**
|
|
* Unit tests for {@see Config}.
|
|
*/
|
|
class ConfigTest extends TestCase
|
|
{
|
|
public function setUp(): void
|
|
{
|
|
Config::_reset();
|
|
}
|
|
|
|
|
|
public function test_has_returns_false_if_section_does_not_exist(): void
|
|
{
|
|
self::assertFalse(Config::has("test_section"));
|
|
}
|
|
|
|
public function test_has_returns_false_if_property_does_not_exist(): void
|
|
{
|
|
self::assertFalse(Config::has("test_section.property"));
|
|
}
|
|
|
|
|
|
public function test_set_creates_section(): void
|
|
{
|
|
Config::_set("test_section", "value");
|
|
|
|
self::assertTrue(Config::has("test_section"));
|
|
}
|
|
|
|
public function test_set_creates_property_in_section(): void
|
|
{
|
|
Config::_set("test_section.property", "value");
|
|
|
|
self::assertTrue(Config::has("test_section.property"));
|
|
}
|
|
|
|
public function test_set_creates_section_for_property(): void
|
|
{
|
|
Config::_set("test_section.property", "value");
|
|
|
|
self::assertTrue(Config::has("test_section"));
|
|
}
|
|
|
|
public function test_set_adds_property_to_existing_section(): void
|
|
{
|
|
Config::_set("test_section.property1", "value");
|
|
Config::_set("test_section.property2", "value");
|
|
|
|
self::assertTrue(Config::has("test_section.property1"));
|
|
self::assertTrue(Config::has("test_section.property2"));
|
|
}
|
|
|
|
public function test_set_overwrites_existing_property(): void
|
|
{
|
|
Config::_set("test_section.property", "value");
|
|
|
|
Config::_set("test_section.property", "new_value");
|
|
|
|
self::assertEquals("new_value", Config::get("test_section.property"));
|
|
}
|
|
|
|
|
|
public function test_get_returns_all_with_null_index(): void
|
|
{
|
|
Config::_set("test_section.property", "value");
|
|
|
|
$config = Config::get();
|
|
self::assertArrayHasKey("test_section", $config);
|
|
self::assertIsArray($config["test_section"]);
|
|
}
|
|
|
|
public function test_get_returns_section(): void
|
|
{
|
|
Config::_set("test_section.property", "value");
|
|
|
|
self::assertEquals(["property" => "value"], Config::get("test_section"));
|
|
}
|
|
|
|
public function test_get_returns_property(): void
|
|
{
|
|
Config::_set("test_section.property", "value");
|
|
|
|
self::assertEquals("value", Config::get("test_section.property"));
|
|
}
|
|
|
|
public function test_get_returns_null_if_section_does_not_exist(): void
|
|
{
|
|
self::assertNull(Config::get("test_section"));
|
|
}
|
|
|
|
public function test_get_returns_null_if_property_does_not_exist(): void
|
|
{
|
|
self::assertNull(Config::get("test_section.property"));
|
|
}
|
|
|
|
|
|
public function test_reset(): void
|
|
{
|
|
Config::_set("test_section.property", "value");
|
|
|
|
Config::_reset();
|
|
|
|
self::assertFalse(Config::has("test_section.property"));
|
|
}
|
|
}
|