test fixes

This commit is contained in:
Dennis Eichhorn 2021-10-25 20:06:48 +02:00
parent 00c343c30a
commit 97f7fb6f91
6 changed files with 160 additions and 0 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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
);
}
}

View File

@ -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
);
}
}

View File

@ -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
);
}
}