Skip to content

Commit 108e9b4

Browse files
committed
fix: test all options
1 parent 6bfe3ed commit 108e9b4

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/Symfony/Component/Notifier/Bridge/Ntfy/NtfyOptions.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\Ntfy;
1313

14+
use Symfony\Component\Notifier\Exception\LogicException;
1415
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
1516
use Symfony\Component\Notifier\Notification\Notification;
1617

@@ -104,7 +105,11 @@ public function setTags(array $tags): self
104105

105106
public function setDelay(\DateTimeInterface $dateTime): self
106107
{
107-
$this->options['delay'] = $dateTime->getTimestamp();
108+
if ($dateTime > (new \DateTime())) {
109+
$this->options['delay'] = (string) $dateTime->getTimestamp();
110+
} else {
111+
throw new LogicException('Delayed date must be defined in the future.');
112+
}
108113

109114
return $this;
110115
}
@@ -151,21 +156,25 @@ public function setEmail(string $email): self
151156
return $this;
152157
}
153158

154-
public function setCache(bool $enable)
159+
public function setCache(bool $enable): self
155160
{
156161
if (!$enable) {
157162
$this->options['cache'] = 'no';
158163
} else {
159164
unset($this->options['cache']);
160165
}
166+
167+
return $this;
161168
}
162169

163-
public function setFirebase(bool $enable)
170+
public function setFirebase(bool $enable): self
164171
{
165172
if (!$enable) {
166173
$this->options['firebase'] = 'no';
167174
} else {
168175
unset($this->options['firebase']);
169176
}
177+
178+
return $this;
170179
}
171180
}

src/Symfony/Component/Notifier/Bridge/Ntfy/Tests/NtfyOptionsTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,40 @@ class NtfyOptionsTest extends TestCase
2121
{
2222
public function testNtfyOptions()
2323
{
24+
$delay = (new \DateTime())->add(new \DateInterval('PT1M'));
2425
$ntfyOptions = (new NtfyOptions())
2526
->setMessage('test message')
27+
->setTitle('message title')
28+
->setPriority(NtfyOptions::PRIORITY_URGENT)
29+
->setTags(['tag1', 'tag2'])
30+
->addTag('tag3')
31+
->setDelay($delay)
32+
->setActions([['action' => 'view', 'label' => 'View', 'url' => 'https://test.com']])
33+
->addAction(['action' => 'http', 'label' => 'Open', 'url' => 'https://test2.com'])
34+
->setClick('https://test3.com')
35+
->setAttachment('https://filesrv.lan/space.jpg')
36+
->setFilename('diskspace.jpg')
37+
->setEmail('me@mail.com')
38+
->setCache(false)
39+
->setFirebase(false)
2640
;
2741

2842
$this->assertSame([
2943
'message' => 'test message',
44+
'title' => 'message title',
45+
'priority' => NtfyOptions::PRIORITY_URGENT,
46+
'tags' => ['tag1', 'tag2', 'tag3'],
47+
'delay' => (string) $delay->getTimestamp(),
48+
'actions' => [
49+
['action' => 'view', 'label' => 'View', 'url' => 'https://test.com'],
50+
['action' => 'http', 'label' => 'Open', 'url' => 'https://test2.com']
51+
],
52+
'click' => 'https://test3.com',
53+
'attach' => 'https://filesrv.lan/space.jpg',
54+
'filename' => 'diskspace.jpg',
55+
'email' => 'me@mail.com',
56+
'cache' => 'no',
57+
'firebase' => 'no'
3058
], $ntfyOptions->toArray());
3159
}
3260
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy