Skip to content

Commit

Permalink
Fix WebPushNotification Shape
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed May 22, 2024
1 parent 12da466 commit c8785a7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
41 changes: 21 additions & 20 deletions src/Firebase/Messaging/WebPushConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,24 @@
* @see https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification#syntax WebPush Notification Syntax
*
* @phpstan-type WebPushNotificationShape array{
* title: non-empty-string,
* options?: array{
* dir?: 'ltr'|'rtl'|'auto',
* lang?: string,
* badge?: non-empty-string,
* body?: non-empty-string,
* tag?: non-empty-string,
* icon?: non-empty-string,
* image?: non-empty-string,
* data?: mixed,
* vibrate?: list<positive-int>,
* renotify?: bool,
* requireInteraction?: bool,
* actions?: list<array{
* action: non-empty-string,
* title: non-empty-string,
* icon: non-empty-string
* }>,
* silent?: bool
* }
* title: string|null,
* dir?: 'ltr'|'rtl'|'auto',
* lang?: string,
* badge?: non-empty-string,
* body?: non-empty-string,
* tag?: non-empty-string,
* icon?: non-empty-string,
* image?: non-empty-string,
* data?: mixed,
* vibrate?: list<positive-int>,
* renotify?: bool,
* requireInteraction?: bool,
* actions?: list<array{
* action: non-empty-string,
* title: non-empty-string,
* icon: non-empty-string
* }>,
* silent?: bool
* }
*
* @see https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#webpushconfig WebPush Config Syntax
Expand Down Expand Up @@ -142,6 +140,9 @@ public function withUrgency(string $urgency): self
return $config;
}

/**
* @return WebPushConfigShape
*/
public function jsonSerialize(): array
{
// @phpstan-ignore notIdentical.alwaysTrue
Expand Down
15 changes: 15 additions & 0 deletions tests/Integration/MessagingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Kreait\Firebase\Messaging\WebPushConfig;
use Kreait\Firebase\Tests\IntegrationTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
use PHPUnit\Framework\Attributes\Test;

/**
Expand Down Expand Up @@ -395,4 +396,18 @@ public function getAppInstanceForUnknownToken(): void
throw $e;
}
}

#[Test]
#[DoesNotPerformAssertions]
public function sendWebPushNotificationWithAnEmptyTitle(): void
{
$message = CloudMessage::withTarget('token', $this->getTestRegistrationToken())
->withWebPushConfig(WebPushConfig::fromArray([
'notification' => [
'title' => '',
],
]));

$this->messaging->send($message);
}
}
8 changes: 4 additions & 4 deletions tests/Unit/Messaging/WebPushConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public function createFromValidPayload(array $data): void
public function itCanHaveAPriority(): void
{
$config = WebPushConfig::new()->withVeryLowUrgency();
$this->assertSame('very-low', $config->jsonSerialize()['headers']['Urgency']);
$this->assertSame('very-low', $config->jsonSerialize()['headers']['Urgency'] ?? null);

$config = WebPushConfig::new()->withLowUrgency();
$this->assertSame('low', $config->jsonSerialize()['headers']['Urgency']);
$this->assertSame('low', $config->jsonSerialize()['headers']['Urgency'] ?? null);

$config = WebPushConfig::new()->withNormalUrgency();
$this->assertSame('normal', $config->jsonSerialize()['headers']['Urgency']);
$this->assertSame('normal', $config->jsonSerialize()['headers']['Urgency'] ?? null);

$config = WebPushConfig::new()->withHighUrgency();
$this->assertSame('high', $config->jsonSerialize()['headers']['Urgency']);
$this->assertSame('high', $config->jsonSerialize()['headers']['Urgency'] ?? null);
}

/**
Expand Down

0 comments on commit c8785a7

Please sign in to comment.