1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppserverIo\Provisioning\Api\Node\AbstractArgsNodeTest |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/appserver-io/provisioning |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Provisioning\Api\Node; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Test for the abstract node that serves nodes having a args/arg child. |
25
|
|
|
* |
26
|
|
|
* @author Tim Wagner <[email protected]> |
27
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
29
|
|
|
* @link https://github.com/appserver-io/provisioning |
30
|
|
|
* @link http://www.appserver.io |
31
|
|
|
*/ |
32
|
|
|
class AppstractArgsNodeTest extends \PHPUnit_Framework_TestCase |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The mock instance of the abstract class. |
37
|
|
|
* |
38
|
|
|
* @var \AppserverIo\Provisioning\Api\Node\AbstractArgsNode |
39
|
|
|
*/ |
40
|
|
|
protected $abstractArgsNode; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Initializes an instance of the abstract class we want to test. |
44
|
|
|
* |
45
|
|
|
* @return void |
46
|
|
|
* @see \PHPUnit_Framework_TestCase::setUp() |
47
|
|
|
*/ |
48
|
|
|
protected function setUp() |
49
|
|
|
{ |
50
|
|
|
$this->abstractArgsNode = $this->getMockForAbstractClass('AppserverIo\Provisioning\Api\Node\AbstractArgsNode'); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Make sure we don't have any args before we add one. |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
public function testGetEmptyArgsArray() |
59
|
|
|
{ |
60
|
|
|
$this->assertCount(0, $this->abstractArgsNode->getArgs()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
*Test to load an not existing arg by name. |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function testGetNotExistingArgByName() |
69
|
|
|
{ |
70
|
|
|
$this->assertNull($this->abstractArgsNode->getArg('unknown')); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Test to return args as array. |
75
|
|
|
* |
76
|
|
|
* @return void |
77
|
|
|
*/ |
78
|
|
|
public function testGetArgsWithOneAttached() |
79
|
|
|
{ |
80
|
|
|
|
81
|
|
|
// create an mock arg node |
82
|
|
|
$mockArgNode = $this->getMock('AppserverIo\Provisioning\Api\Node\ArgNode'); |
83
|
|
|
|
84
|
|
|
// attach the arg node |
85
|
|
|
$this->abstractArgsNode->attachArg($mockArgNode); |
86
|
|
|
|
87
|
|
|
// make sure we've exactly one arg node |
88
|
|
|
$this->assertCount(1, $this->abstractArgsNode->getArgs()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Test to return hundred args as array. |
93
|
|
|
* |
94
|
|
|
* @return void |
95
|
|
|
*/ |
96
|
|
|
public function testGetArgsWithHundredAttached() |
97
|
|
|
{ |
98
|
|
|
|
99
|
|
|
// add 100 args to the node |
100
|
|
|
for ($i = 0; $i < $counter = 100; $i++) { |
101
|
|
|
|
102
|
|
|
// create an mock arg node |
103
|
|
|
$mockArgNode = $this->getMock('AppserverIo\Provisioning\Api\Node\ArgNode'); |
104
|
|
|
|
105
|
|
|
// attach the arg node |
106
|
|
|
$this->abstractArgsNode->attachArg($mockArgNode); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
// make sure we've exactly one arg node |
110
|
|
|
$this->assertCount($counter, $this->abstractArgsNode->getArgs()); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
*Test to load an existing arg by name. |
115
|
|
|
* |
116
|
|
|
* @return void |
117
|
|
|
*/ |
118
|
|
|
public function testGetExistingArgByName() |
119
|
|
|
{ |
120
|
|
|
|
121
|
|
|
// create an mock arg node |
122
|
|
|
$mockArgNode = $this->getMock('AppserverIo\Provisioning\Api\Node\ArgNode', array('getName', 'castToType')); |
123
|
|
|
$mockArgNode->expects($this->once()) |
124
|
|
|
->method('getName') |
125
|
|
|
->will($this->returnValue($name = 'test')); |
126
|
|
|
$mockArgNode->expects($this->once()) |
127
|
|
|
->method('castToType') |
128
|
|
|
->will($this->returnValue($value = 100)); |
129
|
|
|
|
130
|
|
|
// attach the arg node |
131
|
|
|
$this->abstractArgsNode->attachArg($mockArgNode); |
132
|
|
|
|
133
|
|
|
// make sure we've exactly one arg node |
134
|
|
|
$this->assertSame($value, $this->abstractArgsNode->getArg($name)); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Test to load args converted to a simple array. |
139
|
|
|
* |
140
|
|
|
* @return void |
141
|
|
|
*/ |
142
|
|
|
public function testGetArgsAsArray() |
143
|
|
|
{ |
144
|
|
|
|
145
|
|
|
// create an mock arg node |
146
|
|
|
$mockArgNode = $this->getMock('AppserverIo\Provisioning\Api\Node\ArgNode', array('getName', 'castToType')); |
147
|
|
|
$mockArgNode->expects($this->once()) |
148
|
|
|
->method('getName') |
149
|
|
|
->will($this->returnValue($name = 'test')); |
150
|
|
|
$mockArgNode->expects($this->once()) |
151
|
|
|
->method('castToType') |
152
|
|
|
->will($this->returnValue($value = 100)); |
153
|
|
|
|
154
|
|
|
// attach the arg node |
155
|
|
|
$this->abstractArgsNode->attachArg($mockArgNode); |
156
|
|
|
|
157
|
|
|
// make sure we've the expected array |
158
|
|
|
$this->assertEquals(array($name => $value), $this->abstractArgsNode->getArgsAsArray()); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..