getCaller()); // Create a person $person = new Person(); // Create a caller history with the person $callerHistory = new CallerHistory($person, $ticket); // The ticket should now return the person as the caller self::assertSame($person, $ticket->getCaller()); // Create a third party $thirdParty = new ThirdParty(); // Create a new caller history with the third party $callerHistory2 = new CallerHistory($thirdParty, $ticket); // End the first caller history $callerHistory->setEndDate(new \DateTimeImmutable()); // The ticket should now return the third party as the caller self::assertSame($thirdParty, $ticket->getCaller()); // End the second caller history $callerHistory2->setEndDate(new \DateTimeImmutable()); // The ticket should now return null as there is no active caller self::assertNull($ticket->getCaller()); } public function testGetCallerHistories(): void { $ticket = new Ticket(); // Initially, there should be no caller histories self::assertCount(0, $ticket->getCallerHistories()); // Create a caller history $callerHistory = new CallerHistory(new Person(), $ticket); // The ticket should now have one caller history self::assertCount(1, $ticket->getCallerHistories()); self::assertSame($callerHistory, $ticket->getCallerHistories()->first()); // Create another caller history $callerHistory2 = new CallerHistory(new ThirdParty(), $ticket); // The ticket should now have two caller histories self::assertCount(2, $ticket->getCallerHistories()); } }