2026-09-25 10:45:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Services\Mail;
|
|
|
|
|
|
|
|
|
|
use App\Enums\MailToTest;
|
|
|
|
|
use App\Enums\Shop\OrderType;
|
|
|
|
|
use App\Models\Order;
|
|
|
|
|
use App\Models\SellItem;
|
|
|
|
|
use App\Notifications\Customer\DestroyCustomer;
|
|
|
|
|
use App\Notifications\Customer\DestroyedCustomer;
|
|
|
|
|
use App\Notifications\Customer\ResetPassword;
|
|
|
|
|
use App\Notifications\Customer\UpdatePassword;
|
|
|
|
|
use App\Notifications\Customer\VerifyEmail;
|
|
|
|
|
use App\Notifications\Shop\NewOrder;
|
|
|
|
|
use Illuminate\Contracts\Auth\CanResetPassword;
|
|
|
|
|
use Illuminate\Mail\Mailables\Address;
|
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
|
use Override;
|
|
|
|
|
|
|
|
|
|
class MailTesterService
|
|
|
|
|
{
|
|
|
|
|
public function send(MailToTest $mailType, Address $recipient, string $firstname, string $lastname): void
|
|
|
|
|
{
|
2026-09-25 16:25:31 +02:00
|
|
|
$notifiable = $this->createDummyNotifiable($recipient, $firstname, $lastname);
|
2026-09-25 10:45:00 +02:00
|
|
|
$notification = $this->resolveNotification($mailType, $firstname);
|
|
|
|
|
|
|
|
|
|
$notifiable->notifyNow($notification);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function resolveNotification(MailToTest $mailType, string $firstname): Notification
|
|
|
|
|
{
|
|
|
|
|
return match ($mailType) {
|
2026-10-19 11:16:32 +02:00
|
|
|
MailToTest::ValidateAccount => new VerifyEmail($firstname),
|
|
|
|
|
MailToTest::ForgottenPassword => new ResetPassword('token-test-12345', $firstname),
|
|
|
|
|
MailToTest::UpdatePassword => new UpdatePassword($firstname),
|
2026-09-25 10:45:00 +02:00
|
|
|
MailToTest::OrderRecap => $this->createNewOrderDummy($firstname),
|
2026-10-19 11:16:32 +02:00
|
|
|
MailToTest::DestroyCustomer => new DestroyCustomer($firstname),
|
|
|
|
|
MailToTest::DestroyedCustomer => new DestroyedCustomer($firstname),
|
2026-09-25 10:45:00 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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]);
|
2026-09-25 16:25:31 +02:00
|
|
|
|
2026-09-25 10:45:00 +02:00
|
|
|
return $item;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$dummyOrder->setRelation('sellItems', $dummyItems);
|
|
|
|
|
|
|
|
|
|
return new NewOrder($dummyOrder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function createDummyNotifiable(Address $sendTo, string $firstname, string $lastname): mixed
|
|
|
|
|
{
|
|
|
|
|
$username = "{$firstname} {$lastname}";
|
|
|
|
|
|
2026-09-25 16:25:31 +02:00
|
|
|
return new readonly class ($sendTo, $username, $firstname) implements CanResetPassword
|
|
|
|
|
{
|
2026-09-25 10:45:00 +02:00
|
|
|
use Notifiable;
|
|
|
|
|
|
|
|
|
|
public object $apiData;
|
2026-09-25 16:25:31 +02:00
|
|
|
|
2026-09-25 10:45:00 +02:00
|
|
|
public object $api_data;
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
public Address $address,
|
|
|
|
|
public string $username,
|
|
|
|
|
string $firstname,
|
|
|
|
|
) {
|
|
|
|
|
$this->api_data = (object) ['firstname' => $firstname];
|
2026-09-25 16:25:31 +02:00
|
|
|
$this->apiData = $this->api_data;
|
2026-09-25 10:45:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[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;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|