1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2024 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Base\Config\Decorator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class MemoryTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
protected function setUp() : void |
18
|
|
|
{ |
19
|
|
|
$conf = new \Aimeos\Base\Config\PHPArray( [] ); |
20
|
|
|
$this->object = new \Aimeos\Base\Config\Decorator\Memory( $conf ); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
protected function tearDown() : void |
25
|
|
|
{ |
26
|
|
|
unset( $this->object ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
public function testApply() |
31
|
|
|
{ |
32
|
|
|
$cfg = ['resource' => ['db' => ['database' => 'test']]]; |
33
|
|
|
$conf = new \Aimeos\Base\Config\PHPArray( $cfg ); |
34
|
|
|
|
35
|
|
|
$local = ['resource' => ['db' => ['host' => '127.0.0.1']]]; |
36
|
|
|
$object = new \Aimeos\Base\Config\Decorator\Memory( $conf, $local ); |
37
|
|
|
$object->apply( ['resource' => ['db' => ['host' => '127.0.0.2', 'database' => 'testdb']]] ); |
38
|
|
|
|
39
|
|
|
$this->assertEquals( 'testdb', $object->get( 'resource/db/database' ) ); |
40
|
|
|
$this->assertEquals( '127.0.0.1', $object->get( 'resource/db/host' ) ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testGetSet() |
45
|
|
|
{ |
46
|
|
|
$this->object->set( 'resource/db/host', '127.0.0.1' ); |
47
|
|
|
$this->assertEquals( '127.0.0.1', $this->object->get( 'resource/db/host', '127.0.0.2' ) ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
public function testGetLocal() |
52
|
|
|
{ |
53
|
|
|
$conf = new \Aimeos\Base\Config\PHPArray( [] ); |
54
|
|
|
$local = ['resource' => ['db' => ['host' => '127.0.0.1']]]; |
55
|
|
|
$object = new \Aimeos\Base\Config\Decorator\Memory( $conf, $local ); |
56
|
|
|
|
57
|
|
|
$this->assertEquals( '127.0.0.1', $object->get( 'resource/db/host', '127.0.0.2' ) ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
public function testGetDefault() |
62
|
|
|
{ |
63
|
|
|
$this->assertEquals( 3306, $this->object->get( 'resource/db/port', 3306 ) ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
public function testGetMerge() |
68
|
|
|
{ |
69
|
|
|
$cfg = ['resource' => ['db' => ['database' => 'test']]]; |
70
|
|
|
$conf = new \Aimeos\Base\Config\PHPArray( $cfg ); |
71
|
|
|
|
72
|
|
|
$local = ['resource' => ['db' => ['host' => '127.0.0.1']]]; |
73
|
|
|
$object = new \Aimeos\Base\Config\Decorator\Memory( $conf, $local ); |
74
|
|
|
|
75
|
|
|
$result = $object->get( 'resource/db', [] ); |
76
|
|
|
$this->assertArrayHasKey( 'database', $result ); |
77
|
|
|
$this->assertArrayHasKey( 'host', $result ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
public function testGetOverwrite() |
82
|
|
|
{ |
83
|
|
|
$cfg = ['resource' => ['db' => ['database' => 'test']]]; |
84
|
|
|
$conf = new \Aimeos\Base\Config\PHPArray( $cfg ); |
85
|
|
|
|
86
|
|
|
$local = ['resource' => ['db' => ['host' => '127.0.0.1']]]; |
87
|
|
|
$object = new \Aimeos\Base\Config\Decorator\Memory( $conf, $local ); |
88
|
|
|
|
89
|
|
|
$result = $object->get( 'resource/db/database' ); |
90
|
|
|
$this->assertEquals( 'test', $result ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
public function testSet() |
95
|
|
|
{ |
96
|
|
|
$conf = new \Aimeos\Base\Config\PHPArray( [] ); |
97
|
|
|
$object = new \Aimeos\Base\Config\Decorator\Memory( $conf, [] ); |
98
|
|
|
|
99
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Config\Iface::class, $object->set( 'notexisting', null ) ); |
100
|
|
|
$this->assertEquals( null, $object->get( 'notexisting' ) ); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|