fix: answer null instead of 500 when the export marker is missing

This commit is contained in:
fromme committed 2026-09-30 12:18:59 +02:00
1 parent 8a6ce7606f
commit c2c55bc8b2
4 files changed
+83 -15

No files matched your search

@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace App\Tests\Controller\Api;
use App\Controller\Api\LastUpdateController;
use League\Flysystem\FilesystemOperator;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Container;
class LastUpdateControllerTest extends TestCase
{
public function testReturnsTheMarkerTimestamp(): void
{
self::assertSame('2026-09-22 11:10:15', $this->timestampFor(
"22.09.2026 11:10:15\r\nLetzte \xDCbertragung\r\nAnzahl \xDCbertragene Dateien: 177\r\nVollexport\r\n"
));
}
public function testAMissingMarkerIsNullRatherThanAServerError(): void
{
self::assertNull($this->timestampFor(null));
}
public function testAnEmptyMarkerIsNull(): void
{
self::assertNull($this->timestampFor(''));
}
public function testAnUnparseableMarkerIsNull(): void
{
self::assertNull($this->timestampFor("gestern\r\nLetzte \xDCbertragung\r\nAnzahl \xDCbertragene Dateien: 177\r\n"));
}
private function timestampFor(?string $marker): ?string
{
$storage = $this->createStub(FilesystemOperator::class);
$storage->method('fileExists')->willReturn(null !== $marker);
$storage->method('read')->willReturn((string) $marker);
$controller = new LastUpdateController($storage);
$controller->setContainer(new Container());
$body = json_decode((string) $controller->index()->getContent(), true);
self::assertArrayHasKey('timestamp', $body);
return $body['timestamp'];
}
}