More test coverage.
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				ci/woodpecker/push/woodpecker Pipeline was successful
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	ci/woodpecker/push/woodpecker Pipeline was successful
				
			This commit is contained in:
		| @@ -9,7 +9,7 @@ class Notification | ||||
|     /** | ||||
|      * @var NotificationInterface[] $notifiers | ||||
|      */ | ||||
|     public array $notifiers = array(); | ||||
|     private array $notifiers = array(); | ||||
|  | ||||
|     /** | ||||
|      * Load multiple configurations | ||||
| @@ -36,16 +36,31 @@ class Notification | ||||
|             case 'ntfy': | ||||
|             case 'Ntfy': | ||||
|             case 'NTFY': | ||||
|                 $this->notifiers[] = Ntfy::factory($config); | ||||
|                 $this->addNotifier(Ntfy::factory($config)); | ||||
|                 break; | ||||
|             default: | ||||
|                 break; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public function addNotifier(NotificationInterface $instance): void | ||||
|     { | ||||
|         $this->notifiers[] = $instance; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get all active notifiers. | ||||
|      * | ||||
|      * @return NotificationInterface[] All notifiers. | ||||
|      */ | ||||
|     public function getNotifiers(): array | ||||
|     { | ||||
|         return $this->notifiers; | ||||
|     } | ||||
|  | ||||
|     public function send(string $title, string $message): void | ||||
|     { | ||||
|         foreach ($this->notifiers as $notifier) { | ||||
|         foreach ($this->getNotifiers() as $notifier) { | ||||
|             $notifier->send($title, $message); | ||||
|         } | ||||
|     } | ||||
|   | ||||
							
								
								
									
										50
									
								
								tests/Notification/NotificationTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								tests/Notification/NotificationTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | ||||
| <?php declare(strict_types=1); | ||||
|  | ||||
| use PHPUnit\Framework\TestCase; | ||||
| use App\Notification\Notification; | ||||
| use App\Notification\NotificationInterface; | ||||
| use PHPUnit\Framework\Attributes\DataProvider; | ||||
|  | ||||
| final class NotificationTest extends TestCase | ||||
| { | ||||
|     static $config = ['type'=>'ntfy', 'domain'=>'https://test.com', 'topic'=>'testing']; | ||||
|  | ||||
|     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'); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user