Steuerkram/tests/47_SystemEventsTest.php
2026-06-29 18:21:05 +02:00

43 lines
1.6 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
use Steuerkram\Models\EventLog;
class SystemEventsTest extends TestCase
{
protected string $testName = 'Test 47: EventLog – Einträge schreiben und lesen';
public function run(): void
{
$channel = 'test-' . uniqid();
// Kein Eintrag initial
$before = EventLog::findByChannel($channel);
$this->assertEquals(0, count($before), 'Kanal initial leer');
// Eintrag anlegen
EventLog::add($channel, 'Importiert: test.pdf → Beleg TST-0001');
EventLog::add($channel, 'Duplikat (Beleg TST-0001): test.pdf');
EventLog::add($channel, 'FEHLER beim Download: fehler.pdf');
$entries = EventLog::findByChannel($channel);
$this->assertEquals(3, count($entries), 'Drei Einträge vorhanden');
// Neueste zuerst (höchste id zuletzt hinzugefügt)
$this->assertEquals('FEHLER beim Download: fehler.pdf', $entries[0]['message'], 'Neuester Eintrag zuerst');
$this->assertEquals($channel, $entries[0]['channel'], 'Kanal korrekt gesetzt');
// created_at vorhanden und parseable
$ts = strtotime($entries[0]['created_at']);
$this->assert($ts > 0, 'created_at ist ein gültiges Datum');
// Limit wird eingehalten
$limited = EventLog::findByChannel($channel, 2);
$this->assertEquals(2, count($limited), 'Limit 2 wird eingehalten');
// Anderer Kanal bleibt unberührt
$other = EventLog::findByChannel('other-channel-' . uniqid());
$this->assertEquals(0, count($other), 'Anderer Kanal ist leer');
}
}