diff --git a/src/Appwrite/Utopia/Messaging/Messages/Console.php b/src/Appwrite/Utopia/Messaging/Messages/Console.php index f56b592af6..20d85f27e0 100644 --- a/src/Appwrite/Utopia/Messaging/Messages/Console.php +++ b/src/Appwrite/Utopia/Messaging/Messages/Console.php @@ -6,6 +6,8 @@ use Utopia\Messaging\Message; class Console implements Message { + private ?string $origin = null; + /** * @param array $recipients */ @@ -65,4 +67,16 @@ class Console implements Message { return $this->projectInternalId; } + + public function setOrigin(?string $origin): self + { + $this->origin = $origin; + + return $this; + } + + public function getOrigin(): ?string + { + return $this->origin; + } } diff --git a/src/Appwrite/Utopia/Messaging/Messages/Webhook.php b/src/Appwrite/Utopia/Messaging/Messages/Webhook.php index 2852dbeac3..e1146f9bd0 100644 --- a/src/Appwrite/Utopia/Messaging/Messages/Webhook.php +++ b/src/Appwrite/Utopia/Messaging/Messages/Webhook.php @@ -6,6 +6,8 @@ use Utopia\Messaging\Message; class Webhook implements Message { + private ?string $origin = null; + /** * @param array $urls * @param array $payload @@ -63,4 +65,16 @@ class Webhook implements Message { return $this->timeout; } + + public function setOrigin(?string $origin): self + { + $this->origin = $origin; + + return $this; + } + + public function getOrigin(): ?string + { + return $this->origin; + } } diff --git a/tests/unit/Platform/Modules/Notifications/NotificationsTest.php b/tests/unit/Platform/Modules/Notifications/NotificationsTest.php index c128fade15..5daed2633e 100644 --- a/tests/unit/Platform/Modules/Notifications/NotificationsTest.php +++ b/tests/unit/Platform/Modules/Notifications/NotificationsTest.php @@ -34,7 +34,7 @@ final class CapturingNotificationsResponse extends Response } } -class NotificationsTest extends TestCase +final class NotificationsTest extends TestCase { private Authorization $authorization; private Database $database; diff --git a/tests/unit/Platform/Modules/Projects/SchedulesTest.php b/tests/unit/Platform/Modules/Projects/SchedulesTest.php index 8b3f063c21..ca3f105f6c 100644 --- a/tests/unit/Platform/Modules/Projects/SchedulesTest.php +++ b/tests/unit/Platform/Modules/Projects/SchedulesTest.php @@ -37,7 +37,7 @@ final class CapturingSchedulesResponse extends Response } } -class SchedulesTest extends TestCase +final class SchedulesTest extends TestCase { private Authorization $authorization; private Database $database; diff --git a/tests/unit/Platform/Workers/MailsTest.php b/tests/unit/Platform/Workers/MailsTest.php index 172480c129..a6b7a123d7 100644 --- a/tests/unit/Platform/Workers/MailsTest.php +++ b/tests/unit/Platform/Workers/MailsTest.php @@ -12,6 +12,7 @@ use Utopia\Messaging\Adapter\Email as EmailAdapter; use Utopia\Messaging\Messages\Email as EmailMessage; use Utopia\Queue\Message; use Utopia\Registry\Registry; +use Utopia\Telemetry\Adapter\None; final class SpyMailAdapter extends EmailAdapter { @@ -41,7 +42,7 @@ final class SpyMailAdapter extends EmailAdapter } } -class MailsTest extends TestCase +final class MailsTest extends TestCase { public function testLegacyMailPayloadIsSentByMailsWorker(): void { @@ -76,13 +77,14 @@ class MailsTest extends TestCase new Document(['$id' => 'project-x']), $registry, new Log(), + new None(), ); } finally { \putenv($previousSmtpHost === false ? '_APP_SMTP_HOST' : '_APP_SMTP_HOST=' . $previousSmtpHost); } $this->assertSame(1, $adapter->sendCount); - $this->assertNotNull($adapter->captured); + $this->assertInstanceOf(\Utopia\Messaging\Messages\Email::class, $adapter->captured); $message = $adapter->captured; $this->assertSame('legacy@example.test', $message->getTo()[0]['email'] ?? ''); diff --git a/tests/unit/Platform/Workers/NotificationsTest.php b/tests/unit/Platform/Workers/NotificationsTest.php index fe3eaeaa09..96c93c42fe 100644 --- a/tests/unit/Platform/Workers/NotificationsTest.php +++ b/tests/unit/Platform/Workers/NotificationsTest.php @@ -151,7 +151,7 @@ class SpyEmailAdapter extends EmailAdapter } } -class NotificationsTest extends TestCase +final class NotificationsTest extends TestCase { private Database $database; private Authorization $authorization; @@ -414,7 +414,7 @@ class NotificationsTest extends TestCase } $this->assertSame(1, $spy->sendCount); - $this->assertNotNull($spy->captured); + $this->assertInstanceOf(\Utopia\Messaging\Messages\Email::class, $spy->captured); $message = $spy->captured; $this->assertSame('legacy@example.test', $message->getTo()[0]['email'] ?? ''); @@ -724,7 +724,7 @@ class NotificationsTest extends TestCase \putenv($previousConsoleDomain === false ? '_APP_CONSOLE_DOMAIN' : '_APP_CONSOLE_DOMAIN=' . $previousConsoleDomain); } - $this->assertNotNull($spy->captured, 'SpyEmailAdapter must capture exactly one EmailMessage'); + $this->assertInstanceOf(\Utopia\Messaging\Messages\Email::class, $spy->captured, 'SpyEmailAdapter must capture exactly one EmailMessage'); $body = $spy->captured->getContent(); $this->assertStringContainsString(' must be present'); @@ -795,7 +795,7 @@ class NotificationsTest extends TestCase \putenv($previousOpenSslKey === false ? '_APP_OPENSSL_KEY_V1' : '_APP_OPENSSL_KEY_V1=' . $previousOpenSslKey); } - $this->assertNotNull($spy->captured, 'SpyEmailAdapter must capture exactly one EmailMessage'); + $this->assertInstanceOf(\Utopia\Messaging\Messages\Email::class, $spy->captured, 'SpyEmailAdapter must capture exactly one EmailMessage'); $this->assertStringNotContainsString('/v1/notifications/logos/appwrite?jwt=', $spy->captured->getContent()); } @@ -1103,7 +1103,7 @@ class NotificationsTest extends TestCase } $this->assertSame(1, $spy->sendCount, 'SMTP send must be invoked exactly once'); - $this->assertNotNull($spy->captured); + $this->assertInstanceOf(\Utopia\Messaging\Messages\Email::class, $spy->captured); $message = $spy->captured; $this->assertSame('happy@example.test', $message->getTo()[0]['email'] ?? ''); diff --git a/tests/unit/Platform/Workers/WebhooksTest.php b/tests/unit/Platform/Workers/WebhooksTest.php index 9f8ce4c745..356db9f146 100644 --- a/tests/unit/Platform/Workers/WebhooksTest.php +++ b/tests/unit/Platform/Workers/WebhooksTest.php @@ -67,10 +67,10 @@ final class WebhooksTest extends TestCase \realpath(__DIR__ . '/../../../../app/config/locale/templates/email-base-styled.tpl'), \realpath($payload['bodyTemplate']) ); - $this->assertStringContainsString('Payments', $payload['body']); - $this->assertStringContainsString('Ada Lovelace', $payload['body']); - $this->assertStringContainsString('/console/project-fra-project-1/settings/webhooks/webhook-1', $payload['body']); - $this->assertStringNotContainsString('{{', $payload['body']); + $this->assertStringContainsString('Payments', (string) $payload['body']); + $this->assertStringContainsString('Ada Lovelace', (string) $payload['body']); + $this->assertStringContainsString('/console/project-fra-project-1/settings/webhooks/webhook-1', (string) $payload['body']); + $this->assertStringNotContainsString('{{', (string) $payload['body']); $this->assertSame(APP_NAME, $payload['variables']['platform']); $this->assertSame(APP_EMAIL_LOGO_URL, $payload['variables']['logoUrl']); $this->assertCount(2, $payload['recipients']); @@ -153,10 +153,10 @@ final class WebhooksTest extends TestCase $this->assertArrayHasKey('owner@example.test', $bodies); $this->assertArrayHasKey('grace@example.test', $bodies); - $this->assertStringContainsString('Ada Lovelace', $bodies['owner@example.test']); - $this->assertStringNotContainsString('Grace Hopper', $bodies['owner@example.test']); - $this->assertStringContainsString('Grace Hopper', $bodies['grace@example.test']); - $this->assertStringNotContainsString('Ada Lovelace', $bodies['grace@example.test']); + $this->assertStringContainsString('Ada Lovelace', (string) $bodies['owner@example.test']); + $this->assertStringNotContainsString('Grace Hopper', (string) $bodies['owner@example.test']); + $this->assertStringContainsString('Grace Hopper', (string) $bodies['grace@example.test']); + $this->assertStringNotContainsString('Ada Lovelace', (string) $bodies['grace@example.test']); } public function testSendAlertDeduplicationKeyChangesPerPauseCycle(): void @@ -210,19 +210,17 @@ final class WebhooksTest extends TestCase $this->assertSame($expected, $method->invoke(null, $membership)); } - public static function ownerRoleProvider(): array + public static function ownerRoleProvider(): \Iterator { - return [ - 'array owner' => [['owner'], true], - 'array mixed case owner' => [['Owner'], true], - 'comma string owner' => ['developer, owner', true], - 'project-scoped owner string not recognized' => [['project-project-1-owner'], false], - 'mixed case project-scoped owner string not recognized' => [['Project-Project-1-Owner'], false], - 'comma string project-scoped owner not recognized' => ['developer, project-project-1-owner', false], - 'other project owner' => [['project-project-2-owner'], false], - 'non owner' => [['developer'], false], - 'invalid roles' => [null, false], - ]; + yield 'array owner' => [['owner'], true]; + yield 'array mixed case owner' => [['Owner'], true]; + yield 'comma string owner' => ['developer, owner', true]; + yield 'project-scoped owner string not recognized' => [['project-project-1-owner'], false]; + yield 'mixed case project-scoped owner string not recognized' => [['Project-Project-1-Owner'], false]; + yield 'comma string project-scoped owner not recognized' => ['developer, project-project-1-owner', false]; + yield 'other project owner' => [['project-project-2-owner'], false]; + yield 'non owner' => [['developer'], false]; + yield 'invalid roles' => [null, false]; } private function createPlatformDatabase(): Database