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
|
<?php
namespace Guzzle\Tests\Service\Resource;
use Guzzle\Service\Resource\Model;
use Guzzle\Service\Description\Parameter;
use Guzzle\Common\Collection;
/**
* @covers Guzzle\Service\Resource\Model
*/
class ModelTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testOwnsStructure()
{
$param = new Parameter(array('type' => 'object'));
$model = new Model(array('foo' => 'bar'), $param);
$this->assertSame($param, $model->getStructure());
$this->assertEquals('bar', $model->get('foo'));
$this->assertEquals('bar', $model['foo']);
}
public function testCanBeUsedWithoutStructure()
{
$model = new Model(array(
'Foo' => 'baz',
'Bar' => array(
'Boo' => 'Bam'
)
));
$transform = function ($key, $value) {
return ($value && is_array($value)) ? new Collection($value) : $value;
};
$model = $model->map($transform);
$this->assertInstanceOf('Guzzle\Common\Collection', $model->getPath('Bar'));
}
public function testAllowsFiltering()
{
$model = new Model(array(
'Foo' => 'baz',
'Bar' => 'a'
));
$model = $model->filter(function ($i, $v) {
return $v[0] == 'a';
});
$this->assertEquals(array('Bar' => 'a'), $model->toArray());
}
public function testDoesNotIncludeEmptyStructureInString()
{
$model = new Model(array('Foo' => 'baz'));
$str = (string) $model;
$this->assertContains('Debug output of model', $str);
$this->assertNotContains('Model structure', $str);
}
public function testDoesIncludeModelStructureInString()
{
$model = new Model(array('Foo' => 'baz'), new Parameter(array('name' => 'Foo')));
$str = (string) $model;
$this->assertContains('Debug output of Foo model', $str);
$this->assertContains('Model structure', $str);
}
}
|