ParserTest::testParser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 22
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 31
rs 9.568
1
<?php
2
3
namespace Jalle19\StatusManager\Test\Configuration;
4
5
use Jalle19\StatusManager\Configuration\Parser;
6
use Jalle19\StatusManager\Configuration\Reader\ArrayReader;
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * Class ParserTest
11
 * @package   Jalle19\StatusManager\Test\Configuration
12
 * @copyright Copyright &copy; Sam Stenvall 2016-
13
 * @license   https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0
14
 */
15
class ParserTest extends TestCase
16
{
17
18
	use BasicConfigurationTrait;
19
20
21
	public function testParser()
22
	{
23
		$rawConfiguration = $this->getBaseConfiguration();
24
25
		// Configure two instances
26
		$rawConfiguration['instances'] = [
27
			'example.com'     => [
28
				'address' => 'example.com',
29
				'port'    => 9981,
30
			],
31
			'foo.example.com' => [
32
				'address' => 'foo.example.com',
33
				'port'    => 9981,
34
			],
35
		];
36
37
		$configuration = Parser::parseConfiguration(new ArrayReader($rawConfiguration));
38
39
		$this->assertEquals($rawConfiguration['database_path'], $configuration->getDatabasePath());
40
		$this->assertEquals($rawConfiguration['log_path'], $configuration->getLogPath());
41
		$this->assertEquals($rawConfiguration['access_token'], $configuration->getAccessToken());
42
		$this->assertCount(2, $configuration->getInstances());
43
		$this->assertEquals('example.com', $configuration->getInstanceByName('example.com')->getName());
44
		$this->assertEquals('foo.example.com', $configuration->getInstanceByName('foo.example.com')->getName());
45
		$this->assertEquals($rawConfiguration['update_interval'], $configuration->getUpdateInterval());
46
		$this->assertEquals($rawConfiguration['listen_address'], $configuration->getListenAddress());
47
		$this->assertEquals($rawConfiguration['listen_port'], $configuration->getListenPort());
48
		$this->assertEquals($rawConfiguration['http_listen_port'], $configuration->getHttpListenPort());
49
		$this->assertEquals($rawConfiguration['http_username'], $configuration->getHttpUsername());
50
		$this->assertEquals($rawConfiguration['http_password'], $configuration->getHttpPassword());
51
		$this->assertEquals([], $configuration->getInstanceByName('example.com')->getIgnoredUsers());
52
	}
53
54
}
55