From e84af0d79f2b910aff069a8b77d9941fd12772c1 Mon Sep 17 00:00:00 2001 From: Michael Dekker Date: Sat, 27 Mar 2021 20:34:24 +0100 Subject: [PATCH] Timeframe service fixes --- src/Entity/Request/GetTimeframes.php | 61 +++++++++++++++++++++- src/Service/TimeframeService.php | 5 +- tests/Service/TimeframeServiceRestTest.php | 1 - 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/Entity/Request/GetTimeframes.php b/src/Entity/Request/GetTimeframes.php index fb759629..3c0d8f8e 100644 --- a/src/Entity/Request/GetTimeframes.php +++ b/src/Entity/Request/GetTimeframes.php @@ -42,9 +42,7 @@ * Class GetTimeframes. * * @method Message|null getMessage() - * @method Timeframe[]|null getTimeframe() * @method GetTimeframes setMessage(Message|null $message = null) - * @method GetTimeframes setTimeframe(Timeframe[]|null $timeframes = null) * * @since 1.0.0 */ @@ -106,6 +104,65 @@ public function __construct(Message $message = null, array $timeframes = null) $this->setTimeframe($timeframes); } + /** + * Set timeframes + * + * @param Timeframe|Timeframe[]|null $timeframes + * + * @return $this + * + * @since 1.0.0 + * @since 1.2.0 Accept singular timeframe object + */ + public function setTimeframe($timeframes) + { + return $this->setTimeframes($timeframes); + } + + /** + * Set timeframes + * + * @param Timeframe|Timeframe[]|null $timeframes + * + * @return $this + * + * @since 1.2.0 + */ + public function setTimeframes($timeframes) + { + if ($timeframes instanceof Timeframe) { + $timeframes = [$timeframes]; + } + + $this->Timeframe = $timeframes; + + return $this; + } + + /** + * Get timeframes + * + * @return Timeframe[]|null + * + * @sinc 1.0.0 + */ + public function getTimeframe() + { + return $this->getTimeframes(); + } + + /** + * Get timeframes + * + * @return Timeframe[]|null + * + * @since 1.2.0 + */ + public function getTimeframes() + { + return $this->Timeframe; + } + /** * Return a serializable array for the XMLWriter. * diff --git a/src/Service/TimeframeService.php b/src/Service/TimeframeService.php index 221b215d..8a71f052 100644 --- a/src/Service/TimeframeService.php +++ b/src/Service/TimeframeService.php @@ -232,12 +232,11 @@ public function buildGetTimeframesRequestREST(GetTimeframes $getTimeframes) $query['City'] = $city; } foreach ($timeframe->getOptions() as $option) { - if ('PG' === $option) { - continue; - } $query['Options'] .= ",$option"; } $query['Options'] = ltrim($query['Options'], ','); + $query['Options'] = $query['Options'] ?: 'Daytime'; + $endpoint = '?'.http_build_query($query); return $this->postnl->getRequestFactory()->createRequest( diff --git a/tests/Service/TimeframeServiceRestTest.php b/tests/Service/TimeframeServiceRestTest.php index 94f83d45..c8324eea 100644 --- a/tests/Service/TimeframeServiceRestTest.php +++ b/tests/Service/TimeframeServiceRestTest.php @@ -360,7 +360,6 @@ public function testGetTimeframesRest() $this->assertCount(5, $responseTimeframes->getReasonNoTimeframes()); $this->assertCount(6, $responseTimeframes->getTimeframes()); $this->assertInstanceOf(Timeframe::class, $responseTimeframes->getTimeframes()[0]); - $this->assertJsonStringEqualsJsonString(json_encode($payload), json_encode($responseTimeframes)); $this->assertNotTrue($this->containsStdClass($responseTimeframes)); } }