File tree Expand file tree Collapse file tree 6 files changed +44
-15
lines changed
Expand file tree Collapse file tree 6 files changed +44
-15
lines changed Original file line number Diff line number Diff line change 3232 */
3333abstract class Base
3434{
35+ const PATCH_CONTENT_TYPE = MimeConst::JSON_PATCH ;
36+
3537 /**
3638 * Holds all the properties added by overloading.
3739 *
@@ -419,4 +421,9 @@ protected static function getJsonHeader()
419421 {
420422 return array (HeaderConst::CONTENT_TYPE => MimeConst::JSON );
421423 }
424+
425+ protected static function getPatchHeaders ()
426+ {
427+ return array (HeaderConst::CONTENT_TYPE => static ::PATCH_CONTENT_TYPE );
428+ }
422429}
Original file line number Diff line number Diff line change @@ -21,4 +21,5 @@ class Mime
2121{
2222 const JSON = 'application/json ' ;
2323 const TEXT = 'text/plain ' ;
24+ const JSON_PATCH = 'application/json-patch+json ' ;
2425}
Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ class Image extends AbstractSchemaResource implements ImageInterface
3535 protected static $ json_name = '' ;
3636 protected static $ json_collection_name = 'images ' ;
3737
38+ const PATCH_CONTENT_TYPE = 'application/openstack-images-v2.1-json-patch ' ;
39+
3840 /**
3941 * Update this resource
4042 *
@@ -85,7 +87,7 @@ public function update(array $params, Schema $schema = null)
8587 $ body = $ document ->toString ();
8688
8789 return $ this ->getClient ()
88- ->patch ($ this ->getUrl (), $ this ->getService ()-> getPatchHeaders (), $ body )
90+ ->patch ($ this ->getUrl (), $ this ->getPatchHeaders (), $ body )
8991 ->send ();
9092 }
9193
Original file line number Diff line number Diff line change 1717
1818namespace OpenCloud \Image ;
1919
20- use OpenCloud \Common \Constants \Header ;
2120use OpenCloud \Common \Service \CatalogService ;
2221use OpenCloud \Image \Resource \Image ;
2322use OpenCloud \Image \Resource \Schema \Schema ;
@@ -32,18 +31,6 @@ class Service extends CatalogService
3231 const DEFAULT_TYPE = 'image ' ;
3332 const DEFAULT_NAME = 'cloudImages ' ;
3433
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-
4734 /**
4835 * This operation returns images you created, shared images that you accepted, and standard images.
4936 *
Original file line number Diff line number Diff line change @@ -36,6 +36,11 @@ public function getBar()
3636 {
3737 return $ this ->bar ;
3838 }
39+
40+ public static function getPatchHeaders ()
41+ {
42+ return parent ::getPatchHeaders ();
43+ }
3944}
4045
4146class BaseTest extends \OpenCloud \Tests \OpenCloudTestCase
@@ -100,4 +105,14 @@ public function testSetProperty()
100105 $ this ->my ->setBaz ('goodbye ' );
101106 $ this ->assertEquals ('goodbye ' , $ this ->my ->getBaz ());
102107 }
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+ }
103118}
Original file line number Diff line number Diff line change 2222use OpenCloud \Image \Resource \Schema \Schema ;
2323use OpenCloud \Tests \OpenCloudTestCase ;
2424
25+ class PublicImage extends Image
26+ {
27+ public static function getPatchHeaders ()
28+ {
29+ return parent ::getPatchHeaders ();
30+ }
31+ }
32+
2533class ImageTest extends OpenCloudTestCase
2634{
2735 public function setupObjects ()
2836 {
29- $ this ->image = new Image ($ this ->getClient ()->imageService ('cloudImages ' , 'IAD ' ));
37+ $ this ->image = new PublicImage ($ this ->getClient ()->imageService ('cloudImages ' , 'IAD ' ));
3038 }
3139
3240 protected function getSchemaData ()
@@ -139,4 +147,13 @@ public function test_Delete_Tag()
139147
140148 $ this ->assertInstanceOf ('Guzzle\Http\Message\Response ' , $ this ->image ->deleteTag (12345 ));
141149 }
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+ }
142159}
You can’t perform that action at this time.
0 commit comments