All checks were successful
		
		
	
	ci/woodpecker/push/woodpecker Pipeline was successful
				
			
		
			
				
	
	
		
			80 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			80 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php declare(strict_types=1);
 | 
						|
 | 
						|
use PHPUnit\Framework\TestCase;
 | 
						|
use App\Notification\Ntfy;
 | 
						|
use Ntfy\Client;
 | 
						|
use Ntfy\Message;
 | 
						|
use PHPUnit\Framework\Attributes\DataProvider;
 | 
						|
 | 
						|
final class NtfyTest extends TestCase
 | 
						|
{
 | 
						|
 | 
						|
    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);
 | 
						|
    }
 | 
						|
 | 
						|
    public function testSend(): void
 | 
						|
    {
 | 
						|
        $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 );
 | 
						|
 | 
						|
    }
 | 
						|
} |