diff --git a/.gitignore b/.gitignore index 204291e..9a5a319 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ *.log config.yml *.phar -*.deb \ No newline at end of file +*.deb +.phpunit.result.cache \ No newline at end of file diff --git a/README.md b/README.md index 32ffc87..f682451 100644 --- a/README.md +++ b/README.md @@ -14,5 +14,30 @@ rm phpDocumentor.phar wget https://phpdoc.org/phpDocumentor.phar chmod +x phpDocumentor.phar +# PHP latest for debian +curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x +sudo apt update +sudo apt upgrade +sudo apt install php8.2-cli php8.2-xml php8.2-curl php8.2-zip php8.2-xdebug php8.2-mbstring unzip wget graphviz plantuml + + +# Rclone install +rm rclone-current-linux-amd64.deb +wget https://downloads.rclone.org/rclone-current-linux-amd64.deb +sudo dpkg -i rclone-current-linux-amd64.deb + +# Infection install + +rm infection.phar +wget https://github.com/infection/infection/releases/download/0.27.0/infection.phar +chmod +x infection.phar + +# PHP CopyPasteDetector install +rm phpcpd.phar +wget https://phar.phpunit.de/phpcpd.phar +chmod +x phpcpd.phar + # Test, analyze, metrics, document -./composer.phar test-coverage && ./composer.phar analyze && ./composer.phar metrics && ./composer.phar doc +./composer.phar test-full && ./composer.phar analyze && ./composer.phar metrics && ./composer.phar doc + + diff --git a/composer.json b/composer.json index 61c3b82..dcf54d5 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ }, "scripts": { "test": "vendor/bin/phpunit tests --display-warnings", - "test-coverage": "vendor/bin/phpunit tests --testdox --coverage-filter src --coverage-html output/coverage --coverage-text --path-coverage --testdox-html output/test.html --log-junit output/test.xml ", + "test-full": "vendor/bin/phpunit -c phpunit.full.xml", "metrics": "vendor/bin/phpmetrics --report-html=output/metrics --junit=output/test.xml src/", "docs": "./phpDocumentor.phar --setting=graphs.enabled=true", "analyze": [ diff --git a/infection.json5 b/infection.json5 new file mode 100644 index 0000000..7442996 --- /dev/null +++ b/infection.json5 @@ -0,0 +1,16 @@ +{ + "$schema": "https://raw.githubusercontent.com/infection/infection/0.27.0/resources/schema.json", + "source": { + "directories": [ + "src" + ] + }, + "logs": { + "text": "output/mutation/infection.log", + "html": "output/mutation/infection.html", + "summary": "output/mutation/summary.log", + }, + "mutators": { + "@default": true + } +} \ No newline at end of file diff --git a/install.sh b/install.sh deleted file mode 100755 index 9330f5b..0000000 --- a/install.sh +++ /dev/null @@ -1,14 +0,0 @@ -curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x -sudo apt update -sudo apt upgrade -sudo apt install php8.2-cli php8.2-xml php8.2-curl php8.2-zip php8.2-xdebug php8.2-mbstring unzip wget graphviz plantuml - -./composer.phar self-update - -rm rclone-current-linux-amd64.deb -wget https://downloads.rclone.org/rclone-current-linux-amd64.deb -sudo dpkg -i rclone-current-linux-amd64.deb - -rm phpDocumentor.phar -wget https://phpdoc.org/phpDocumentor.phar -chmod +x phpDocumentor.phar \ No newline at end of file diff --git a/phpunit.full.xml b/phpunit.full.xml new file mode 100644 index 0000000..03ee150 --- /dev/null +++ b/phpunit.full.xml @@ -0,0 +1,36 @@ + + + + tests + + + + + src + backup + + + + + + + + + + + + + + \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..cd2c3ab --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,11 @@ + + + + tests + + + + \ No newline at end of file diff --git a/src/Notification/Ntfy.php b/src/Notification/Ntfy.php index b45c202..9099334 100644 --- a/src/Notification/Ntfy.php +++ b/src/Notification/Ntfy.php @@ -14,8 +14,9 @@ use InvalidArgumentException; */ class Ntfy implements NotificationInterface { - const TOPIC_MAX_LENGTH = 256; - const MESSAGE_MAX_LENGTH = 4096; + public const TOPIC_MAX_LENGTH = 256; + public const TITLE_MAX_LENGTH = 256; + public const MESSAGE_MAX_LENGTH = 4096; private string $topic = 'default'; /** @@ -68,7 +69,7 @@ class Ntfy implements NotificationInterface */ public function send(string $title, string $message): void { - if (!strlen($title) || strlen($title) > self::TOPIC_MAX_LENGTH) { + if (!strlen($title) || strlen($title) > self::TITLE_MAX_LENGTH) { throw new InvalidArgumentException("Invalid title length"); } diff --git a/src/Rclone/Rclone.php b/src/Rclone/Rclone.php index 9634a2e..a9acc7e 100644 --- a/src/Rclone/Rclone.php +++ b/src/Rclone/Rclone.php @@ -18,6 +18,7 @@ use Exception; */ class Rclone { + private const MAX_RUNTIME = 4 * 3600; //4 hours maximum protected string $version = ""; /** @@ -107,7 +108,7 @@ class Rclone * * @return Process Instance. */ - protected function exec(string $command, array $options = array()): Process + private function exec(string $command, array $options = array()): Process { $process = new Process( array_merge( @@ -119,7 +120,7 @@ class Rclone $this->logger->info("Execute command", [$process->getCommandLine()]); - $process->setTimeout(4 * 3600); + $process->setTimeout(self::MAX_RUNTIME); $process->run(); // executes after the command finishes diff --git a/tests/CommandBackupTest.php b/tests/CommandBackupTest.php index c5f67ce..7343d1c 100644 --- a/tests/CommandBackupTest.php +++ b/tests/CommandBackupTest.php @@ -15,14 +15,23 @@ final class CommandBackupTest extends \PHPUnit\Framework\TestCase { protected function setUp(): void { - mkdir('temp'); - mkdir('temp/destination'); - exec('rclone test makefiles temp/source 2>&1'); + if (!is_dir('temp')) { + mkdir('temp'); + } + if (!is_dir('temp/destination')) { + mkdir('temp/destination'); + } + exec('rclone test makefiles --files 10 temp/source 2>&1'); } protected function tearDown(): void { exec('rclone purge temp 2>&1'); + + if (is_dir('temp/destination')) { + rmdir('temp/destination'); + } + if (is_dir("temp")) { rmdir('temp'); } diff --git a/tests/Notification/NtfyTest.php b/tests/Notification/NtfyTest.php index 3af6c8a..747aaad 100644 --- a/tests/Notification/NtfyTest.php +++ b/tests/Notification/NtfyTest.php @@ -42,7 +42,7 @@ final class NtfyTest extends TestCase public function testSendLong(): void { $this->client->expects($this->once())->method('send')->with($this->isInstanceOf(Message::class)); - $this->instance->send(str_repeat("t", Ntfy::TOPIC_MAX_LENGTH), str_repeat("t", Ntfy::MESSAGE_MAX_LENGTH)); + $this->instance->send(str_repeat("t", Ntfy::TITLE_MAX_LENGTH), str_repeat("t", Ntfy::MESSAGE_MAX_LENGTH)); } /** @return array> */ @@ -52,8 +52,8 @@ final class NtfyTest extends TestCase ['', ''], ['', 'text'], ['title', ''], - [str_repeat("t", Ntfy::TOPIC_MAX_LENGTH+1),'text'], - ['title',str_repeat("t", Ntfy::MESSAGE_MAX_LENGTH+1)], + [str_repeat("t", Ntfy::TITLE_MAX_LENGTH + 1), 'text'], + ['title',str_repeat("t", Ntfy::MESSAGE_MAX_LENGTH + 1)], ]; } @@ -80,8 +80,7 @@ final class NtfyTest extends TestCase { return [ [''], - [str_repeat("t", Ntfy::TOPIC_MAX_LENGTH+1)], - [str_repeat("t", Ntfy::MESSAGE_MAX_LENGTH+1)], + [str_repeat("t", Ntfy::TOPIC_MAX_LENGTH + 1)], ]; }