From dc44adb5c9549f53a84ce91044a774ed804575bf Mon Sep 17 00:00:00 2001 From: DumbergerL Date: Fri, 3 Nov 2023 09:17:39 +0100 Subject: [PATCH] feat(appointment): add virtual property to toData method #176 --- .../Calendars/Appointment/Appointment.php | 8 +++++ tests/Unit/Models/AppointmentModelTest.php | 29 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/Models/Calendars/Appointment/Appointment.php b/src/Models/Calendars/Appointment/Appointment.php index b62aa213..4a991557 100644 --- a/src/Models/Calendars/Appointment/Appointment.php +++ b/src/Models/Calendars/Appointment/Appointment.php @@ -111,6 +111,14 @@ public function getBaseEndDateAsDateTime(): ?\DateTimeImmutable return CTDateTimeService::stringToDateTime($this->getBaseEndDate()); } + public function toData(): array + { + $data = $this->convertPropertiesToData(); + $data["startDate"] = $this->getStartDate(); + $data["endDate"] = $this->getEndDate(); + return $data; + } + /** * @param string|null $id * @return Appointment diff --git a/tests/Unit/Models/AppointmentModelTest.php b/tests/Unit/Models/AppointmentModelTest.php index b5350558..3ffffad3 100644 --- a/tests/Unit/Models/AppointmentModelTest.php +++ b/tests/Unit/Models/AppointmentModelTest.php @@ -87,4 +87,33 @@ public function testOverwriteBaseAttributes_WrongOrder() $this->assertEquals(CTDateTimeService::stringToDateTime("2022-08-07T15:00:00Z"), $appointment->getBaseStartDateAsDateTime()); $this->assertEquals(CTDateTimeService::stringToDateTime("2022-08-07T16:00:00Z"), $appointment->getBaseEndDateAsDateTime()); } + + public function testToData() + { + $dataA = [ + "base" => [ + "id" => 848, + "caption" => "Service", + "startDate" => "2022-08-07T15:00:00Z", + "endDate" => "2022-08-07T16:00:00Z", + ], + "calculated" => [ + "startDate" => "2022-01-07T15:00:00Z", + "endDate" => "2022-01-07T16:00:00Z", + ] + ]; + + $appointment = Appointment::createModelFromData($dataA); + + $data = $appointment->toData(); + + print_r($data); + + $this->assertArrayHasKey("base_startDate", $data); + $this->assertArrayHasKey("base_endDate", $data); + $this->assertArrayHasKey("calculated_startDate", $data); + $this->assertArrayHasKey("calculated_endDate", $data); + $this->assertArrayHasKey("startDate", $data); + $this->assertArrayHasKey("endDate", $data); + } } \ No newline at end of file