test(dump): cover filename parsing and MySQL variant detection
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace AeonDumpManager\Tests\Service;
|
||||
|
||||
use AeonDumpManager\Service\DumpFilenameParser;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DumpFilenameParserTest extends TestCase
|
||||
{
|
||||
private DumpFilenameParser $parser;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->parser = new DumpFilenameParser();
|
||||
}
|
||||
|
||||
public function testFormatProducesExpectedPattern(): void
|
||||
{
|
||||
$dateTime = new \DateTimeImmutable('2026-09-14 15:04:05');
|
||||
|
||||
self::assertSame('dump_2026-09-14_15-04-05.sql.gz', $this->parser->format($dateTime));
|
||||
}
|
||||
|
||||
public function testParseRoundTripsWithFormat(): void
|
||||
{
|
||||
$dateTime = new \DateTimeImmutable('2026-09-14 15:04:05');
|
||||
$filename = $this->parser->format($dateTime);
|
||||
|
||||
self::assertEquals($dateTime, $this->parser->parse($filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidFilenameProvider
|
||||
*/
|
||||
public function testParseRejectsInvalidFilenames(string $filename): void
|
||||
{
|
||||
self::assertNull($this->parser->parse($filename));
|
||||
}
|
||||
|
||||
public static function invalidFilenameProvider(): iterable
|
||||
{
|
||||
yield 'wrong extension' => ['dump_2026-09-14_15-04-05.sql'];
|
||||
yield 'no prefix' => ['2026-09-14_15-04-05.sql.gz'];
|
||||
yield 'path traversal' => ['../dump_2026-09-14_15-04-05.sql.gz'];
|
||||
yield 'garbage' => ['not-a-dump.sql.gz'];
|
||||
yield 'empty' => [''];
|
||||
}
|
||||
|
||||
public function testIsValid(): void
|
||||
{
|
||||
self::assertTrue($this->parser->isValid('dump_2026-09-14_15-04-05.sql.gz'));
|
||||
self::assertFalse($this->parser->isValid('../etc/passwd'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace AeonDumpManager\Tests\Service;
|
||||
|
||||
use AeonDumpManager\Service\MySqlVariant;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class MySqlVariantTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider versionProvider
|
||||
*/
|
||||
public function testIsMariaDb(string $version, bool $expected): void
|
||||
{
|
||||
self::assertSame($expected, MySqlVariant::isMariaDb($version));
|
||||
}
|
||||
|
||||
public static function versionProvider(): iterable
|
||||
{
|
||||
yield 'plain mysql' => ['8.0.36', false];
|
||||
yield 'mariadb with legacy prefix' => ['5.5.5-10.11.2-MariaDB', true];
|
||||
yield 'mariadb without legacy prefix' => ['10.11.2-MariaDB', true];
|
||||
yield 'mariadb lowercase' => ['10.11.2-mariadb', true];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user