Static analysis of unittest code.
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:
10
Makefile
10
Makefile
@ -3,13 +3,13 @@ analyze: analyze-yaml analyze-phpmd analyze-phpstan analyze-psalm analyze-phpcs
|
||||
analyze-yaml:
|
||||
vendor/bin/yaml-lint *.yml
|
||||
analyze-phpmd:
|
||||
vendor/bin/phpmd src text cleancode,codesize,controversial,design,naming,unusedcode
|
||||
vendor/bin/phpmd src,tests text cleancode,codesize,controversial,design,naming,unusedcode
|
||||
analyze-phpstan:
|
||||
vendor/bin/phpstan analyze --level=8 --error-format=raw src/ backup
|
||||
vendor/bin/phpstan analyze --level=8 --error-format=raw src/ backup tests
|
||||
analyze-psalm:
|
||||
vendor/bin/psalm --no-cache
|
||||
analyze-phpcs:
|
||||
vendor/bin/phpcs src backup --report=emacs --standard=PSR12
|
||||
vendor/bin/phpcs src backup tests --report=emacs --standard=PSR12
|
||||
|
||||
docs:
|
||||
./phpDocumentor.phar --setting=graphs.enabled=true
|
||||
@ -19,7 +19,7 @@ install:
|
||||
install-dev:
|
||||
php composer.phar install
|
||||
test:
|
||||
vendor/bin/phpunit tests
|
||||
vendor/bin/phpunit tests --display-warnings
|
||||
test-coverage:
|
||||
vendor/bin/phpunit tests --testdox --coverage-filter src --coverage-html output/coverage --coverage-text --branch-coverage --testdox-html output/test.html
|
||||
vendor/bin/phpunit tests --testdox --coverage-filter src --coverage-html output/coverage --coverage-text --path-coverage --testdox-html output/test.html
|
||||
|
@ -1,27 +1,31 @@
|
||||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use App\CommandBackup;
|
||||
|
||||
class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
||||
#[CoversClass(CommandBackup::class)]
|
||||
final class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
mkdir('temp');
|
||||
mkdir('temp/destination');
|
||||
exec('rclone test makefiles temp/source 2>&1');
|
||||
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
exec('rclone purge temp 2>&1', $output);
|
||||
exec('rclone purge temp 2>&1');
|
||||
}
|
||||
|
||||
|
||||
public function testBadConfig()
|
||||
public function testBadConfig(): void
|
||||
{
|
||||
$applicationd = new Application('backup', "1.1.1");
|
||||
|
||||
@ -30,15 +34,14 @@ class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$command = $applicationd->find('backup');
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(['config'=>"bad_file"]);
|
||||
$commandTester->execute(['config' => "bad_file"]);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertStringContainsString('[ERROR] Configuration error:File "bad_file" does not exist.', $output);
|
||||
}
|
||||
|
||||
public function testGoodConfig()
|
||||
public function testGoodConfig(): void
|
||||
{
|
||||
|
||||
$applicationd = new Application('backup', "1.1.1");
|
||||
|
||||
$applicationd->add(new CommandBackup());
|
||||
@ -46,13 +49,13 @@ class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$command = $applicationd->find('backup');
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(['config'=>"config.example.yml"]);
|
||||
$commandTester->execute(['config' => "config.example.yml"]);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertStringContainsString('[OK] Complete ', $output);
|
||||
}
|
||||
|
||||
public function testNoDestinationFolder()
|
||||
public function testNoDestinationFolder(): void
|
||||
{
|
||||
exec('rclone purge temp/destination 2>&1', $output);
|
||||
$applicationd = new Application('backup', "1.1.1");
|
||||
@ -62,13 +65,13 @@ class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$command = $applicationd->find('backup');
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(['config'=>"config.example.yml"]);
|
||||
$commandTester->execute(['config' => "config.example.yml"]);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertStringContainsString('[OK] Complete ', $output);
|
||||
}
|
||||
|
||||
public function testNoSourceFolder()
|
||||
public function testNoSourceFolder(): void
|
||||
{
|
||||
exec('rclone purge temp/source 2>&1', $output);
|
||||
$applicationd = new Application('backup', "1.1.1");
|
||||
@ -78,9 +81,9 @@ class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$command = $applicationd->find('backup');
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(['config'=>"config.example.yml"]);
|
||||
$commandTester->execute(['config' => "config.example.yml"]);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertStringContainsString('[OK] Complete ', $output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,19 @@
|
||||
<?php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use App\CommandShow;
|
||||
|
||||
class CommandShowTest extends \PHPUnit\Framework\TestCase
|
||||
#[CoversClass(CommandShow::class)]
|
||||
final class CommandShowTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testInvalidConfig()
|
||||
public function testInvalidConfig(): void
|
||||
{
|
||||
|
||||
$applicationd = new Application('backup', "1.1.1");
|
||||
@ -16,16 +23,16 @@ class CommandShowTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$command = $applicationd->find('show');
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(['config'=>"bad_file"]);
|
||||
$commandTester->execute(['config' => "bad_file"]);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertStringContainsString('[ERROR] Configuration error: File "bad_file" does not exist.', $output);
|
||||
}
|
||||
|
||||
public function testGoodConfig()
|
||||
public function testGoodConfig(): void
|
||||
{
|
||||
exec('rclone test makefiles temp/source 2>&1');
|
||||
|
||||
|
||||
$applicationd = new Application('backup', "1.1.1");
|
||||
|
||||
$applicationd->add(new CommandShow());
|
||||
@ -33,13 +40,11 @@ class CommandShowTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$command = $applicationd->find('show');
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(['config'=>"config.example.yml"]);
|
||||
$commandTester->execute(['config' => "config.example.yml"]);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertStringContainsString('Example', $output);
|
||||
$this->assertStringContainsString('temp/source', $output);
|
||||
$this->assertStringContainsString('temp/destination', $output);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\Rclone\Rclone;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@ -7,15 +11,12 @@ final class RcloneTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
if(!is_dir('temp')) {
|
||||
mkdir('temp');
|
||||
}
|
||||
exec('rclone test makefiles temp/source 2>&1');
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
exec('rclone purge temp 2>&1', $output);
|
||||
exec('rclone purge temp 2>&1');
|
||||
}
|
||||
|
||||
|
||||
@ -23,20 +24,20 @@ final class RcloneTest extends TestCase
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$rclone = new Rclone('invalid');
|
||||
$this->assertString('', $rclone->getVersion());
|
||||
$this->assertEquals('', $rclone->getVersion());
|
||||
}
|
||||
|
||||
public function testRcloneInvalidVersion(): void
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$rclone = new Rclone('uname');
|
||||
$this->assertString('', $rclone->getVersion());
|
||||
$this->assertEquals('', $rclone->getVersion());
|
||||
}
|
||||
|
||||
public function testRcloneValidVersion(): void
|
||||
{
|
||||
$rclone = new Rclone();
|
||||
$this->assertStringContainsString('rclone', $rclone->getVersion());
|
||||
$this->assertStringStartsWith('rclone', $rclone->getVersion());
|
||||
}
|
||||
|
||||
public function testRcloneSize(): void
|
||||
@ -54,16 +55,16 @@ final class RcloneTest extends TestCase
|
||||
public function testRcloneCopy(): void
|
||||
{
|
||||
$rclone = new Rclone();
|
||||
$result = $rclone->copy('temp/source','temp/destination');
|
||||
$rclone->copy('temp/source', 'temp/destination');
|
||||
$this->assertDirectoryExists('temp/destination');
|
||||
|
||||
$rclone = new Rclone();
|
||||
$result = $rclone->copy('temp/source','temp/destination',['bwlimit'=>'6M']);
|
||||
$rclone->copy('temp/source', 'temp/destination', ['bwlimit' => '6M']);
|
||||
$this->assertDirectoryExists('temp/destination');
|
||||
|
||||
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage("ERROR");
|
||||
$result = $rclone->copy('temp/bogus-source','temp/bogus-destination');
|
||||
$rclone->copy('temp/bogus-source', 'temp/bogus-destination');
|
||||
$this->assertDirectoryDoesNotExist('temp/bogus-destination');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user