Static analysis of unittest code.
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2023-07-10 09:20:36 +00:00
parent 534c8cdbe6
commit 3b9cea1c70
6 changed files with 81 additions and 65 deletions

View File

@ -1,4 +1,8 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace App\Tests;
use PHPUnit\Framework\TestCase;
use App\Notification\Notification;
@ -7,7 +11,8 @@ use PHPUnit\Framework\Attributes\DataProvider;
final class NotificationTest extends TestCase
{
static $config = ['type'=>'ntfy', 'domain'=>'https://test.com', 'topic'=>'testing'];
/** @var array<string, string> */
private static array $config = ['type' => 'ntfy', 'domain' => 'https://test.com', 'topic' => 'testing'];
public function testloadSingle(): void
{
@ -47,4 +52,4 @@ final class NotificationTest extends TestCase
$mock->expects($this->once())->method('send');
$dut->send('title', 'topic');
}
}
}

View File

@ -1,16 +1,20 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace App\Tests;
use PHPUnit\Framework\TestCase;
use App\Notification\Ntfy;
use Ntfy\Client;
use Ntfy\Message;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
final class NtfyTest extends TestCase
{
private ?Ntfy $instance;
private object $client;
private Ntfy $instance;
private MockObject $client;
protected function setUp(): void
{
@ -18,14 +22,12 @@ final class NtfyTest extends TestCase
$this->instance = new Ntfy($this->client);
}
protected function tearDown(): void
{
$this->instance = null;
}
/**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function testFactory(): void
{
$config = ['domain'=>'https://test.com', 'topic'=>'something'];
$config = ['domain' => 'https://test.com', 'topic' => 'something'];
$instance = Ntfy::factory($config);
$this->assertInstanceOf(Ntfy::class, $instance);
}
@ -33,10 +35,10 @@ final class NtfyTest extends TestCase
public function testSend(): void
{
$this->client->expects($this->once())->method('send')->with($this->isInstanceOf(Message::class));
$this->instance->send('title','text');
$this->instance->send('title', 'text');
}
/** @return array<int, array<int, string>> */
public static function sendBadParameterProvider(): array
{
return [
@ -49,9 +51,9 @@ final class NtfyTest extends TestCase
}
#[DataProvider('sendBadParameterProvider')]
public function testSendInvalidParameters($title, $message): void
public function testSendInvalidParameters(string $title, string $message): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->instance->send($title, $message);
}
@ -62,6 +64,7 @@ final class NtfyTest extends TestCase
$this->assertEquals($topic, $this->instance->getTopic());
}
/** @return array<int, array<int, string>> */
public static function topicBadParameterProvider(): array
{
return [
@ -72,10 +75,9 @@ final class NtfyTest extends TestCase
}
#[DataProvider('topicBadParameterProvider')]
public function testSetTopicInvalidParameters( $topic ): void
public function testSetTopicInvalidParameters(string $topic): void
{
$this->expectException(InvalidArgumentException::class);
$this->instance->setTopic( $topic );
$this->expectException(\InvalidArgumentException::class);
$this->instance->setTopic($topic);
}
}
}