diff --git a/Models/Calendar.php b/Models/Calendar.php index b44820f..71acbb6 100755 --- a/Models/Calendar.php +++ b/Models/Calendar.php @@ -193,4 +193,25 @@ class Calendar return false; } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'name' => $this->name, + 'description' => $this->description, + 'createdAt' => $this->createdAt, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } } diff --git a/Models/Event.php b/Models/Event.php index de11a0a..42dd156 100755 --- a/Models/Event.php +++ b/Models/Event.php @@ -349,4 +349,32 @@ class Event { return $this->tags[$id] ?? new NullTag(); } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'name' => $this->name, + 'description' => $this->description, + 'type' => $this->type, + 'status' => $this->status, + 'schedule' => $this->schedule, + 'location' => $this->location, + 'calendar' => $this->calendar, + 'people' => $this->people, + 'tags' => $this->tags, + 'createdAt' => $this->createdAt, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } } diff --git a/Models/Schedule.php b/Models/Schedule.php index c667909..3ce3e25 100755 --- a/Models/Schedule.php +++ b/Models/Schedule.php @@ -295,4 +295,31 @@ class Schedule { return $this->freqInterval; } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'uuid' => $this->uid, + 'status' => $this->status, + 'freqType' => $this->freqType, + 'freqInterval' => $this->freqInterval, + 'relativeInternal' => $this->relativeInternal, + 'intervalType' => $this->intervalType, + 'recurrenceFactor' => $this->recurrenceFactor, + 'start' => $this->start, + 'createdAt' => $this->createdAt, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } } diff --git a/tests/Models/CalendarTest.php b/tests/Models/CalendarTest.php index 8b664e0..8f21e49 100755 --- a/tests/Models/CalendarTest.php +++ b/tests/Models/CalendarTest.php @@ -138,4 +138,26 @@ final class CalendarTest extends \PHPUnit\Framework\TestCase self::assertEquals([], $this->calendar->getEventsOnDate(new \DateTime('2005-10-10'))); self::assertEquals([$event], $this->calendar->getEventsOnDate(new \DateTime('2005-10-09'))); } + + /** + * @covers Modules\Calendar\Models\Calendar + * @group module + */ + public function testSerialize() : void + { + $this->calendar->name = 'Name'; + $this->calendar->description = 'Description'; + + $serialized = $this->calendar->jsonSerialize(); + unset($serialized['createdAt']); + + self::assertEquals( + [ + 'id' => 0, + 'name' => 'Name', + 'description' => 'Description', + ], + $serialized + ); + } } diff --git a/tests/Models/EventTest.php b/tests/Models/EventTest.php index 3cadab8..d07f283 100755 --- a/tests/Models/EventTest.php +++ b/tests/Models/EventTest.php @@ -166,4 +166,35 @@ final class EventTest extends \PHPUnit\Framework\TestCase self::assertCount(0, $this->event->getTags()); self::assertFalse($this->event->removeTag(0)); } + + /** + * @covers Modules\Calendar\Models\Event + * @group module + */ + public function testSerialize() : void + { + $this->event->name = 'Name'; + $this->event->description = 'Description'; + $this->event->setType(EventType::TEMPLATE); + $this->event->setStatus(EventStatus::INACTIVE); + + $serialized = $this->event->jsonSerialize(); + unset($serialized['location']); + unset($serialized['schedule']); + unset($serialized['createdAt']); + + self::assertEquals( + [ + 'id' => 0, + 'name' => 'Name', + 'description' => 'Description', + 'type' => EventType::TEMPLATE, + 'status' => EventStatus::INACTIVE, + 'calendar' => 0, + 'people' => [], + 'tags' => [], + ], + $serialized + ); + } } diff --git a/tests/Models/ScheduleTest.php b/tests/Models/ScheduleTest.php index e762e4a..88fec9d 100644 --- a/tests/Models/ScheduleTest.php +++ b/tests/Models/ScheduleTest.php @@ -152,4 +152,35 @@ final class ScheduleTest extends \PHPUnit\Framework\TestCase $this->expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class); $this->schedule->setIntervalType(999); } + + /** + * @covers Modules\Calendar\Models\Schedule + * @group module + */ + public function testSerialize() : void + { + $this->schedule->setStatus(ScheduleStatus::INACTIVE); + $this->schedule->setFreqType(FrequencyType::YEARLY); + $this->schedule->setFreqInterval(FrequencyInterval::DAY); + $this->schedule->setFrequencyRelative(FrequencyRelative::LAST); + $this->schedule->setIntervalType(IntervalType::RELATIVE); + + $serialized = $this->schedule->jsonSerialize(); + unset($serialized['start']); + unset($serialized['createdAt']); + + self::assertEquals( + [ + 'id' => 0, + 'uuid' => '', + 'status' => ScheduleStatus::INACTIVE, + 'freqType' => FrequencyType::YEARLY, + 'freqInterval' => FrequencyInterval::DAY, + 'relativeInternal' => FrequencyRelative::LAST, + 'intervalType' => IntervalType::RELATIVE, + 'recurrenceFactor' => 0, + ], + $serialized + ); + } }