PHPArrayTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2026
6
 */
7
8
9
namespace Aimeos\Base\Config;
10
11
12
class PHPArrayTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
16
17
	protected function setUp() : void
18
	{
19
		$dir = __DIR__ . DIRECTORY_SEPARATOR . 'testfiles';
20
		$dir2 = __DIR__ . DIRECTORY_SEPARATOR . 'testowrite';
21
22
		$conf = array( 'resource' => array( 'db' => array( 'host' => '127.0.0.1' ) ) );
23
		$this->object = new \Aimeos\Base\Config\PHPArray( $conf, array( $dir, $dir2 ) );
24
	}
25
26
27
	public function testApply()
28
	{
29
		$this->object->apply( ['resource' => ['db' => ['database' => 'testdb']]] );
30
		$this->assertEquals( 'testdb', $this->object->get( 'resource/db/database' ) );
31
32
		$this->object->apply( ['resource' => ['foo' => 'testdb']] );
33
		$this->object->set( 'resource/foo', 'testdb' );
34
		$this->assertEquals( 'testdb', $this->object->get( 'resource/foo' ) );
35
36
		$this->object->apply( ['resource' => ['bar' => ['db' => 'testdb']]] );
37
		$this->assertEquals( 'testdb', $this->object->get( 'resource/bar/db' ) );
38
	}
39
40
41
	public function testGet()
42
	{
43
		$this->assertEquals( '127.0.0.1', $this->object->get( 'resource/db/host' ) );
44
45
		$x = $this->object->get( 'config/manager/default/select', 'defvalue1' );
46
		$this->assertEquals( 'select11', $x );
47
48
		$x = $this->object->get( 'config/provider/delivery/sh/select', 'defvalue2' );
49
		$this->assertEquals( 'select2', $x );
50
51
		$x = $this->object->get( 'subconfig/default/subitem/a/aa', 'defvalue3' );
52
		$this->assertEquals( '111', $x );
53
54
		$x = $this->object->get( 'subconfig/subsubconfig/default/subsubitem/aa/aaa', 'defvalue4' );
55
		$this->assertEquals( '111', $x );
56
57
		$x = $this->object->get( 'config/manager/default/select', 'defvalue5' );
58
		$this->assertEquals( 'select11', $x );
59
60
		$x = $this->object->get( 'subconfig/subsubconfig/default/subsubitem/aa/aaa', 'defvalue6' );
61
		$this->assertEquals( '111', $x );
62
63
		$x = $this->object->get( 'subconfig/default/subitem/a/aa', 'defvalue7' );
64
		$this->assertEquals( '111', $x );
65
66
		$x = $this->object->get( 'subconfig/default/subitem/a/bb', 'defvalue8' );
67
		$this->assertEquals( 'defvalue8', $x );
68
69
		$x = $this->object->get( 'nonsubconfig', 'defvalue9' );
70
		$this->assertEquals( 'defvalue9', $x );
71
72
		$x = $this->object->get( 'subconfig', 'defvalue10' );
73
		$this->assertIsArray( $x );
74
	}
75
76
77
	public function testGetArray()
78
	{
79
		$this->assertEquals( array( 'host' => '127.0.0.1' ), $this->object->get( 'resource/db/' ) );
80
81
		$this->assertEquals(
82
			array(
83
				'subitem' => array(
84
					'a' => array(
85
						'aa' => '111',
86
					),
87
				),
88
				'subbla' => array(
89
					'b' => array(
90
						'bb' => '22',
91
					),
92
				),
93
			),
94
			$this->object->get( 'subconfig/default' )
95
		);
96
	}
97
98
99
	public function testGetDefault()
100
	{
101
		$this->assertEquals( 3306, $this->object->get( 'resource/db/port', 3306 ) );
102
	}
103
104
105
	public function testSet()
106
	{
107
		$this->object->set( 'resource/db/database', 'testdb' );
108
		$this->assertEquals( 'testdb', $this->object->get( 'resource/db/database' ) );
109
110
		$this->object->set( 'resource/foo', 'testdb' );
111
		$this->assertEquals( 'testdb', $this->object->get( 'resource/foo' ) );
112
113
		$this->object->set( 'resource/bar/db', 'testdb' );
114
		$this->assertEquals( 'testdb', $this->object->get( 'resource/bar/db' ) );
115
	}
116
117
118
	public function testSetArray()
119
	{
120
		$this->object->set( 'resource/ldap/', array( 'host' => 'localhost', 'port' => 389 ) );
121
		$this->assertEquals( array( 'host' => 'localhost', 'port' => 389 ), $this->object->get( 'resource/ldap' ) );
122
	}
123
}
124