10000 Notifier mercure7.3 · symfony/symfony@d54febf · GitHub
[go: up one dir, main page]

Skip to content

Commit d54febf

Browse files
ernie76fabpot
authored andcommitted
Notifier mercure7.3
1 parent 7a24bdc commit d54febf

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

src/Symfony/Component/Notifier/Bridge/Mercure/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4 10000 +
7.3
5+
---
6+
7+
* Add `content` option
8+
49
5.3
510
---
611

src/Symfony/Component/Notifier/Bridge/Mercure/MercureOptions.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function __construct(
2929
private ?string $id = null,
3030
private ?string $type = null,
3131
private ?int $retry = null,
32+
private ?array $content = null,
3233
) {
3334
$this->topics = null !== $topics ? (array) $topics : null;
3435
}
@@ -61,6 +62,11 @@ public function getRetry(): ?int
6162
return $this->retry;
6263
}
6364

65+
public function getContent(): ?array
66+
{
67+
return $this->content;
68+
}
69+
6470
public function toArray(): array
6571
{
6672
return [
@@ -69,6 +75,7 @@ public function toArray(): array
6975
'id' => $this->id,
7076
'type' => $this->type,
7177
'retry' => $this->retry,
78+
'content' => $this->content,
7279
];
7380
}
7481

src/Symfony/Component/Notifier/Bridge/Mercure/MercureTransport.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ protected function doSend(MessageInterface $message): SentMessage
7777
'@context' => 'https://www.w3.org/ns/activitystreams',
7878
'type' => 'Announce',
7979
'summary' => $message->getSubject(),
80+
'mediaType' => 'application/json',
81+
'content' => $options->getContent(),
8082
]), $options->isPrivate(), $options->getId(), $options->getType(), $options->getRetry());
8183

8284
try {

src/Symfony/Component/Notifier/Bridge/Mercure/Tests/MercureOptionsTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@ public function testConstructWithDefaults()
2424
'id' => null,
2525
'type' => null,
2626
'retry' => null,
27+
'content' => null,
2728
]);
2829
}
2930

3031
public function testConstructWithParameters()
3132
{
32-
$options = (new MercureOptions('/topic/1', true, 'id', 'type', 1));
33+
$options = (new MercureOptions('/topic/1', true, 'id', 'type', 1, ['tag' => '1234', 'body' => 'TEST']));
3334

3435
$this->assertSame($options->toArray(), [
3536
'topics' => ['/topic/1'],
3637
'private' => true,
3738
'id' => 'id',
3839
'type' => 'type',
3940
'retry' => 1,
41+
'content' => ['tag' => '1234', 'body' => 'TEST'],
4042
]);
4143
}
4244

src/Symfony/Component/Notifier/Bridge/Mercure/Tests/MercureTransportTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function testSendWithMercureOptions()
114114
{
115115
$hub = new MockHub('https://foo.com/.well-known/mercure', new StaticTokenProvider('foo'), function (Update $update): string {
116116
$this->assertSame(['/topic/1', '/topic/2'], $update->getTopics());
117-
$this->assertSame('{"@context":"https:\/\/www.w3.org\/ns\/activitystreams","type":"Announce","summary":"subject"}', $update->getData());
117+
$this->assertSame('{"@context":"https:\/\/www.w3.org\/ns\/activitystreams","type":"Announce","summary":"subject","mediaType":"application\/json","content":{"tag":"1234","body":"TEST"}}', $update->getData());
118118
$this->assertSame('id', $update->getId());
119119
$this->assertSame('type', $update->getType());
120120
$this->assertSame(1, $update->getRetry());
@@ -123,14 +123,14 @@ public function testSendWithMercureOptions()
123123
return 'id';
124124
});
125125

126-
self::createTransport(null, $hub)->send(new ChatMessage('subject', new MercureOptions(['/topic/1', '/topic/2'], true, 'id', 'type', 1)));
126+
self::createTransport(null, $hub)->send(new ChatMessage('subject', new MercureOptions(['/topic/1', '/topic/2'], true, 'id', 'type', 1, ['tag' => '1234', 'body' => 'TEST'])));
127127
}
128128

129129
public function testSendWithMercureOptionsButWithoutOptionTopic()
130130
{
131131
$hub = new MockHub('https://foo.com/.well-known/mercure', new StaticTokenProvider('foo'), function (Update $update): string {
132132
$this->assertSame(['https://symfony.com/notifier'], $update->getTopics());
133-
$this->assertSame('{"@context":"https:\/\/www.w3.org\/ns\/activitystreams","type":"Announce","summary":"subject"}', $update->getData());
133+
$this->assertSame('{"@context":"https:\/\/www.w3.org\/ns\/activitystreams","type":"Announce","summary":"subject","mediaType":"application\/json","content":null}', $update->getData());
134134
$this->assertSame('id', $update->getId());
135135
$this->assertSame('type', $update->getType());
136136
$this->assertSame(1, $update->getRetry());
@@ -146,7 +146,7 @@ public function testSendWithoutMercureOptions()
146146
{
147147
$hub = new MockHub('https://foo.com/.well-known/mercure', new StaticTokenProvider('foo'), function (Update $update): string {
148148
$this->assertSame(['https://symfony.com/notifier'], $update->getTopics());
149-
$this->assertSame('{"@context":"https:\/\/www.w3.org\/ns\/activitystreams","type":"Announce","summary":"subject"}', $update->getData());
149+
$this->assertSame('{"@context":"https:\/\/www.w3.org\/ns\/activitystreams","type":"Announce","summary":"subject","mediaType":"application\/json","content":null}', $update->getData());
150150
$this->assertFalse($update->isPrivate());
151151

152152
return 'id';

0 commit comments

Comments
 (0)
0