File tree 6 files changed +44
-15
lines changed
6 files changed +44
-15
lines changed Original file line number Diff line number Diff line change 32
32
*/
33
33
abstract class Base
34
34
{
35
+ const PATCH_CONTENT_TYPE = MimeConst::JSON_PATCH ;
36
+
35
37
/**
36
38
* Holds all the properties added by overloading.
37
39
*
@@ -419,4 +421,9 @@ protected static function getJsonHeader()
419
421
{
420
422
return array (HeaderConst::CONTENT_TYPE => MimeConst::JSON );
421
423
}
424
+
425
+ protected static function getPatchHeaders ()
426
+ {
427
+ return array (HeaderConst::CONTENT_TYPE => static ::PATCH_CONTENT_TYPE );
428
+ }
422
429
}
Original file line number Diff line number Diff line change @@ -21,4 +21,5 @@ class Mime
21
21
{
22
22
const JSON = 'application/json ' ;
23
23
const TEXT = 'text/plain ' ;
24
+ const JSON_PATCH = 'application/json-patch+json ' ;
24
25
}
Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ class Image extends AbstractSchemaResource implements ImageInterface
35
35
protected static $ json_name = '' ;
36
36
protected static $ json_collection_name = 'images ' ;
37
37
38
+ const PATCH_CONTENT_TYPE = 'application/openstack-images-v2.1-json-patch ' ;
39
+
38
40
/**
39
41
* Update this resource
40
42
*
@@ -85,7 +87,7 @@ public function update(array $params, Schema $schema = null)
85
87
$ body = $ document ->toString ();
86
88
87
89
return $ this ->getClient ()
88
- ->patch ($ this ->getUrl (), $ this ->getService ()-> getPatchHeaders (), $ body )
90
+ ->patch ($ this ->getUrl (), $ this ->getPatchHeaders (), $ body )
89
91
->send ();
90
92
}
91
93
Original file line number Diff line number Diff line change 17
17
18
18
namespace OpenCloud \Image ;
19
19
20
- use OpenCloud \Common \Constants \Header ;
21
20
use OpenCloud \Common \Service \CatalogService ;
22
21
use OpenCloud \Image \Resource \Image ;
23
22
use OpenCloud \Image \Resource \Schema \Schema ;
@@ -32,18 +31,6 @@ class Service extends CatalogService
32
31
const DEFAULT_TYPE = 'image ' ;
33
32
const DEFAULT_NAME = 'cloudImages ' ;
34
33
35
- const PATCH_CONTENT_TYPE = 'application/openstack-images-v2.1-json-patch ' ;
36
-
37
- /**
38
- * Get the default headers to send for PATCH requests
39
- *
40
- * @return array
41
- */
42
- public function getPatchHeaders ()
43
- {
44
- return array (Header::CONTENT_TYPE => self ::PATCH_CONTENT_TYPE );
45
- }
46
-
47
34
/**
48
35
* This operation returns images you created, shared images that you accepted, and standard images.
49
36
*
Original file line number Diff line number Diff line change @@ -36,6 +36,11 @@ public function getBar()
36
36
{
37
37
return $ this ->bar ;
38
38
}
39
+
40
+ public static function getPatchHeaders ()
41
+ {
42
+ return parent ::getPatchHeaders ();
43
+ }
39
44
}
40
45
41
46
class BaseTest extends \OpenCloud \Tests \OpenCloudTestCase
@@ -100,4 +105,14 @@ public function testSetProperty()
100
105
$ this ->my ->setBaz ('goodbye ' );
101
106
$ this ->assertEquals ('goodbye ' , $ this ->my ->getBaz ());
102
107
}
108
+
109
+ public function testGetPatchHeaders ()
110
+ {
111
+ $ expectedHeaders = array (
112
+ 'Content-Type ' => 'application/json-patch+json '
113
+ );
114
+
115
+ $ my = $ this ->my ;
116
+ $ this ->assertEquals ($ expectedHeaders , $ my ::getPatchHeaders ());
117
+ }
103
118
}
Original file line number Diff line number Diff line change 22
22
use OpenCloud \Image \Resource \Schema \Schema ;
23
23
use OpenCloud \Tests \OpenCloudTestCase ;
24
24
25
+ class PublicImage extends Image
26
+ {
27
+ public static function getPatchHeaders ()
28
+ {
29
+ return parent ::getPatchHeaders ();
30
+ }
31
+ }
32
+
25
33
class ImageTest extends OpenCloudTestCase
26
34
{
27
35
public function setupObjects ()
28
36
{
29
- $ this ->image = new Image ($ this ->getClient ()->imageService ('cloudImages ' , 'IAD ' ));
37
+ $ this ->image = new PublicImage ($ this ->getClient ()->imageService ('cloudImages ' , 'IAD ' ));
30
38
}
31
39
32
40
protected function getSchemaData ()
@@ -139,4 +147,13 @@ public function test_Delete_Tag()
139
147
140
148
$ this ->assertInstanceOf ('Guzzle\Http\Message\Response ' , $ this ->image ->deleteTag (12345 ));
141
149
}
150
+
151
+ public function testGetPatchHeaders ()
152
+ {
153
+ $ expectedHeaders = array (
154
+ 'Content-Type ' => 'application/openstack-images-v2.1-json-patch '
155
+ );
156
+
157
+ $ this ->assertEquals ($ expectedHeaders , $ this ->image ->getPatchHeaders ());
158
+ }
142
159
}
You can’t perform that action at this time.
0 commit comments