Issues (12)

lib/custom/tests/MW/Config/Zend2Test.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2014-2018
6
 */
7
8
9
namespace Aimeos\MW\Config;
10
11
12
/**
13
 * Test class for \Aimeos\MW\Config\Zend2.
14
 */
15
class Zend2Test extends \PHPUnit\Framework\TestCase
0 ignored issues
show
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
{
17
	private $object;
18
19
20
	/**
21
	 * Sets up the fixture, for example, opens a network connection.
22
	 * This method is called before a test is executed.
23
	 *
24
	 * @access protected
25
	 */
26
	protected function setUp()
27
	{
28
		if( class_exists( 'Zend\Config\Config' ) === false ) {
29
			$this->markTestSkipped( 'Class Zend\Config\Config not found' );
30
		}
31
32
		$dir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'testfiles';
33
		$dir2 = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'testowrite';
34
35
		$conf = new \Zend\Config\Config( array( 'resource' => array( 'db' => array( 'host' => '127.0.0.1' ) ) ), true );
36
		$this->object = new \Aimeos\MW\Config\Zend2( $conf, array( $dir, $dir2 ) );
37
	}
38
39
40
	/**
41
	 * Tears down the fixture, for example, closes a network connection.
42
	 * This method is called after a test is executed.
43
	 *
44
	 * @access protected
45
	 */
46
	protected function tearDown()
47
	{
48
	}
49
50
51
	public function testGet()
52
	{
53
		$this->assertEquals( '127.0.0.1', $this->object->get( 'resource/db/host' ) );
54
55
		$x = $this->object->get( 'config/manager/standard/select', 'defvalue1');
56
		$this->assertEquals( 'select11', $x );
57
58
		$x = $this->object->get( 'config/provider/delivery/sh/select', 'defvalue2');
59
		$this->assertEquals( 'select2', $x );
60
61
		$x = $this->object->get( 'subconfig/standard/subitem/a/aa', 'defvalue3');
62
		$this->assertEquals( '111', $x );
63
64
		$x = $this->object->get( 'subconfig/subsubconfig/standard/subsubitem/aa/aaa', 'defvalue4');
65
		$this->assertEquals( '111', $x );
66
67
		$x = $this->object->get( 'config/manager/standard/select', 'defvalue5');
68
		$this->assertEquals( 'select11', $x );
69
70
		$x = $this->object->get( 'subconfig/subsubconfig/standard/subsubitem/aa/aaa', 'defvalue6');
71
		$this->assertEquals( '111', $x );
72
73
		$x = $this->object->get( 'subconfig/standard/subitem/a/aa', 'defvalue7');
74
		$this->assertEquals( '111', $x );
75
76
		$x = $this->object->get( 'subconfig/standard/subitem/a/bb', 'defvalue8');
77
		$this->assertEquals( 'defvalue8', $x );
78
79
		$x = $this->object->get( 'nonsubconfig', 'defvalue9');
80
		$this->assertEquals( 'defvalue9', $x );
81
82
		$x = $this->object->get( 'subconfig', 'defvalue10');
83
		$this->assertInternalType( 'array', $x );
84
	}
85
86
87
	public function testGetArray()
88
	{
89
		$this->assertEquals( array( 'host' => '127.0.0.1' ), $this->object->get( 'resource/db/' ) );
90
91
		$this->assertEquals(
92
			array(
93
				'subitem' => array (
94
						'a' => array(
95
							'aa' => '111',
96
						),
97
					),
98
					'subbla' => array(
99
						'b' => array (
100
							'bb' => '22',
101
						),
102
					),
103
				),
104
				$this->object->get( 'subconfig/standard'
105
			)
106
		);
107
	}
108
109
110
	public function testGetDefault()
111
	{
112
		$this->assertEquals( 3306, $this->object->get( 'resource/db/port', 3306 ) );
113
	}
114
115
116
	public function testSet()
117
	{
118
		$this->object->set( 'resource/db/database', 'testdb' );
119
		$this->assertEquals( 'testdb', $this->object->get( 'resource/db/database' ) );
120
121
		$this->object->set( 'resource/foo', 'testdb' );
122
		$this->assertEquals( 'testdb', $this->object->get( 'resource/foo' ) );
123
124
		$this->object->set( 'resource/bar/db', 'testdb' );
125
		$this->assertEquals( 'testdb', $this->object->get( 'resource/bar/db' ) );
126
	}
127
128
129
	public function testSetArray()
130
	{
131
		$this->object->set( 'resource/ldap/', array( 'host' => 'localhost', 'port' => 389 ) );
132
		$this->assertEquals( array( 'host' => 'localhost', 'port' => 389 ), $this->object->get( 'resource/ldap' ) );
133
	}
134
}
135