backupscript/tests/Notification/NtfyTest.php

80 lines
2.0 KiB
PHP
Raw Normal View History

2023-06-15 14:10:17 +00:00
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use App\Notification\Ntfy;
use Ntfy\Client;
use Ntfy\Message;
2023-07-03 13:01:31 +00:00
use PHPUnit\Framework\Attributes\DataProvider;
2023-06-16 08:08:09 +00:00
2023-06-15 14:10:17 +00:00
final class NtfyTest extends TestCase
{
2023-07-03 13:01:31 +00:00
private ?Ntfy $instance;
protected function setUp(): void
{
$this->client = $this->createMock(Client::class);
$this->instance = new Ntfy($this->client);
}
protected function tearDown(): void
{
$this->instance = null;
}
public function testFactory(): void
{
$config = ['domain'=>'https://test.com', 'topic'=>'something'];
$instance = Ntfy::factory($config);
$this->assertInstanceOf(Ntfy::class, $instance);
}
2023-06-16 08:08:09 +00:00
public function testSend(): void
2023-06-15 14:10:17 +00:00
{
2023-07-03 13:01:31 +00:00
$this->client->expects($this->once())->method('send')->with($this->isInstanceOf(Message::class));
$this->instance->send('title','text');
}
public static function sendBadParameterProvider(): array
{
return [
['', ''],
['', 'text'],
['title', ''],
[str_repeat("t", 256),'text'],
['title',str_repeat("t", 4096)],
];
}
#[DataProvider('sendBadParameterProvider')]
public function testSendInvalidParameters($title, $message): void
{
$this->expectException(InvalidArgumentException::class);
$this->instance->send($title, $message);
}
public function testSetTopic(): void
{
$topic = "abcdefg";
$this->instance->setTopic($topic);
$this->assertEquals($topic, $this->instance->getTopic());
}
public static function topicBadParameterProvider(): array
{
return [
[''],
[str_repeat("t", 256)],
[str_repeat("t", 4096)],
];
}
#[DataProvider('topicBadParameterProvider')]
public function testSetTopicInvalidParameters( $topic ): void
{
$this->expectException(InvalidArgumentException::class);
$this->instance->setTopic( $topic );
2023-06-15 14:10:17 +00:00
}
}