test: assert plugin logs to injected PSR logger
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5f8cc9bdad
commit
8afe30b476
3 files changed
+128
No files matched your search
@@ -0,0 +1,66 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user