Open Monograph Press  3.3.0
ServiceDescriptionLoaderTest.php
1 <?php
2 
4 
7 
12 {
13  public function testAllowsExtraData()
14  {
15  $d = ServiceDescription::factory(array(
16  'foo' => true,
17  'baz' => array('bar'),
18  'apiVersion' => '123',
19  'operations' => array()
20  ));
21 
22  $this->assertEquals(true, $d->getData('foo'));
23  $this->assertEquals(array('bar'), $d->getData('baz'));
24  $this->assertEquals('123', $d->getApiVersion());
25  }
26 
28  {
29  $d = ServiceDescription::factory(array(
30  'operations' => array(
31  'abstract' => array(
32  'httpMethod' => 'HEAD',
33  'parameters' => array(
34  'test' => array('type' => 'string', 'required' => true)
35  )
36  ),
37  'abstract2' => array('uri' => '/test', 'extends' => 'abstract'),
38  'concrete' => array('extends' => 'abstract2'),
39  'override' => array('extends' => 'abstract', 'httpMethod' => 'PUT'),
40  'override2' => array('extends' => 'override', 'httpMethod' => 'POST', 'uri' => '/')
41  )
42  ));
43 
44  $c = $d->getOperation('concrete');
45  $this->assertEquals('/test', $c->getUri());
46  $this->assertEquals('HEAD', $c->getHttpMethod());
47  $params = $c->getParams();
48  $param = $params['test'];
49  $this->assertEquals('string', $param->getType());
50  $this->assertTrue($param->getRequired());
51 
52  // Ensure that merging HTTP method does not make an array
53  $this->assertEquals('PUT', $d->getOperation('override')->getHttpMethod());
54  $this->assertEquals('POST', $d->getOperation('override2')->getHttpMethod());
55  $this->assertEquals('/', $d->getOperation('override2')->getUri());
56  }
57 
62  {
64  'operations' => array(
65  'concrete' => array(
66  'extends' => 'missing'
67  )
68  )
69  ));
70  }
71 
73  {
74  $description = ServiceDescription::factory(array(
75  'operations' => array(
76  'a' => array(
77  'httpMethod' => 'GET',
78  'parameters' => array(
79  'a1' => array(
80  'default' => 'foo',
81  'required' => true,
82  'prepend' => 'hi'
83  )
84  )
85  ),
86  'b' => array(
87  'extends' => 'a',
88  'parameters' => array(
89  'b2' => array()
90  )
91  ),
92  'c' => array(
93  'parameters' => array(
94  'a1' => array(
95  'default' => 'bar',
96  'required' => true,
97  'description' => 'test'
98  ),
99  'c3' => array()
100  )
101  ),
102  'd' => array(
103  'httpMethod' => 'DELETE',
104  'extends' => array('b', 'c'),
105  'parameters' => array(
106  'test' => array()
107  )
108  )
109  )
110  ));
111 
112  $command = $description->getOperation('d');
113  $this->assertEquals('DELETE', $command->getHttpMethod());
114  $this->assertContains('a1', $command->getParamNames());
115  $this->assertContains('b2', $command->getParamNames());
116  $this->assertContains('c3', $command->getParamNames());
117  $this->assertContains('test', $command->getParamNames());
118 
119  $this->assertTrue($command->getParam('a1')->getRequired());
120  $this->assertEquals('bar', $command->getParam('a1')->getDefault());
121  $this->assertEquals('test', $command->getParam('a1')->getDescription());
122  }
123 
124  public function testAddsOtherFields()
125  {
126  $description = ServiceDescription::factory(array(
127  'operations' => array(),
128  'description' => 'Foo',
129  'apiVersion' => 'bar'
130  ));
131  $this->assertEquals('Foo', $description->getDescription());
132  $this->assertEquals('bar', $description->getApiVersion());
133  }
134 
135  public function testCanLoadNestedExtends()
136  {
137  $description = ServiceDescription::factory(array(
138  'operations' => array(
139  'root' => array(
140  'class' => 'foo'
141  ),
142  'foo' => array(
143  'extends' => 'root',
144  'parameters' => array(
145  'baz' => array('type' => 'string')
146  )
147  ),
148  'foo_2' => array(
149  'extends' => 'foo',
150  'parameters' => array(
151  'bar' => array('type' => 'string')
152  )
153  ),
154  'foo_3' => array(
155  'class' => 'bar',
156  'parameters' => array(
157  'bar2' => array('type' => 'string')
158  )
159  ),
160  'foo_4' => array(
161  'extends' => array('foo_2', 'foo_3'),
162  'parameters' => array(
163  'bar3' => array('type' => 'string')
164  )
165  )
166  )
167  ));
168 
169  $this->assertTrue($description->hasOperation('foo_4'));
170  $foo4 = $description->getOperation('foo_4');
171  $this->assertTrue($foo4->hasParam('baz'));
172  $this->assertTrue($foo4->hasParam('bar'));
173  $this->assertTrue($foo4->hasParam('bar2'));
174  $this->assertTrue($foo4->hasParam('bar3'));
175  $this->assertEquals('bar', $foo4->getClass());
176  }
177 }
Guzzle\Tests\Service\Description\ServiceDescriptionLoaderTest\testAllowsMultipleInheritance
testAllowsMultipleInheritance()
Definition: ServiceDescriptionLoaderTest.php:72
Guzzle\Tests\GuzzleTestCase
Definition: GuzzleTestCase.php:22
Guzzle\Tests\Service\Description\ServiceDescriptionLoaderTest\testCanLoadNestedExtends
testCanLoadNestedExtends()
Definition: ServiceDescriptionLoaderTest.php:135
Guzzle\Tests\Service\Description\ServiceDescriptionLoaderTest\testAllowsExtraData
testAllowsExtraData()
Definition: ServiceDescriptionLoaderTest.php:13
Guzzle\Service\Description\ServiceDescription\factory
static factory($config, array $options=array())
Definition: ServiceDescription.php:65
Guzzle\Tests\Service\Description\ServiceDescriptionLoaderTest\testAddsOtherFields
testAddsOtherFields()
Definition: ServiceDescriptionLoaderTest.php:124
Guzzle\Tests\Service\Description\ServiceDescriptionLoaderTest
Definition: ServiceDescriptionLoaderTest.php:11
Guzzle\Tests\Service\Description\ServiceDescriptionLoaderTest\testThrowsExceptionWhenExtendingMissingCommand
testThrowsExceptionWhenExtendingMissingCommand()
Definition: ServiceDescriptionLoaderTest.php:61
Guzzle\Service\Description\ServiceDescription
Definition: ServiceDescription.php:11
Guzzle\Tests\Service\Description
Definition: OperationTest.php:3
Guzzle\Tests\Service\Description\ServiceDescriptionLoaderTest\testAllowsDeepNestedInheritance
testAllowsDeepNestedInheritance()
Definition: ServiceDescriptionLoaderTest.php:27
Guzzle\Service\Description\ServiceDescriptionLoader
Definition: ServiceDescriptionLoader.php:11