More tests and error handling
	
		
			
	
		
	
	
		
	
		
			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:
		@@ -4,14 +4,77 @@ 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
 | 
			
		||||
    {
 | 
			
		||||
        $client = $this->createMock(Client::class);
 | 
			
		||||
        $sut = new Ntfy($client);
 | 
			
		||||
        $client->expects($this->once())->method('send')->with($this->isInstanceOf(Message::class));
 | 
			
		||||
        $sut->send('title','text');
 | 
			
		||||
        $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 );
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user