| 1 | <?php |
| 2 | |
| 3 | namespace Liuch\DmarcSrg; |
| 4 | |
| 5 | use Liuch\DmarcSrg\Exception\LogicException; |
| 6 | |
| 7 | class ConfigTest extends \PHPUnit\Framework\TestCase |
| 8 | { |
| 9 | private $conf = null; |
| 10 | |
| 11 | public function setUp(): void |
| 12 | { |
| 13 | $this->conf = new Config('tests/conf_test_file.php'); |
| 14 | } |
| 15 | |
| 16 | public function testEmptyName(): void |
| 17 | { |
| 18 | $this->expectException(LogicException::class); |
| 19 | $this->conf->get(''); |
| 20 | } |
| 21 | |
| 22 | public function testNestedEmptyName(): void |
| 23 | { |
| 24 | $this->expectException(LogicException::class); |
| 25 | $this->expectExceptionMessage('Incorrect '); |
| 26 | $this->conf->get('cleaner/'); |
| 27 | } |
| 28 | |
| 29 | public function testNotAllowedName(): void |
| 30 | { |
| 31 | $this->assertNull($this->conf->get('some')); |
| 32 | $this->assertEquals(1, $this->conf->get('some', 1)); |
| 33 | } |
| 34 | |
| 35 | public function testNonexistentParameter(): void |
| 36 | { |
| 37 | $this->assertNull($this->conf->get('unknown')); |
| 38 | $this->assertNull($this->conf->get('unknown', null)); |
| 39 | $this->assertFalse($this->conf->get('unknown', false)); |
| 40 | $this->assertSame(0, $this->conf->get('unknown', 0)); |
| 41 | $this->assertSame('', $this->conf->get('unknown', '')); |
| 42 | $array = $this->conf->get('unknown', []); |
| 43 | $this->assertIsArray($array); |
| 44 | $this->assertEmpty($array); |
| 45 | } |
| 46 | |
| 47 | public function testBoolParameter(): void |
| 48 | { |
| 49 | $this->assertSame(false, $this->conf->get('debug')); |
| 50 | } |
| 51 | |
| 52 | public function testIntParameter(): void |
| 53 | { |
| 54 | $this->assertSame(0, $this->conf->get('database')); |
| 55 | } |
| 56 | |
| 57 | public function testStringParameter(): void |
| 58 | { |
| 59 | $this->assertSame('', $this->conf->get('mailboxes')); |
| 60 | } |
| 61 | |
| 62 | public function testNullParameter(): void |
| 63 | { |
| 64 | $this->assertNull($this->conf->get('directories')); |
| 65 | } |
| 66 | |
| 67 | public function testArrayParameter(): void |
| 68 | { |
| 69 | $array = $this->conf->get('admin'); |
| 70 | $this->assertIsArray($array); |
| 71 | $this->assertEmpty($array); |
| 72 | } |
| 73 | |
| 74 | public function testArrayKeyIntParameter(): void |
| 75 | { |
| 76 | $this->assertSame(0, $this->conf->get('cleaner/key_int')); |
| 77 | } |
| 78 | |
| 79 | public function testArrayKeyBoolParameter(): void |
| 80 | { |
| 81 | $this->assertFalse($this->conf->get('cleaner/key_bool')); |
| 82 | } |
| 83 | |
| 84 | public function testArrayKeyStringParameter(): void |
| 85 | { |
| 86 | $this->assertSame('', $this->conf->get('cleaner/key_string')); |
| 87 | } |
| 88 | |
| 89 | public function testArrayKeyNonexistentParameter(): void |
| 90 | { |
| 91 | $this->assertSame('default', $this->conf->get('cleaner/key_some', 'default')); |
| 92 | } |
| 93 | } |