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); } public function testSavePersistiertAbhakenAlsGegessen(): void { $jetzt = $this->jetzt(); $created = $this->processor()->create(Mahlzeit::anlegen('Bolognese', '', [Wochentag::Mo], 1, $jetzt)); $gegessen = $created->markAsGegessen($jetzt); $this->processor()->save($gegessen); $neu = (new MahlzeitProvider($this->em, new MahlzeitMapper()))->find($created->id); self::assertNotNull($neu); self::assertSame(MahlzeitStatus::Gegessen, $neu->status); self::assertSame($jetzt, $neu->gegessenAm); self::assertTrue($neu->istGegessen()); } public function testSavePersistiertAufhebenAlsGeplant(): void { $jetzt = $this->jetzt(); $created = $this->processor()->create(Mahlzeit::anlegen('Bolognese', '', [Wochentag::Mo], 1, $jetzt)->markAsGegessen($jetzt)); $geplant = $created->markAsGeplant($jetzt); $this->processor()->save($geplant); $neu = (new MahlzeitProvider($this->em, new MahlzeitMapper()))->find($created->id); self::assertNotNull($neu); self::assertSame(MahlzeitStatus::Geplant, $neu->status); self::assertNull($neu->gegessenAm); self::assertTrue($neu->istGeplant()); } }