Skip to content

Commit

Permalink
- Add status property in Event
Browse files Browse the repository at this point in the history
- Add method property in Event
- Update Unit test to test new properties
  • Loading branch information
giuseppenucifora committed Jul 6, 2021
1 parent b65e802 commit ba81b43
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 38 additions & 1 deletion src/Domain/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Eluceo\iCal\Domain\Entity;

use Eluceo\iCal\Domain\Enum\MethodType;
use Eluceo\iCal\Domain\Enum\StatusType;
use Eluceo\iCal\Domain\ValueObject\Alarm;
use Eluceo\iCal\Domain\ValueObject\Attachment;
use Eluceo\iCal\Domain\ValueObject\Location;
Expand All @@ -29,7 +31,8 @@ class Event
private ?Location $location = null;
private ?Organizer $organizer = null;
private ?Timestamp $lastModified = null;

private ?StatusType $status = null;
private ?MethodType $method = null;
/**
* @var array<Alarm>
*/
Expand Down Expand Up @@ -63,6 +66,40 @@ public function touch(?Timestamp $dateTime = null): self
return $this;
}

public function getStatus(): ?StatusType
{
return $this->status;
}

public function hasStatus(): bool
{
return $this->status !== null;
}

public function setStatus(?StatusType $status): Event
{
$this->status = $status;

return $this;
}

public function getMethod(): ?MethodType
{
return $this->method;
}

public function hasMethod(): bool
{
return $this->method !== null;
}

public function setMethod(?MethodType $method): Event
{
$this->method = $method;

return $this;
}

public function getSummary(): string
{
assert($this->summary !== null);
Expand Down
42 changes: 42 additions & 0 deletions src/Domain/Enum/MethodType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the eluceo/iCal package.
*
* (c) 2021 Markus Poerschke <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Eluceo\iCal\Domain\Enum;

final class MethodType
{
private static ?self $publish = null;
private static ?self $cancel = null;

private string $method;

public function __construct(string $method)
{
assert(!empty($method), 'Method cannot be empty');

$this->method = $method;
}

public static function PUBLISH(): self
{
return self::$publish = self::$publish ?? new MethodType('PUBLISH');
}

public static function CANCELLED(): self
{
return self::$cancel = self::$cancel ?? new MethodType('CANCEL');
}

public function __toString()
{
return $this->method;
}
}
48 changes: 48 additions & 0 deletions src/Domain/Enum/StatusType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of the eluceo/iCal package.
*
* (c) 2021 Markus Poerschke <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Eluceo\iCal\Domain\Enum;

final class StatusType
{
private static ?self $confirmed = null;
private static ?self $cancelled = null;
private static ?self $tentative = null;

private string $status;

public function __construct(string $status)
{
assert(!empty($status), 'Status cannot be empty');

$this->status = $status;
}

public static function CONFIRMED(): self
{
return self::$confirmed = self::$confirmed ?? new StatusType('CONFIRMED');
}

public static function CANCELLED(): self
{
return self::$cancelled = self::$cancelled ?? new StatusType('CANCELLED');
}

public static function TENTATIVE(): self
{
return self::$tentative = self::$tentative ?? new StatusType('TENTATIVE');
}

public function __toString()
{
return $this->status;
}
}
8 changes: 8 additions & 0 deletions src/Presentation/Factory/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ protected function getProperties(Event $event): Generator
yield new Property('UID', new TextValue((string) $event->getUniqueIdentifier()));
yield new Property('DTSTAMP', new DateTimeValue($event->getTouchedAt()));

if ($event->hasStatus()) {
yield new Property('STATUS', new TextValue((string) $event->getStatus()));
}

if ($event->hasMethod()) {
yield new Property('METHOD', new TextValue((string) $event->getMethod()));
}

if ($event->hasLastModified()) {
yield new Property('LAST-MODIFIED', new DateTimeValue($event->getLastModified()));
}
Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/Presentation/Factory/EventFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use DateTimeImmutable;
use DateTimeZone;
use Eluceo\iCal\Domain\Entity\Event;
use Eluceo\iCal\Domain\Enum\MethodType;
use Eluceo\iCal\Domain\Enum\StatusType;
use Eluceo\iCal\Domain\ValueObject\Attachment;
use Eluceo\iCal\Domain\ValueObject\BinaryContent;
use Eluceo\iCal\Domain\ValueObject\Date;
Expand Down Expand Up @@ -178,6 +180,26 @@ public function testOrganizer()
]);
}

public function testStatus()
{
$event = (new Event())
->setStatus(StatusType::CONFIRMED());

self::assertEventRendersCorrect($event, [
'STATUS:CONFIRMED',
]);
}

public function testMethod()
{
$event = (new Event())
->setMethod(MethodType::PUBLISH());

self::assertEventRendersCorrect($event, [
'METHOD:PUBLISH',
]);
}

private static function assertEventRendersCorrect(Event $event, array $expected)
{
$resultAsString = (string) (new EventFactory())->createComponent($event);
Expand Down

0 comments on commit ba81b43

Please sign in to comment.