diff --git a/src/Entities/NotificationReaderEntity.php b/src/Entities/NotificationReaderEntity.php index 3168e02..9f25d77 100644 --- a/src/Entities/NotificationReaderEntity.php +++ b/src/Entities/NotificationReaderEntity.php @@ -19,6 +19,8 @@ class NotificationReaderEntity implements \JsonSerializable, NotificationReaderE protected ?string $id = null; protected ?string $tenantId = null; + protected ?string $changeTypeString = null; + /** @param array $data */ public function __construct(array $data = []) { @@ -61,6 +63,7 @@ public function setSubscriptionId(?string $subscriptionId): NotificationReaderEn public function setChangeType(?string $changeType = null): NotificationReaderEntityInterface { + $this->setChangeTypeReceivedString($changeType); $this->changeType = ChangeType::UNKNOWN; if (isset($changeType) && ($value = ChangeType::tryFrom($changeType))) { $this->changeType = $value; @@ -126,4 +129,15 @@ public function getTenantId(): ?string { return $this->tenantId; } + + // MARK: Logging purpose only + public function getChangeTypeReceivedString(): ?string + { + return $this->changeTypeString; + } + + protected function setChangeTypeReceivedString(?string $changeType = null): void + { + $this->changeTypeString = $changeType; + } } diff --git a/tests/Notification/ReceiverTest.php b/tests/Notification/ReceiverTest.php index 164d5d3..5d4f155 100644 --- a/tests/Notification/ReceiverTest.php +++ b/tests/Notification/ReceiverTest.php @@ -72,6 +72,7 @@ public function testExec() $this->assertSame('#Microsoft.Graph.Event', $entity->getODataType()); $this->assertSame('2023-12-10T18:23:45+00:00', $entity->getSubscriptionExpirationDateTime()); $this->assertSame('tenant_id_1', $entity->getTenantId()); + $this->assertSame(ChangeType::UPDATED->value, $entity->getChangeTypeReceivedString()); $this->receiverStub->hydrate([$entity]); $this->receiverStub->exec( @@ -121,6 +122,25 @@ public function testEntity(): void $this->assertEquals(ChangeType::UPDATED, $entity->getChangeType()); } + public function testChangeTypeString(): void + { + $entity = new NotificationReaderEntity(); + $entity->setResource('test.com') + ->setId('123') + ->setChangeType(ChangeType::CREATED->value) + ->setSubscriptionId('ABC=='); + + $this->assertEquals(ChangeType::CREATED->value, $entity->getChangeTypeReceivedString()); + + $entity->setChangeType('Changed'); + $this->assertEquals('Changed', $entity->getChangeTypeReceivedString()); + $this->assertEquals(ChangeType::UNKNOWN, $entity->getChangeType()); + + $entity->setChangeType(); + $this->assertEquals(null, $entity->getChangeTypeReceivedString()); + $this->assertEquals(ChangeType::UNKNOWN, $entity->getChangeType()); + } + protected function getOData(): array { return [