Files
AeonDumpManager/tests/Service/DumpServiceLoggingTest.php
2026-10-04 00:50:19 +02:00

67 lines
2.1 KiB
PHP

<?php declare(strict_types=1);
namespace AeonDumpManager\Tests\Service;
use AeonDumpManager\Service\DumpBinaryLocator;
use AeonDumpManager\Service\DumpFilenameParser;
use AeonDumpManager\Service\DumpLister;
use AeonDumpManager\Service\DumpService;
use AeonDumpManager\Service\Exception\DumpNotFoundException;
use AeonDumpManager\Tests\Support\RecordingLogger;
use Doctrine\DBAL\Connection;
use League\Flysystem\FilesystemOperator;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Shopware\Core\System\SystemConfig\SystemConfigService;
class DumpServiceLoggingTest extends TestCase
{
private const FILENAME = 'dump_2026-09-14_15-04-05.sql.gz';
private FilesystemOperator&MockObject $filesystem;
private RecordingLogger $logger;
private DumpService $service;
protected function setUp(): void
{
$this->filesystem = $this->createMock(FilesystemOperator::class);
$this->logger = new RecordingLogger();
$this->service = new DumpService(
$this->createMock(DumpLister::class),
$this->filesystem,
$this->createMock(DumpBinaryLocator::class),
$this->createMock(Connection::class),
$this->createMock(SystemConfigService::class),
new DumpFilenameParser(),
$this->logger,
);
}
public function testDeleteLogsInfo(): void
{
$this->filesystem->method('fileExists')->willReturn(true);
$this->filesystem->expects(self::once())->method('delete')->with(DumpLister::path(self::FILENAME));
$this->service->delete(self::FILENAME);
self::assertSame(
[['level' => 'info', 'message' => 'Dump deleted.', 'context' => ['filename' => self::FILENAME]]],
$this->logger->records
);
}
public function testDeleteMissingDumpDoesNotLog(): void
{
$this->filesystem->method('fileExists')->willReturn(false);
try {
$this->service->delete(self::FILENAME);
self::fail('Expected DumpNotFoundException.');
} catch (DumpNotFoundException) {
self::assertSame([], $this->logger->records);
}
}
}