More tests
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
2023-08-14 14:24:19 +00:00
parent 1d94738b04
commit 31891f3e53
4 changed files with 71 additions and 29 deletions

View File

@ -8,6 +8,7 @@ use PHPUnit\Framework\TestCase;
use App\Notification\Notification;
use App\Notification\NotificationInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use Exception;
final class NotificationTest extends TestCase
{
@ -44,12 +45,43 @@ final class NotificationTest extends TestCase
$this->assertEquals(4, count($dut->getNotifiers()));
}
public function testSend(): void
public function testSendNoNotifier(): void
{
$dut = new Notification();
$mock = $this->createMock(NotificationInterface::class);
$dut->addNotifier($mock);
$mock->expects($this->once())->method('send');
$dut->send('title', 'topic');
$this->assertEquals(0, count($dut->getNotifiers()));
}
public function testSendOneNotifier(): void
{
$dut = new Notification();
$mock1 = $this->createMock(NotificationInterface::class);
$dut->addNotifier($mock1);
$mock1->expects($this->once())->method('send');
$dut->send('title', 'topic');
}
public function testSendMoreNotifiers(): void
{
$dut = new Notification();
$mock1 = $this->createMock(NotificationInterface::class);
$mock2 = $this->createMock(NotificationInterface::class);
$dut->addNotifier($mock1);
$dut->addNotifier($mock2);
$mock1->expects($this->once())->method('send');
$mock2->expects($this->once())->method('send');
$dut->send('title', 'topic');
}
public function testSendErrorInNotifiers(): void
{
$dut = new Notification();
$mock1 = $this->createMock(NotificationInterface::class);
$mock2 = $this->createMock(NotificationInterface::class);
$dut->addNotifier($mock1);
$dut->addNotifier($mock2);
$mock1->expects($this->once())->method('send')->willThrowException(new Exception());
$mock2->expects($this->once())->method('send');
$dut->send('title', 'topic');
}
}