createDummyNotifiable($recipient, $firstname, $lastname); $notification = $this->resolveNotification($mailType, $firstname); $notifiable->notifyNow($notification); } private function resolveNotification(MailToTest $mailType, string $firstname): Notification { return match ($mailType) { MailToTest::ValidateAccount => new VerifyEmail($firstname), MailToTest::ForgottenPassword => new ResetPassword('token-test-12345', $firstname), MailToTest::UpdatePassword => new UpdatePassword($firstname), MailToTest::OrderRecap => $this->createNewOrderDummy($firstname), MailToTest::DestroyCustomer => new DestroyCustomer($firstname), MailToTest::DestroyedCustomer => new DestroyedCustomer($firstname), }; } private function createNewOrderDummy(string $firstname): NewOrder { /** @var Order $dummyOrder */ $dummyOrder = Order::factory()->make([ 'customer_id' => 1, 'firstname' => $firstname, 'payementType' => OrderType::check, ]); $dummyItems = SellItem::factory()->count(2)->make()->map(function (SellItem $item) { $item->setRelation('pivot', (object) ['quantity' => 1]); return $item; }); $dummyOrder->setRelation('sellItems', $dummyItems); return new NewOrder($dummyOrder); } private function createDummyNotifiable(Address $sendTo, string $firstname, string $lastname): mixed { $username = "{$firstname} {$lastname}"; return new readonly class ($sendTo, $username, $firstname) implements CanResetPassword { use Notifiable; public object $apiData; public object $api_data; public function __construct( public Address $address, public string $username, string $firstname, ) { $this->api_data = (object) ['firstname' => $firstname]; $this->apiData = $this->api_data; } #[Override] public function getEmailForPasswordReset(): string { return $this->address->address; } #[Override] public function sendPasswordResetNotification($token): void { throw new \BadMethodCallException('Not implemented in testing mock.'); } public function getKey(): int { return 1; } public function getEmailForVerification(): string { return $this->address->address; } public function routeNotificationForMail(): string { return $this->address->address; } }; } }