51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?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'];
|
|
}
|
|
}
|