16 public function setUp()
23 $value = array(array(1));
24 $this->assertFalse($this->validator->validate($this->getComplexParam(), $value));
26 array(
'[Foo][0] must be an array of properties. Got a numerically indexed array.'),
27 $this->validator->getErrors()
34 $this->assertFalse($this->validator->validate($this->getComplexParam(), $value));
36 array(
'[Foo][0] must be of type object'),
37 $this->validator->getErrors()
43 $value = array(array());
44 $this->assertTrue($this->validator->validate($this->getComplexParam(), $value));
45 $this->assertEquals(array(array(
'Bar' =>
true)), $value);
51 array(
'Baz' =>
'hello!'),
54 $this->assertTrue($this->validator->validate($this->getComplexParam(), $value));
55 $this->assertEquals(array(
67 $result = $param->toArray();
68 $this->assertInternalType(
'array', $result[
'items']);
69 $this->assertEquals(
'array', $result[
'type']);
70 $this->assertInstanceOf(
'Guzzle\Service\Description\Parameter', $param->getItems());
78 'instanceOf' => get_class($this)
80 $this->assertTrue($this->validator->validate($p, $this));
81 $this->assertFalse($this->validator->validate($p, $p));
82 $this->assertEquals(array(
'[foo] must be an instance of ' . __CLASS__), $this->validator->getErrors());
89 'type' => array(
'object',
'string'),
90 'instanceOf' => get_class($this)
92 $this->assertTrue($this->validator->validate($p, $this));
94 $this->assertTrue($this->validator->validate($p, $s));
99 $o = $this->getMockBuilder(
'Guzzle\Common\ToArrayInterface')
100 ->setMethods(array(
'toArray'))
101 ->getMockForAbstractClass();
102 $o->expects($this->once())
104 ->will($this->returnValue(array(
110 'properties' => array(
111 'foo' => array(
'required' =>
'true')
114 $this->assertTrue($this->validator->validate($p, $o));
122 'properties' => array(
123 'bar' => array(
'type' =>
'string',
'required' =>
true,
'description' =>
'This is what it does'),
124 'test' => array(
'type' =>
'string',
'minLength' => 2,
'maxLength' => 5),
125 'test2' => array(
'type' =>
'string',
'minLength' => 2,
'maxLength' => 2),
126 'test3' => array(
'type' =>
'integer',
'minimum' => 100),
127 'test4' => array(
'type' =>
'integer',
'maximum' => 10),
128 'test5' => array(
'type' =>
'array',
'maxItems' => 2),
129 'test6' => array(
'type' =>
'string',
'enum' => array(
'a',
'bc')),
130 'test7' => array(
'type' =>
'string',
'pattern' =>
'/[0-9]+/'),
131 'test8' => array(
'type' =>
'number'),
136 "items" => array(
"type" =>
"string")
144 'baz' => array(
false),
147 'test5' => array(1, 3, 4),
153 $this->assertFalse($this->validator->validate($p, $value));
154 $this->assertEquals(array (
155 '[foo][bar] is a required string: This is what it does',
156 '[foo][baz] must contain 2 or more elements',
157 '[foo][baz][0] must be of type string',
158 '[foo][test2] length must be less than or equal to 2',
159 '[foo][test3] must be greater than or equal to 100',
160 '[foo][test4] must be less than or equal to 10',
161 '[foo][test5] must contain 2 or fewer elements',
162 '[foo][test6] must be one of "a" or "bc"',
163 '[foo][test7] must match the following regular expression: /[0-9]+/',
164 '[foo][test8] must be of type number',
165 '[foo][test] length must be greater than or equal to 2',
166 ), $this->validator->getErrors());
175 'properties' => array(
179 'properties' => array(
180 'foo' => array(
'default' =>
'hi')
186 $this->assertTrue($this->validator->validate($p, $value));
187 $this->assertEquals(array(
'bar' => array(
'foo' =>
'hi')), $value);
196 'properties' => array(
200 'properties' => array(
'foo' => array(
'type' =>
'string'))
205 $this->assertFalse($this->validator->validate($p, $value));
206 $this->assertEquals(array(
'[foo][bar] is a required object'), $this->validator->getErrors());
212 $r = new \ReflectionMethod($p,
'determineType');
213 $r->setAccessible(
true);
214 $this->assertEquals(
'any', $r->invoke($p,
'any',
'hello'));
215 $this->assertEquals(
false, $r->invoke($p,
'foo',
'foo'));
216 $this->assertEquals(
'string', $r->invoke($p,
'string',
'hello'));
217 $this->assertEquals(
false, $r->invoke($p,
'string',
false));
218 $this->assertEquals(
'integer', $r->invoke($p,
'integer', 1));
219 $this->assertEquals(
false, $r->invoke($p,
'integer',
'abc'));
220 $this->assertEquals(
'numeric', $r->invoke($p,
'numeric', 1));
221 $this->assertEquals(
'numeric', $r->invoke($p,
'numeric',
'1'));
222 $this->assertEquals(
'number', $r->invoke($p,
'number', 1));
223 $this->assertEquals(
'number', $r->invoke($p,
'number',
'1'));
224 $this->assertEquals(
false, $r->invoke($p,
'numeric',
'a'));
225 $this->assertEquals(
'boolean', $r->invoke($p,
'boolean',
true));
226 $this->assertEquals(
'boolean', $r->invoke($p,
'boolean',
false));
227 $this->assertEquals(
false, $r->invoke($p,
'boolean',
'false'));
228 $this->assertEquals(
'null', $r->invoke($p,
'null',
null));
229 $this->assertEquals(
false, $r->invoke($p,
'null',
'abc'));
230 $this->assertEquals(
'array', $r->invoke($p,
'array', array()));
231 $this->assertEquals(
false, $r->invoke($p,
'array',
'foo'));
239 'properties' => array(
'bar' => array(
'type' =>
'string')),
240 'additionalProperties' =>
false
242 $value = array(
'test' =>
'123');
243 $this->assertFalse($this->validator->validate($param, $value));
244 $this->assertEquals(array(
'[foo][test] is not an allowed property'), $this->validator->getErrors());
245 $value = array(
'bar' =>
'123');
246 $this->assertTrue($this->validator->validate($param, $value));
254 'properties' => array(
'bar' => array(
'type' =>
'string'))
256 $value = array(
'test' =>
'123');
257 $this->assertTrue($this->validator->validate($param, $value));
265 'properties' => array(
'bar' => array(
'type' =>
'string')),
266 'additionalProperties' => array(
'type' =>
'integer')
268 $value = array(
'test' =>
'foo');
269 $this->assertFalse($this->validator->validate($param, $value));
270 $this->assertEquals(array(
'[foo][test] must be of type integer'), $this->validator->getErrors());
278 'additionalProperties' => array(
280 'items' => array(
'type' =>
'string')
283 $value = array(
'test' => array(
true));
284 $this->assertFalse($this->validator->validate($param, $value));
285 $this->assertEquals(array(
'[foo][test][0] must be of type string'), $this->validator->getErrors());
290 $param =
new Parameter(array(
'name' =>
'test',
'type' =>
'string'));
292 $this->assertTrue($this->validator->validate($param, $value));
293 $this->assertEquals(
'12', $value);
298 $param =
new Parameter(array(
'name' =>
'test',
'type' => array(
'string',
'boolean'),
'required' =>
true));
300 $this->assertFalse($this->validator->validate($param, $value));
301 $this->assertEquals(array(
'[test] is a required string or boolean'), $this->validator->getErrors());
313 'properties' => array(