From 15d2e91f38173ee5075d4ae2fee7294822929d0d Mon Sep 17 00:00:00 2001 From: Doug Miller Date: Wed, 26 Feb 2020 12:42:09 -0600 Subject: [PATCH] Adding support to map array params to csv --- lib/recurly/pager.php | 22 +++++++++++++++++++++- tests/BaseClient_Test.php | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/recurly/pager.php b/lib/recurly/pager.php index ae6cfa59..cf6c2585 100644 --- a/lib/recurly/pager.php +++ b/lib/recurly/pager.php @@ -21,7 +21,27 @@ public function __construct(\Recurly\BaseClient $client, string $path, ?array $p { $this->_client = $client; $this->_path = $path; - $this->_params = $params; + $this->_params = $this->_mapArrayParams($params); + } + + /** + * Maps parameters with array values into csv strings. The API expects these + * values to be csv strings, but an array is a nicer interface for developers. + * + * @param array $params + * + * @return array + */ + private function _mapArrayParams(?array $params = []): ?array + { + if (!is_null($params)) { + array_walk($params, function(&$param, $key) { + if (is_array($param)) { + $param = join(',', $param); + } + }); + } + return $params; } /** diff --git a/tests/BaseClient_Test.php b/tests/BaseClient_Test.php index ce9a6c65..7909cd35 100644 --- a/tests/BaseClient_Test.php +++ b/tests/BaseClient_Test.php @@ -65,6 +65,7 @@ public function testDeleteResource204(): void $result = ""; $this->client->addScenario("DELETE", $url, NULL, $result, "204 No Content"); $empty = $this->client->deleteResource("iexist"); + $this->assertInstanceOf(\Recurly\EmptyResource::class, $empty); } public function testUpdateResource200(): void