This commit is contained in:
@ -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');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user