Skip to content

Commit

Permalink
feat(appointment): add virtual property to toData method #176
Browse files Browse the repository at this point in the history
  • Loading branch information
DumbergerL committed Nov 3, 2023
1 parent d44154a commit dc44adb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Models/Calendars/Appointment/Appointment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions tests/Unit/Models/AppointmentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit dc44adb

Please sign in to comment.