Passed
Push — master ( 5d1e58...95ad6f )
by Aimeos
05:54
created

MemoryTest::testApply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 12
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2013
6
 * @copyright Aimeos (aimeos.org), 2015-2021
7
 */
8
9
10
namespace Aimeos\MW\Config\Decorator;
11
12
13
class MemoryTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $object;
16
17
18
	protected function setUp() : void
19
	{
20
		$conf = new \Aimeos\MW\Config\PHPArray( [] );
21
		$this->object = new \Aimeos\MW\Config\Decorator\Memory( $conf );
22
	}
23
24
25
	protected function tearDown() : void
26
	{
27
	}
28
29
30
	public function testApply()
31
	{
32
		$cfg = ['resource' => ['db' => ['database' => 'test']]];
33
		$conf = new \Aimeos\MW\Config\PHPArray( $cfg );
34
35
		$local = ['resource' => ['db' => ['host' => '127.0.0.1']]];
36
		$this->object = new \Aimeos\MW\Config\Decorator\Memory( $conf, $local );
37
		$this->object->apply( ['resource' => ['db' => ['host' => '127.0.0.2', 'database' => 'testdb']]] );
38
39
		$result = $this->object->get( 'resource/db', [] );
40
		$this->assertEquals( 'testdb', $result['database'] );
41
		$this->assertEquals( '127.0.0.2', $result['host'] );
42
	}
43
44
45
	public function testGetSet()
46
	{
47
		$this->object->set( 'resource/db/host', '127.0.0.1' );
48
		$this->assertEquals( '127.0.0.1', $this->object->get( 'resource/db/host', '127.0.0.2' ) );
49
	}
50
51
52
	public function testGetLocal()
53
	{
54
		$conf = new \Aimeos\MW\Config\PHPArray( [] );
55
		$local = ['resource' => ['db' => ['host' => '127.0.0.1' ] ] ];
56
		$this->object = new \Aimeos\MW\Config\Decorator\Memory( $conf, $local );
57
58
		$this->assertEquals( '127.0.0.1', $this->object->get( 'resource/db/host', '127.0.0.2' ) );
59
	}
60
61
62
	public function testGetDefault()
63
	{
64
		$this->assertEquals( 3306, $this->object->get( 'resource/db/port', 3306 ) );
65
	}
66
67
68
	public function testGetOverwrite()
69
	{
70
		$cfg = ['resource' => ['db' => ['database' => 'test']]];
71
		$conf = new \Aimeos\MW\Config\PHPArray( $cfg );
72
73
		$local = ['resource' => ['db' => ['host' => '127.0.0.1']]];
74
		$this->object = new \Aimeos\MW\Config\Decorator\Memory( $conf, $local );
75
76
		$result = $this->object->get( 'resource/db', [] );
77
		$this->assertArrayNotHasKey( 'database', $result );
78
		$this->assertArrayHasKey( 'host', $result );
79
	}
80
}
81