File tree Expand file tree Collapse file tree 2 files changed +37
-4
lines changed
Expand file tree Collapse file tree 2 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -132,9 +132,11 @@ public function setForwardingURL(int $statusCode, string $forwardingUrl)
132132 throw new ConfigurationsException ('Status Codes can only be 301 or 302. ' );
133133 }
134134
135- $ this ->addConfigurationOption ('forwarding_url ' , [
136- 'status_code ' => $ statusCode ,
137- 'url ' => $ forwardingUrl ,
135+ $ this ->addConfigurationOption ("forwarding_url " , [
136+ 'value ' => [
137+ 'status_code ' => $ statusCode ,
138+ 'url ' => $ forwardingUrl ,
139+ ],
138140 ]);
139141 }
140142
@@ -299,9 +301,19 @@ public function getArray(): array
299301
300302 private function addConfigurationOption (string $ setting , array $ configuration )
301303 {
304+ /**
305+ * Transforms an, optionally nested, array in to a collection of
306+ * stdClass objects.
307+ *
308+ * @var array $array
309+ */
310+ $ getArrayAsObject = function (array $ array ) {
311+ return json_decode (json_encode ($ array ));
312+ };
313+
302314 $ configuration ['id ' ] = $ setting ;
303315
304- $ this ->configs [] = ( object ) $ configuration ;
316+ array_push ( $ this ->configs , $ getArrayAsObject ( $ configuration)) ;
305317 }
306318
307319 private function getBoolAsOnOrOff (bool $ value ): string
Original file line number Diff line number Diff line change 1+ <?php
2+ use Cloudflare \API \Configurations \PageRulesActions ;
3+
4+ class PageRulesActionTest extends TestCase
5+ {
6+ public function testForwardingURLConfigurationIsApplied ()
7+ {
8+ $ identifier = 'forwarding_url ' ;
9+ $ statusCode = 301 ;
10+ $ forwardingURL = 'https://www.example.org/ ' ;
11+
12+ $ actions = new PageRulesActions ();
13+ $ actions ->setForwardingURL ($ statusCode , $ forwardingURL );
14+ $ configuration = $ actions ->getArray ();
15+
16+ $ this ->assertCount (1 , $ configuration );
17+ $ this ->assertEquals ($ identifier , $ configuration [0 ]->id );
18+ $ this ->assertEquals ($ statusCode , $ configuration [0 ]->value ->status_code );
19+ $ this ->assertEquals ($ forwardingURL , $ configuration [0 ]->value ->url );
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments