fix(notifications): satisfy messaging 1.1.0 Message interface and align tests

The 1.9.x merge bumped utopia-php/messaging to 1.1.0, which added
setOrigin/getOrigin to the Message interface; implement them on the
Console and Webhook message classes (fatal on class load otherwise).

Also pass the new Telemetry argument to Mails::action() in MailsTest and
apply the repository Rector rules to the notification test suite so the
Checks (lint/rector/phpstan) job is green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Damodar LohaniandClaude Opus 4.8 committed 2026-06-23 02:25:13 +00:00
1 parent 8bdd701a2d
commit 3c31bfbb21
7 files changed
+57 -29

No files matched your search

@@ -6,6 +6,8 @@ use Utopia\Messaging\Message;
class Console implements Message
{
private ?string $origin = null;
/**
* @param array<int, array{address?: string, resourceType: string, resourceId: string, resourceInternalId: string, parentResourceType: string, parentResourceId: string, parentResourceInternalId: string, alertId?: string, recipientHash?: string}> $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;
}
}
@@ -6,6 +6,8 @@ use Utopia\Messaging\Message;
class Webhook implements Message
{
private ?string $origin = null;
/**
* @param array<int, string> $urls
* @param array<string, mixed> $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;
}
}
@@ -34,7 +34,7 @@ final class CapturingNotificationsResponse extends Response
}
}
class NotificationsTest extends TestCase
final class NotificationsTest extends TestCase
{
private Authorization $authorization;
private Database $database;
@@ -37,7 +37,7 @@ final class CapturingSchedulesResponse extends Response
}
}
class SchedulesTest extends TestCase
final class SchedulesTest extends TestCase
{
private Authorization $authorization;
private Database $database;
+4 -2
View File
@@ -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'] ?? '');
@@ -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('<img src=', $body, 'tracking logo <img> 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'] ?? '');
+18 -20
View File
@@ -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