You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.3 KiB
PHP
85 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services {
|
|
final class Config
|
|
{
|
|
public static function get($key, $default = null)
|
|
{
|
|
return [
|
|
'mailgun_key' => 'test-key',
|
|
'mailgun_domain' => 'mg.example.test',
|
|
'mailgun_sender' => 'Legacy Name <sender@example.test>',
|
|
'mailgun_endpoint' => 'https://api.mailgun.net',
|
|
][$key] ?? $default;
|
|
}
|
|
}
|
|
|
|
final class SiteName
|
|
{
|
|
public static function defaultName(): string
|
|
{
|
|
return 'Default Site';
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace {
|
|
use App\Services\Mail\Mailgun;
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
require dirname(__DIR__) . '/app/Services/MailSenderIdentity.php';
|
|
require dirname(__DIR__) . '/app/Services/Mail/Base.php';
|
|
require dirname(__DIR__) . '/app/Services/Mail/Mailgun.php';
|
|
|
|
final class MailgunMessagesProbe
|
|
{
|
|
public array $calls = [];
|
|
|
|
public function send($domain, array $message)
|
|
{
|
|
$this->calls[] = compact('domain', 'message');
|
|
return true;
|
|
}
|
|
}
|
|
|
|
final class MailgunClientProbe
|
|
{
|
|
public function __construct(private MailgunMessagesProbe $messages)
|
|
{
|
|
}
|
|
|
|
public function messages(): MailgunMessagesProbe
|
|
{
|
|
return $this->messages;
|
|
}
|
|
}
|
|
|
|
$transport = new Mailgun();
|
|
$messages = new MailgunMessagesProbe();
|
|
$client = new MailgunClientProbe($messages);
|
|
$property = (new ReflectionClass($transport))->getProperty('mg');
|
|
$property->setValue($transport, $client);
|
|
|
|
if (!$transport->send(
|
|
'recipient@example.test',
|
|
'Instance Provisioned',
|
|
'<p>Ready</p>',
|
|
[]
|
|
)) {
|
|
throw new RuntimeException('The Mailgun transport rejected the probe.');
|
|
}
|
|
|
|
$call = $messages->calls[0] ?? null;
|
|
if (!is_array($call)
|
|
|| ($call['domain'] ?? null) !== 'mg.example.test'
|
|
|| ($call['message']['from'] ?? null)
|
|
!== '"Default Site" <sender@example.test>'
|
|
|| ($call['message']['subject'] ?? null) !== 'Instance Provisioned') {
|
|
throw new RuntimeException(
|
|
'Mailgun did not build the final payload from the default site title.'
|
|
);
|
|
}
|
|
|
|
echo 'Mailgun sender identity checks passed.' . PHP_EOL;
|
|
}
|