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:
|
analyze-yaml:
|
||||||
vendor/bin/yaml-lint *.yml
|
vendor/bin/yaml-lint *.yml
|
||||||
analyze-phpmd:
|
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:
|
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:
|
analyze-psalm:
|
||||||
vendor/bin/psalm --no-cache
|
vendor/bin/psalm --no-cache
|
||||||
analyze-phpcs:
|
analyze-phpcs:
|
||||||
vendor/bin/phpcs src backup --report=emacs --standard=PSR12
|
vendor/bin/phpcs src backup tests --report=emacs --standard=PSR12
|
||||||
|
|
||||||
docs:
|
docs:
|
||||||
./phpDocumentor.phar --setting=graphs.enabled=true
|
./phpDocumentor.phar --setting=graphs.enabled=true
|
||||||
@ -19,7 +19,7 @@ install:
|
|||||||
install-dev:
|
install-dev:
|
||||||
php composer.phar install
|
php composer.phar install
|
||||||
test:
|
test:
|
||||||
vendor/bin/phpunit tests
|
vendor/bin/phpunit tests --display-warnings
|
||||||
test-coverage:
|
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\TestCase;
|
||||||
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
use App\CommandBackup;
|
use App\CommandBackup;
|
||||||
|
|
||||||
class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
#[CoversClass(CommandBackup::class)]
|
||||||
|
final class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
mkdir('temp');
|
mkdir('temp');
|
||||||
mkdir('temp/destination');
|
mkdir('temp/destination');
|
||||||
exec('rclone test makefiles temp/source 2>&1');
|
exec('rclone test makefiles temp/source 2>&1');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
exec('rclone purge temp 2>&1', $output);
|
exec('rclone purge temp 2>&1');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testBadConfig(): void
|
||||||
public function testBadConfig()
|
|
||||||
{
|
{
|
||||||
$applicationd = new Application('backup', "1.1.1");
|
$applicationd = new Application('backup', "1.1.1");
|
||||||
|
|
||||||
@ -30,15 +34,14 @@ class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
$command = $applicationd->find('backup');
|
$command = $applicationd->find('backup');
|
||||||
$commandTester = new CommandTester($command);
|
$commandTester = new CommandTester($command);
|
||||||
$commandTester->execute(['config'=>"bad_file"]);
|
$commandTester->execute(['config' => "bad_file"]);
|
||||||
|
|
||||||
$output = $commandTester->getDisplay();
|
$output = $commandTester->getDisplay();
|
||||||
$this->assertStringContainsString('[ERROR] Configuration error:File "bad_file" does not exist.', $output);
|
$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 = new Application('backup', "1.1.1");
|
||||||
|
|
||||||
$applicationd->add(new CommandBackup());
|
$applicationd->add(new CommandBackup());
|
||||||
@ -46,13 +49,13 @@ class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
$command = $applicationd->find('backup');
|
$command = $applicationd->find('backup');
|
||||||
$commandTester = new CommandTester($command);
|
$commandTester = new CommandTester($command);
|
||||||
$commandTester->execute(['config'=>"config.example.yml"]);
|
$commandTester->execute(['config' => "config.example.yml"]);
|
||||||
|
|
||||||
$output = $commandTester->getDisplay();
|
$output = $commandTester->getDisplay();
|
||||||
$this->assertStringContainsString('[OK] Complete ', $output);
|
$this->assertStringContainsString('[OK] Complete ', $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNoDestinationFolder()
|
public function testNoDestinationFolder(): void
|
||||||
{
|
{
|
||||||
exec('rclone purge temp/destination 2>&1', $output);
|
exec('rclone purge temp/destination 2>&1', $output);
|
||||||
$applicationd = new Application('backup', "1.1.1");
|
$applicationd = new Application('backup', "1.1.1");
|
||||||
@ -62,13 +65,13 @@ class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
$command = $applicationd->find('backup');
|
$command = $applicationd->find('backup');
|
||||||
$commandTester = new CommandTester($command);
|
$commandTester = new CommandTester($command);
|
||||||
$commandTester->execute(['config'=>"config.example.yml"]);
|
$commandTester->execute(['config' => "config.example.yml"]);
|
||||||
|
|
||||||
$output = $commandTester->getDisplay();
|
$output = $commandTester->getDisplay();
|
||||||
$this->assertStringContainsString('[OK] Complete ', $output);
|
$this->assertStringContainsString('[OK] Complete ', $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNoSourceFolder()
|
public function testNoSourceFolder(): void
|
||||||
{
|
{
|
||||||
exec('rclone purge temp/source 2>&1', $output);
|
exec('rclone purge temp/source 2>&1', $output);
|
||||||
$applicationd = new Application('backup', "1.1.1");
|
$applicationd = new Application('backup', "1.1.1");
|
||||||
@ -78,9 +81,9 @@ class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
$command = $applicationd->find('backup');
|
$command = $applicationd->find('backup');
|
||||||
$commandTester = new CommandTester($command);
|
$commandTester = new CommandTester($command);
|
||||||
$commandTester->execute(['config'=>"config.example.yml"]);
|
$commandTester->execute(['config' => "config.example.yml"]);
|
||||||
|
|
||||||
$output = $commandTester->getDisplay();
|
$output = $commandTester->getDisplay();
|
||||||
$this->assertStringContainsString('[OK] Complete ', $output);
|
$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\TestCase;
|
||||||
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
use App\CommandShow;
|
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");
|
$applicationd = new Application('backup', "1.1.1");
|
||||||
@ -16,16 +23,16 @@ class CommandShowTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
$command = $applicationd->find('show');
|
$command = $applicationd->find('show');
|
||||||
$commandTester = new CommandTester($command);
|
$commandTester = new CommandTester($command);
|
||||||
$commandTester->execute(['config'=>"bad_file"]);
|
$commandTester->execute(['config' => "bad_file"]);
|
||||||
|
|
||||||
$output = $commandTester->getDisplay();
|
$output = $commandTester->getDisplay();
|
||||||
$this->assertStringContainsString('[ERROR] Configuration error: File "bad_file" does not exist.', $output);
|
$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');
|
exec('rclone test makefiles temp/source 2>&1');
|
||||||
|
|
||||||
$applicationd = new Application('backup', "1.1.1");
|
$applicationd = new Application('backup', "1.1.1");
|
||||||
|
|
||||||
$applicationd->add(new CommandShow());
|
$applicationd->add(new CommandShow());
|
||||||
@ -33,13 +40,11 @@ class CommandShowTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
$command = $applicationd->find('show');
|
$command = $applicationd->find('show');
|
||||||
$commandTester = new CommandTester($command);
|
$commandTester = new CommandTester($command);
|
||||||
$commandTester->execute(['config'=>"config.example.yml"]);
|
$commandTester->execute(['config' => "config.example.yml"]);
|
||||||
|
|
||||||
$output = $commandTester->getDisplay();
|
$output = $commandTester->getDisplay();
|
||||||
$this->assertStringContainsString('Example', $output);
|
$this->assertStringContainsString('Example', $output);
|
||||||
$this->assertStringContainsString('temp/source', $output);
|
$this->assertStringContainsString('temp/source', $output);
|
||||||
$this->assertStringContainsString('temp/destination', $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 PHPUnit\Framework\TestCase;
|
||||||
use App\Notification\Notification;
|
use App\Notification\Notification;
|
||||||
@ -7,7 +11,8 @@ use PHPUnit\Framework\Attributes\DataProvider;
|
|||||||
|
|
||||||
final class NotificationTest extends TestCase
|
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
|
public function testloadSingle(): void
|
||||||
{
|
{
|
||||||
@ -47,4 +52,4 @@ final class NotificationTest extends TestCase
|
|||||||
$mock->expects($this->once())->method('send');
|
$mock->expects($this->once())->method('send');
|
||||||
$dut->send('title', 'topic');
|
$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 PHPUnit\Framework\TestCase;
|
||||||
use App\Notification\Ntfy;
|
use App\Notification\Ntfy;
|
||||||
use Ntfy\Client;
|
use Ntfy\Client;
|
||||||
use Ntfy\Message;
|
use Ntfy\Message;
|
||||||
use PHPUnit\Framework\Attributes\DataProvider;
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
|
||||||
final class NtfyTest extends TestCase
|
final class NtfyTest extends TestCase
|
||||||
{
|
{
|
||||||
|
private Ntfy $instance;
|
||||||
private ?Ntfy $instance;
|
private MockObject $client;
|
||||||
private object $client;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
@ -18,14 +22,12 @@ final class NtfyTest extends TestCase
|
|||||||
$this->instance = new Ntfy($this->client);
|
$this->instance = new Ntfy($this->client);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(): void
|
/**
|
||||||
{
|
* @SuppressWarnings(PHPMD.StaticAccess)
|
||||||
$this->instance = null;
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
public function testFactory(): void
|
public function testFactory(): void
|
||||||
{
|
{
|
||||||
$config = ['domain'=>'https://test.com', 'topic'=>'something'];
|
$config = ['domain' => 'https://test.com', 'topic' => 'something'];
|
||||||
$instance = Ntfy::factory($config);
|
$instance = Ntfy::factory($config);
|
||||||
$this->assertInstanceOf(Ntfy::class, $instance);
|
$this->assertInstanceOf(Ntfy::class, $instance);
|
||||||
}
|
}
|
||||||
@ -33,10 +35,10 @@ final class NtfyTest extends TestCase
|
|||||||
public function testSend(): void
|
public function testSend(): void
|
||||||
{
|
{
|
||||||
$this->client->expects($this->once())->method('send')->with($this->isInstanceOf(Message::class));
|
$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
|
public static function sendBadParameterProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -49,9 +51,9 @@ final class NtfyTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[DataProvider('sendBadParameterProvider')]
|
#[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);
|
$this->instance->send($title, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,6 +64,7 @@ final class NtfyTest extends TestCase
|
|||||||
$this->assertEquals($topic, $this->instance->getTopic());
|
$this->assertEquals($topic, $this->instance->getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return array<int, array<int, string>> */
|
||||||
public static function topicBadParameterProvider(): array
|
public static function topicBadParameterProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -72,10 +75,9 @@ final class NtfyTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[DataProvider('topicBadParameterProvider')]
|
#[DataProvider('topicBadParameterProvider')]
|
||||||
public function testSetTopicInvalidParameters( $topic ): void
|
public function testSetTopicInvalidParameters(string $topic): void
|
||||||
{
|
{
|
||||||
$this->expectException(InvalidArgumentException::class);
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
$this->instance->setTopic( $topic );
|
$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 App\Rclone\Rclone;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
@ -7,15 +11,12 @@ final class RcloneTest extends TestCase
|
|||||||
{
|
{
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
if(!is_dir('temp')) {
|
|
||||||
mkdir('temp');
|
|
||||||
}
|
|
||||||
exec('rclone test makefiles temp/source 2>&1');
|
exec('rclone test makefiles temp/source 2>&1');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(): void
|
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);
|
$this->expectException(\Exception::class);
|
||||||
$rclone = new Rclone('invalid');
|
$rclone = new Rclone('invalid');
|
||||||
$this->assertString('', $rclone->getVersion());
|
$this->assertEquals('', $rclone->getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRcloneInvalidVersion(): void
|
public function testRcloneInvalidVersion(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\Exception::class);
|
$this->expectException(\Exception::class);
|
||||||
$rclone = new Rclone('uname');
|
$rclone = new Rclone('uname');
|
||||||
$this->assertString('', $rclone->getVersion());
|
$this->assertEquals('', $rclone->getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRcloneValidVersion(): void
|
public function testRcloneValidVersion(): void
|
||||||
{
|
{
|
||||||
$rclone = new Rclone();
|
$rclone = new Rclone();
|
||||||
$this->assertStringContainsString('rclone', $rclone->getVersion());
|
$this->assertStringStartsWith('rclone', $rclone->getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRcloneSize(): void
|
public function testRcloneSize(): void
|
||||||
@ -54,16 +55,16 @@ final class RcloneTest extends TestCase
|
|||||||
public function testRcloneCopy(): void
|
public function testRcloneCopy(): void
|
||||||
{
|
{
|
||||||
$rclone = new Rclone();
|
$rclone = new Rclone();
|
||||||
$result = $rclone->copy('temp/source','temp/destination');
|
$rclone->copy('temp/source', 'temp/destination');
|
||||||
$this->assertDirectoryExists('temp/destination');
|
$this->assertDirectoryExists('temp/destination');
|
||||||
|
|
||||||
$rclone = new Rclone();
|
$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->assertDirectoryExists('temp/destination');
|
||||||
|
|
||||||
$this->expectException(\Exception::class);
|
$this->expectException(\Exception::class);
|
||||||
$this->expectExceptionMessage("ERROR");
|
$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');
|
$this->assertDirectoryDoesNotExist('temp/bogus-destination');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user