backupscript/tests/Notification/NotificationTest.php

56 lines
1.5 KiB
PHP
Raw Normal View History

2023-07-10 09:20:36 +00:00
<?php
declare(strict_types=1);
namespace App\Tests;
2023-07-03 14:28:53 +00:00
use PHPUnit\Framework\TestCase;
use App\Notification\Notification;
use App\Notification\NotificationInterface;
use PHPUnit\Framework\Attributes\DataProvider;
final class NotificationTest extends TestCase
{
2023-07-10 09:20:36 +00:00
/** @var array<string, string> */
private static array $config = ['type' => 'ntfy', 'domain' => 'https://test.com', 'topic' => 'testing'];
2023-07-03 14:28:53 +00:00
public function testloadSingle(): void
{
$dut = new Notification();
$dut->loadSingle('ntfy', self::$config);
$this->assertEquals(1, count($dut->getNotifiers()));
$dut->loadSingle('Ntfy', self::$config);
$this->assertEquals(2, count($dut->getNotifiers()));
$dut->loadSingle('NTFY', self::$config);
$this->assertEquals(3, count($dut->getNotifiers()));
$dut->loadSingle('invalid', self::$config);
$this->assertEquals(3, count($dut->getNotifiers()));
}
public function testloadMany(): void
{
$dut = new Notification();
$arr = [];
$arr[] = self::$config;
$arr[] = self::$config;
$arr[] = self::$config;
$arr[] = self::$config;
$dut->loadMany($arr);
$this->assertEquals(4, count($dut->getNotifiers()));
}
public function testSend(): void
{
$dut = new Notification();
$mock = $this->createMock(NotificationInterface::class);
$dut->addNotifier($mock);
$mock->expects($this->once())->method('send');
$dut->send('title', 'topic');
}
2023-07-10 09:20:36 +00:00
}