-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefinitionTest.php
213 lines (194 loc) · 7.55 KB
/
DefinitionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Server
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DefinitionTest.php 23522 2010-12-16 20:33:22Z andries $
*/
// Call Zend_Server_DefinitionTest::main() if this source file is executed directly.
if (!defined("PHPUnit_MAIN_METHOD")) {
define("PHPUnit_MAIN_METHOD", "Zend_Server_DefinitionTest::main");
}
/** Zend_Server_Definition */
require_once 'Zend/Server/Definition.php';
/** Zend_Server_Method_Definition */
require_once 'Zend/Server/Method/Definition.php';
/** Zend_Server_Method_Callback */
require_once 'Zend/Server/Method/Callback.php';
/** Zend_Server_Method_Prototype */
require_once 'Zend/Server/Method/Prototype.php';
/**
* Test class for Zend_Server_Definition
*
* @category Zend
* @package Zend_Server
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @group Zend_Server
*/
class Zend_Server_DefinitionTest extends PHPUnit_Framework_TestCase
{
/**
* Runs the test methods of this class.
*
* @return void
*/
public static function main()
{
$suite = new PHPUnit_Framework_TestSuite("Zend_Server_DefinitionTest");
$result = PHPUnit_TextUI_TestRunner::run($suite);
}
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*
* @return void
*/
public function setUp()
{
$this->definition = new Zend_Server_Definition();
}
/**
* Tears down the fixture, for example, close a network connection.
* This method is called after a test is executed.
*
* @return void
*/
public function tearDown()
{
}
public function testMethodsShouldBeEmptyArrayByDefault()
{
$methods = $this->definition->getMethods();
$this->assertTrue(is_array($methods));
$this->assertTrue(empty($methods));
}
public function testDefinitionShouldAllowAddingSingleMethods()
{
$method = new Zend_Server_Method_Definition(array('name' => 'foo'));
$this->definition->addMethod($method);
$methods = $this->definition->getMethods();
$this->assertEquals(1, count($methods));
$this->assertSame($method, $methods['foo']);
$this->assertSame($method, $this->definition->getMethod('foo'));
}
public function testDefinitionShouldAllowAddingMultipleMethods()
{
$method1 = new Zend_Server_Method_Definition(array('name' => 'foo'));
$method2 = new Zend_Server_Method_Definition(array('name' => 'bar'));
$this->definition->addMethods(array($method1, $method2));
$methods = $this->definition->getMethods();
$this->assertEquals(2, count($methods));
$this->assertSame($method1, $methods['foo']);
$this->assertSame($method1, $this->definition->getMethod('foo'));
$this->assertSame($method2, $methods['bar']);
$this->assertSame($method2, $this->definition->getMethod('bar'));
}
public function testSetMethodsShouldOverwriteExistingMethods()
{
$this->testDefinitionShouldAllowAddingMultipleMethods();
$method1 = new Zend_Server_Method_Definition(array('name' => 'foo'));
$method2 = new Zend_Server_Method_Definition(array('name' => 'bar'));
$methods = array($method1, $method2);
$this->assertNotEquals($methods, $this->definition->getMethods());
$this->definition->setMethods($methods);
$test = $this->definition->getMethods();
$this->assertEquals(array_values($methods), array_values($test));
}
public function testHasMethodShouldReturnFalseWhenMethodNotRegisteredWithDefinition()
{
$this->assertFalse($this->definition->hasMethod('foo'));
}
public function testHasMethodShouldReturnTrueWhenMethodRegisteredWithDefinition()
{
$this->testDefinitionShouldAllowAddingMultipleMethods();
$this->assertTrue($this->definition->hasMethod('foo'));
}
public function testDefinitionShouldAllowRemovingIndividualMethods()
{
$this->testDefinitionShouldAllowAddingMultipleMethods();
$this->assertTrue($this->definition->hasMethod('foo'));
$this->definition->removeMethod('foo');
$this->assertFalse($this->definition->hasMethod('foo'));
}
public function testDefinitionShouldAllowClearingAllMethods()
{
$this->testDefinitionShouldAllowAddingMultipleMethods();
$this->definition->clearMethods();
$test = $this->definition->getMethods();
$this->assertTrue(empty($test));
}
public function testDefinitionShouldSerializeToArray()
{
$method = array(
'name' => 'foo.bar',
'callback' => array(
'type' => 'function',
'function' => 'bar',
),
'prototypes' => array(
array(
'returnType' => 'string',
'parameters' => array('string'),
),
),
'methodHelp' => 'Foo Bar!',
'invokeArguments' => array('foo'),
);
$definition = new Zend_Server_Definition();
$definition->addMethod($method);
$test = $definition->toArray();
$this->assertEquals(1, count($test));
$test = array_shift($test);
$this->assertEquals($method['name'], $test['name']);
$this->assertEquals($method['methodHelp'], $test['methodHelp']);
$this->assertEquals($method['invokeArguments'], $test['invokeArguments']);
$this->assertEquals($method['prototypes'][0]['returnType'], $test['prototypes'][0]['returnType']);
}
public function testPassingOptionsToConstructorShouldSetObjectState()
{
$method = array(
'name' => 'foo.bar',
'callback' => array(
'type' => 'function',
'function' => 'bar',
),
'prototypes' => array(
array(
'returnType' => 'string',
'parameters' => array('string'),
),
),
'methodHelp' => 'Foo Bar!',
'invokeArguments' => array('foo'),
);
$options = array($method);
$definition = new Zend_Server_Definition($options);
$test = $definition->toArray();
$this->assertEquals(1, count($test));
$test = array_shift($test);
$this->assertEquals($method['name'], $test['name']);
$this->assertEquals($method['methodHelp'], $test['methodHelp']);
$this->assertEquals($method['invokeArguments'], $test['invokeArguments']);
$this->assertEquals($method['prototypes'][0]['returnType'], $test['prototypes'][0]['returnType']);
}
}
// Call Zend_Server_DefinitionTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == "Zend_Server_DefinitionTest::main") {
Zend_Server_DefinitionTest::main();
}