More testing. Removed Gitea actions.
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Jens True 2023-07-24 13:32:21 +00:00
parent bc00b36799
commit 9459045e6c
6 changed files with 55 additions and 60 deletions

@ -1,37 +0,0 @@
name: Build and test
run-name: Perform a regular build and test
on: push
jobs:
requirements:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mbstring, xml, curl, zip
tools: composer, phpdoc
coverage: xdebug
- name: Install dependencies
run: |
composer config github-oauth.github.com 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
composer install
wget https://downloads.rclone.org/rclone-current-linux-amd64.deb
dpkg -i rclone-current-linux-amd64.deb
- name: Dry run
run: ./backup show config.example.yml
- name: Static analysis
run: composer analyze
- name: Test
run: composer test-coverage
- uses: actions/upload-artifact@v3
with:
path: output/test.html
- name: Document
run: phpdoc run
# - uses: actions/upload-artifact@v3
# with:
# path: output/docs

@ -54,8 +54,7 @@ class CommandBackup extends Command
return Command::FAILURE; return Command::FAILURE;
} }
$rclone = new Rclone((string)$app->getConfig('rclone.path')); $rclone = new Rclone($app->getLogger()->withName('rclone'), (string)$app->getConfig('rclone.path'));
$rclone->setLogger($app->getLogger()->withName('rclone'));
$notification = new Notification(); $notification = new Notification();
/** @var array<array-key,array<string,string>> */ /** @var array<array-key,array<string,string>> */

@ -4,8 +4,6 @@ declare(strict_types=1);
namespace App\Rclone; namespace App\Rclone;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\Process\Process; use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\Exception\ProcessFailedException;
@ -20,7 +18,10 @@ use Exception;
*/ */
class Rclone class Rclone
{ {
use LoggerAwareTrait; /**
* The logger instance.
*/
protected LoggerInterface $logger;
protected string $rclonePath; protected string $rclonePath;
/** /**
@ -40,10 +41,10 @@ class Rclone
* *
* @param string $rclonePath Relative or absolute path * @param string $rclonePath Relative or absolute path
*/ */
public function __construct(string $rclonePath = "rclone") public function __construct(LoggerInterface $logger, string $rclonePath = "rclone")
{ {
$this->rclonePath = $rclonePath; $this->rclonePath = $rclonePath;
$this->setLogger(new NullLogger()); $this->logger = $logger;
$process = $this->exec('--version'); $process = $this->exec('--version');
if (!$process->isSuccessful()) { if (!$process->isSuccessful()) {
@ -130,22 +131,18 @@ class Rclone
$options $options
) )
); );
if ($this->logger instanceof LoggerInterface) {
$this->logger->info("Execute command", [$process->getCommandLine()]); $this->logger->info("Execute command", [$process->getCommandLine()]);
}
$process->setTimeout(4 * 3600); $process->setTimeout(4 * 3600);
$process->run(); $process->run();
// executes after the command finishes // executes after the command finishes
if (!$process->isSuccessful()) { if (!$process->isSuccessful()) {
if ($this->logger instanceof LoggerInterface) { $this->logger->error("Failed execution");
$this->logger->error("Failed execution");
}
}
if ($this->logger instanceof LoggerInterface) {
$this->logger->info("Return code", [$process->getExitCode()]);
} }
$this->logger->info("Return code", [$process->getExitCode()]);
return $process; return $process;
} }
} }

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Tests; namespace App\Tests;
use App\Rclone\Rclone; use App\Rclone\Rclone;
use Psr\Log\NullLogger;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
final class RcloneTest extends TestCase final class RcloneTest extends TestCase
@ -23,26 +24,26 @@ final class RcloneTest extends TestCase
public function testRclonePath(): void public function testRclonePath(): void
{ {
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
new Rclone('invalid'); new Rclone(new NullLogger(), 'invalid');
$this->fail('Exception was not thrown'); $this->fail('Exception was not thrown');
} }
public function testRcloneInvalidVersion(): void public function testRcloneInvalidVersion(): void
{ {
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
new Rclone('uname'); new Rclone(new NullLogger(), 'uname');
$this->fail('Exception was not thrown'); $this->fail('Exception was not thrown');
} }
public function testRcloneValidVersion(): void public function testRcloneValidVersion(): void
{ {
$rclone = new Rclone(); $rclone = new Rclone(new NullLogger());
$this->assertStringStartsWith('rclone', $rclone->getVersion()); $this->assertStringStartsWith('rclone', $rclone->getVersion());
} }
public function testRcloneSize(): void public function testRcloneSize(): void
{ {
$rclone = new Rclone(); $rclone = new Rclone(new NullLogger());
$size = $rclone->getSize('temp/source'); $size = $rclone->getSize('temp/source');
$this->assertGreaterThan(10000, $size); $this->assertGreaterThan(10000, $size);
@ -54,17 +55,33 @@ final class RcloneTest extends TestCase
public function testRcloneCopy(): void public function testRcloneCopy(): void
{ {
$rclone = new Rclone(); $rclone = new Rclone(new NullLogger());
$rclone->copy('temp/source', 'temp/destination'); $rclone->copy('temp/source', 'temp/destination');
$this->assertDirectoryExists('temp/destination'); $this->assertDirectoryExists('temp/destination');
}
$rclone = new Rclone(); public function testRcloneCopyParam(): void
{
$rclone = new Rclone(new NullLogger());
$rclone->copy('temp/source', 'temp/destination', ['bwlimit' => '6M']); $rclone->copy('temp/source', 'temp/destination', ['bwlimit' => '6M']);
$this->assertDirectoryExists('temp/destination'); $this->assertDirectoryExists('temp/destination');
}
public function testRcloneCopyBad(): void
{
$rclone = new Rclone(new NullLogger());
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
$this->expectExceptionMessage("ERROR"); $this->expectExceptionMessage("ERROR");
$rclone->copy('temp/bogus-source', 'temp/bogus-destination'); $rclone->copy('temp/bogus-source', 'temp/bogus-destination');
$this->fail('Exception was not thrown'); $this->fail('Exception was not thrown');
} }
public function testRcloneCopyBadParam(): void
{
$rclone = new Rclone(new NullLogger());
$this->expectException(\Exception::class);
$this->expectExceptionMessage("ERROR");
$rclone->copy('temp/bogus-source', 'temp/bogus-destination', ['bwlimit' => '6M']);
$this->fail('Exception was not thrown');
}
} }

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace App\Tests; namespace App\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Template\TwigExtension; use App\Template\TwigExtension;
use Twig\TwigFilter; use Twig\TwigFilter;

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace App\Tests;
use PHPUnit\Framework\TestCase;
use App\Template\Twig;
use Twig\TwigFilter;
final class TwigTest extends \PHPUnit\Framework\TestCase
{
public function testInstance(): void
{
$obj = new Twig(['template' => 'start {{ var }} end']);
$template = $obj->load('template');
$output = $template->render(['var' => 'middle']);
$this->assertEquals('start middle end', $output);
}
}