17 protected function setUp()
25 $p = $this->coll->getAll();
26 $this->assertEmpty($p,
'-> Collection must be empty when no data is passed');
36 $this->assertEquals($this->coll->getAll(), $testData,
'-> getAll() must return the data passed in the constructor');
37 $this->assertEquals($this->coll->getAll(), $this->coll->toArray());
42 $this->coll->set(
'key',
'value');
43 $this->assertInstanceOf(
'ArrayIterator', $this->coll->getIterator());
44 $this->assertEquals(1, count($this->coll));
46 foreach ($this->coll as $key => $value) {
47 $this->assertEquals(
'key', $key);
48 $this->assertEquals(
'value', $value);
51 $this->assertEquals(1, $total);
56 $this->coll->add(
'test',
'value1');
57 $this->assertEquals($this->coll->getAll(), array(
'test' =>
'value1'));
58 $this->coll->add(
'test',
'value2');
59 $this->assertEquals($this->coll->getAll(), array(
'test' => array(
'value1',
'value2')));
60 $this->coll->add(
'test',
'value3');
61 $this->assertEquals($this->coll->getAll(), array(
'test' => array(
'value1',
'value2',
'value3')));
69 'test3' => array(
'value3',
'value4')
71 $this->coll->merge($params);
72 $this->assertEquals($this->coll->getAll(), $params);
75 $this->assertEquals($this->coll->merge($this->coll), $this->coll);
80 $this->coll->merge(array(
86 $this->coll->remove(
'test');
88 $this->assertEquals($this->coll->getAll(), array(
95 $this->assertEquals($this->coll->getAll(), array());
100 $this->assertNull($this->coll->get(
'test'));
101 $this->coll->add(
'test',
'value');
102 $this->assertEquals(
'value', $this->coll->get(
'test'));
103 $this->coll->set(
'test2',
'v2');
104 $this->coll->set(
'test3',
'v3');
105 $this->assertEquals(array(
108 ), $this->coll->getAll(array(
'test',
'test2')));
113 $this->assertEquals(array(), $this->coll->getKeys());
114 $this->coll->merge(array(
118 $this->assertEquals(array(
'test1',
'test2'), $this->coll->getKeys());
120 $this->assertEquals(array(
'test1',
'test2'), $this->coll->getKeys());
121 $this->coll->remove(
'test1');
122 $this->assertEquals(array(
'test2'), $this->coll->getKeys());
123 $this->coll->add(
'test3',
'value3');
124 $this->assertEquals(array(
'test2',
'test3'), $this->coll->getKeys());
129 $this->assertFalse($this->coll->hasKey(
'test'));
130 $this->coll->add(
'test',
'value');
131 $this->assertEquals(
true, $this->coll->hasKey(
'test'));
132 $this->coll->add(
'test2',
'value2');
133 $this->assertEquals(
true, $this->coll->hasKey(
'test'));
134 $this->assertEquals(
true, $this->coll->hasKey(
'test2'));
135 $this->assertFalse($this->coll->hasKey(
'testing'));
136 $this->assertEquals(
false, $this->coll->hasKey(
'AB-C',
'junk'));
141 $this->assertFalse($this->coll->hasValue(
'value'));
142 $this->coll->add(
'test',
'value');
143 $this->assertEquals(
'test', $this->coll->hasValue(
'value'));
144 $this->coll->add(
'test2',
'value2');
145 $this->assertEquals(
'test', $this->coll->hasValue(
'value'));
146 $this->assertEquals(
'test2', $this->coll->hasValue(
'value2'));
147 $this->assertFalse($this->coll->hasValue(
'val'));
152 $this->coll->add(
'foo',
'bar');
153 $this->coll->add(
'tEsT',
'value');
154 $this->coll->add(
'tesTing',
'v2');
155 $this->coll->add(
'key',
'v3');
156 $this->assertNull($this->coll->get(
'test'));
157 $this->assertEquals(array(
161 ), $this->coll->getAll(array(
162 'foo',
'tesTing',
'tEsT'
169 $this->assertEquals(0, $data->count());
170 $data->add(
'key',
'value');
171 $this->assertEquals(1, count($data));
172 $data->add(
'key',
'value2');
173 $this->assertEquals(1, count($data));
174 $data->add(
'key_2',
'value3');
175 $this->assertEquals(2, count($data));
183 'test3' => array(
'value3',
'value4')
187 $this->coll->merge($params);
190 $this->coll->merge(array(
192 'different_key' =>
'new value'
195 $this->assertEquals(array(
196 'test' => array(
'value1',
'another'),
198 'test3' => array(
'value3',
'value4'),
199 'different_key' =>
'new value'
200 ), $this->coll->getAll());
205 $this->coll->merge(array(
208 'prepositions' => array(
'about',
'above',
'across',
'after'),
209 'same_number' =>
'ten'
212 $filtered = $this->coll->filter(
function($key, $value) {
213 return $value ==
'ten';
216 $this->assertNotEquals($filtered, $this->coll);
218 $this->assertEquals(array(
220 'same_number' =>
'ten'
221 ), $filtered->getAll());
226 $this->coll->merge(array(
232 $mapped = $this->coll->map(
function($key, $value) {
233 return $value * $value;
236 $this->assertNotEquals($mapped, $this->coll);
238 $this->assertEquals(array(
242 ), $mapped->getAll());
247 $this->coll->merge(array(
252 $this->assertTrue($this->coll->offsetExists(
'k1'));
253 $this->assertFalse($this->coll->offsetExists(
'Krull'));
255 $this->coll->offsetSet(
'k3',
'v3');
256 $this->assertEquals(
'v3', $this->coll->offsetGet(
'k3'));
257 $this->assertEquals(
'v3', $this->coll->get(
'k3'));
259 $this->coll->offsetUnset(
'k1');
260 $this->assertFalse($this->coll->offsetExists(
'k1'));
270 $this->assertInstanceOf(
'Guzzle\\Http\\QueryString', $qs->map(
function($a, $b) {}));
271 $this->assertInstanceOf(
'Guzzle\\Common\\Collection', $qs->map(
function($a, $b) {}, array(),
false));
273 $this->assertInstanceOf(
'Guzzle\\Http\\QueryString', $qs->filter(
function($a, $b) {}));
274 $this->assertInstanceOf(
'Guzzle\\Common\\Collection', $qs->filter(
function($a, $b) {},
false));
279 $this->assertSame($this->coll, $this->coll->replace(array(
283 $this->assertEquals(array(
285 ), $this->coll->getAll());
291 array(
'this_is_a_test',
'{a}_is_a_{b}', array(
295 array(
'this_is_a_test',
'{abc}_is_a_{0}', array(
299 array(
'this_is_a_test',
'{abc}_is_a_{0}', array(
303 array(
'this_is_a_test',
'this_is_a_test', array(
306 array(
'{abc}_is_{not_found}a_{0}',
'{abc}_is_{not_found}a_{0}', array())
316 $this->assertEquals($output, $collection->inject($input));
326 $this->assertEquals(
'foo', $collection->keySearch(
'FOO'));
327 $this->assertEquals(
'BaZ', $collection->keySearch(
'baz'));
328 $this->assertEquals(
false, $collection->keySearch(
'Bar'));
335 'base_url' =>
'http://www.test.com/'
341 $this->assertInstanceOf(
'Guzzle\Common\Collection', $c);
342 $this->assertEquals(array(
345 'base_url' =>
'http://www.test.com/'
350 $this->fail(
'Exception not throw when missing config');
361 array(array(), array()),
372 $this->assertSame($b, $c->get(
'value'));
386 $this->assertEquals(
'bar', $collection->getPath(
'foo'));
387 $this->assertEquals(
'jar', $collection->getPath(
'baz/mesa/jar'));
388 $this->assertNull($collection->getPath(
'wewewf'));
389 $this->assertNull($collection->getPath(
'baz/mesa/jar/jar'));
400 $this->assertEquals(
'jar', $collection->getPath(
'0/a'));
401 $this->assertEquals(
'other', $collection->getPath(
'1'));
411 'array' => array(
'a',
'b',
'c')
415 'array' => array(
'd',
'e',
'f')
421 array(
'array' => array(
'h',
'i'))
428 array($c,
'foo',
'bar'),
429 array($c,
'baz', $data[
'baz']),
430 array($c,
'bam', $data[
'bam']),
431 array($c,
'baz/mesa', $data[
'baz'][
'mesa']),
432 array($c,
'baz/mesa/jar',
'jar'),
434 array($c,
'baz/*', array(
436 'array' => array_merge($data[
'baz'][
'mesa'][
'array'], $data[
'baz'][
'bar'][
'array']),
440 array($c,
'fefwfw',
null),
442 array($c,
'*/*/*/*/*/wefwfe', array()),
444 array($c,
'*|mesa', $data[
'baz'][
'mesa'],
'|'),
446 array($c,
'baz/*/array/*', array_merge($data[
'baz'][
'mesa'][
'array'], $data[
'baz'][
'bar'][
'array'])),
448 array($c,
'baz/*/array', array_merge($data[
'baz'][
'mesa'][
'array'], $data[
'baz'][
'bar'][
'array'])),
449 array($c,
'baz/mesa/array', $data[
'baz'][
'mesa'][
'array']),
451 array($c,
'baz/mesa/array/*', $data[
'baz'][
'mesa'][
'array']),
453 array($c,
'*', array_merge(array(
'bar'), $data[
'baz'], $data[
'bam'])),
455 array($c,
'*/*', array(
457 'array' => array(
'a',
'b',
'c',
'd',
'e',
'f',
'h',
'i'),
462 array($c,
'*/*/array', array(
'a',
'b',
'c',
'd',
'e',
'f',
'h',
'i'))
471 $this->assertEquals($expected, $c->getPath($path, $separator));
476 $c =
new Collection(array(
'foo' => 1,
'baz' => 2,
'bar' => 3));
477 $c->overwriteWith(array(
'foo' => 10,
'bar' => 300));
478 $this->assertEquals(array(
'foo' => 10,
'baz' => 2,
'bar' => 300), $c->getAll());
483 $c =
new Collection(array(
'foo' => 1,
'baz' => 2,
'bar' => 3));
485 $c->overwriteWith($b);
486 $this->assertEquals(array(
'foo' => 10,
'baz' => 2,
'bar' => 300), $c->getAll());
491 $c =
new Collection(array(
'foo' => 1,
'baz' => 2,
'bar' => 3));
493 $c->overwriteWith($b->getIterator());
494 $this->assertEquals(array(
'foo' => 10,
'baz' => 2,
'bar' => 300), $c->getAll());
500 $c->setPath(
'foo/bar/baz/123',
'hi');
501 $this->assertEquals(
'hi', $c[
'foo'][
'bar'][
'baz'][
'123']);
506 $c =
new Collection(array(
'foo' => array(
'bar' =>
'test')));
507 $c->setPath(
'foo/bar',
'hi');
508 $this->assertEquals(
'hi', $c[
'foo'][
'bar']);
517 $c->setPath(
'foo/bar',
'hi');
518 $this->assertEquals(
'hi', $c[
'foo'][
'bar']);
527 $c->setPath(
'foo/bar/baz',
'test');