em, new MahlzeitMapper()); } private function jetzt(): \DateTimeImmutable { return new \DateTimeImmutable('2026-09-18 12:00:00'); } public function testCreatePersistiertUndLiefertMitNeuerId(): void { $m = Mahlzeit::anlegen('Bolognese', 'süß', [Wochentag::Mo, Wochentag::Do], 0, $this->jetzt()); $gespeichert = $this->processor()->create($m); self::assertGreaterThan(0, $gespeichert->id); self::assertCount(1, $this->alleEntitaeten()); $neu = (new MahlzeitProvider($this->em, new MahlzeitMapper()))->find($gespeichert->id); self::assertNotNull($neu); self::assertSame('Bolognese', $neu->name); self::assertSame('süß', $neu->notiz); self::assertSame([Wochentag::Mo, Wochentag::Do], $neu->wochentage()); } public function testSaveAktualisiertBestehendeZeile(): void { $m = Mahlzeit::anlegen('Altes', '', [Wochentag::Mo], 1, $this->jetzt()); $created = $this->processor()->create($m); $geaendert = $created->aktualisieren( name: 'Neues', notiz: 'scharf', wochentage: [Wochentag::Fr], sortOrder: $created->sortOrder, jetzt: $this->jetzt(), ); $gespeichert = $this->processor()->save($geaendert); self::assertSame($created->id, $gespeichert->id); self::assertCount(1, $this->alleEntitaeten()); $neu = (new MahlzeitProvider($this->em, new MahlzeitMapper()))->find($created->id); self::assertNotNull($neu); self::assertSame('Neues', $neu->name); self::assertSame('scharf', $neu->notiz); self::assertSame([Wochentag::Fr], $neu->wochentage()); } public function testSaveMitUnbekannterIdWirft404(): void { $m = Mahlzeit::anlegen('X', '', [], 0, $this->jetzt())->mitId(9999); $this->expectException(MahlzeitNotFoundException::class); $this->processor()->save($m); } public function testDeleteEntferntZeile(): void { $m = Mahlzeit::anlegen('Bolognese', '', [], 1, $this->jetzt()); $created = $this->processor()->create($m); $this->processor()->delete($created); self::assertCount(0, $this->alleEntitaeten()); } public function testDeleteMitUnbekannterIdWirft404(): void { $m = Mahlzeit::anlegen('X', '', [], 0, $this->jetzt())->mitId(9999); $this->expectException(MahlzeitNotFoundException::class); $this->processor()->delete($m); } }