From dd38ac63b76a9d8e46676c1f0394d2391f0ec00f Mon Sep 17 00:00:00 2001 From: spiralbot Date: Fri, 24 Jan 2025 10:35:00 +0000 Subject: [PATCH] Merge pull request #1207: Apply Spiral Code Style --- composer.json | 14 +++---- src/Bootloader/BuilderBootloader.php | 1 - src/Bootloader/MailerBootloader.php | 19 ++++----- src/Config/MailerConfig.php | 2 +- src/Event/MessageNotSent.php | 5 +-- src/Event/MessageSent.php | 5 +-- src/Listener/LoggerListener.php | 17 ++++---- src/MailJob.php | 5 +-- src/MailQueue.php | 7 ++-- src/MessageSerializer.php | 10 ++--- src/Renderer/ViewRenderer.php | 51 ++++++++++++----------- src/TransportResolver.php | 3 +- tests/App/config/mailer.php | 2 +- tests/ConfigTest.php | 22 +++++----- tests/JobTest.php | 33 +++++++-------- tests/JobsQueueTest.php | 12 +++--- tests/QueueTest.php | 60 ++++++++++++++-------------- tests/RenderTest.php | 30 +++++++------- tests/SerializerTest.php | 7 +--- tests/TransportResolverTest.php | 10 ++--- 20 files changed, 152 insertions(+), 163 deletions(-) diff --git a/composer.json b/composer.json index 1a3bcb5..0a1bdeb 100644 --- a/composer.json +++ b/composer.json @@ -35,19 +35,19 @@ "require": { "php": ">=8.1", "ext-json": "*", - "spiral/core": "^3.14.10", - "spiral/queue": "^3.14.10", - "spiral/logger": "^3.14.10", - "spiral/mailer": "^3.14.10", - "spiral/views": "^3.14.10", + "spiral/core": "^3.15", + "spiral/queue": "^3.15", + "spiral/logger": "^3.15", + "spiral/mailer": "^3.15", + "spiral/views": "^3.15", "symfony/mailer": "^5.1 || ^6.0 || ^7.0", "psr/event-dispatcher": "^1.0" }, "require-dev": { "phpunit/phpunit": "^10.1", "mockery/mockery": "^1.5", - "spiral/boot": "^3.14.10", - "spiral/stempler-bridge": "^3.14.10", + "spiral/boot": "^3.15", + "spiral/stempler-bridge": "^3.15", "spiral/testing": "^2.8", "vimeo/psalm": "^5.9" }, diff --git a/src/Bootloader/BuilderBootloader.php b/src/Bootloader/BuilderBootloader.php index 67da03d..4d7f582 100644 --- a/src/Bootloader/BuilderBootloader.php +++ b/src/Bootloader/BuilderBootloader.php @@ -18,7 +18,6 @@ final class BuilderBootloader extends Bootloader protected const DEPENDENCIES = [ StemplerBootloader::class, ]; - protected const SINGLETONS = [ RendererInterface::class => ViewRenderer::class, ]; diff --git a/src/Bootloader/MailerBootloader.php b/src/Bootloader/MailerBootloader.php index e804a72..46e54e9 100644 --- a/src/Bootloader/MailerBootloader.php +++ b/src/Bootloader/MailerBootloader.php @@ -6,7 +6,6 @@ use Psr\Container\ContainerInterface; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\LoggerInterface; use Spiral\Boot\Bootloader\Bootloader; use Spiral\Boot\EnvironmentInterface; use Spiral\Config\ConfiguratorInterface; @@ -36,7 +35,6 @@ class MailerBootloader extends Bootloader QueueBootloader::class, BuilderBootloader::class, ]; - protected const SINGLETONS = [ MailJob::class => MailJob::class, SymfonyMailer::class => [self::class, 'mailer'], @@ -47,9 +45,8 @@ class MailerBootloader extends Bootloader ]; public function __construct( - private readonly ConfiguratorInterface $config - ) { - } + private readonly ConfiguratorInterface $config, + ) {} public function init(EnvironmentInterface $env): void { @@ -65,10 +62,10 @@ public function boot(BinderInterface $binder, ContainerInterface $container): vo { $binder->bindSingleton( MailerInterface::class, - static fn (MailerConfig $config, QueueConnectionProviderInterface $provider): MailQueue => new MailQueue( + static fn(MailerConfig $config, QueueConnectionProviderInterface $provider): MailQueue => new MailQueue( $config, - $provider->getConnection($config->getQueueConnection()) - ) + $provider->getConnection($config->getQueueConnection()), + ), ); $registry = $container->get(QueueRegistry::class); @@ -85,7 +82,7 @@ public function mailer(TransportInterface $transport, ?EventDispatcherInterface { return new Mailer( transport: $transport, - dispatcher: $dispatcher + dispatcher: $dispatcher, ); } @@ -96,11 +93,11 @@ protected function initTransportResolver( $defaultTransports = \iterator_to_array(Transport::getDefaultFactories( $dispatcher, null, - $logs?->getLogger('mailer') + $logs?->getLogger('mailer'), )); return new TransportResolver( - new Transport($defaultTransports) + new Transport($defaultTransports), ); } } diff --git a/src/Config/MailerConfig.php b/src/Config/MailerConfig.php index c98e94b..71e2087 100644 --- a/src/Config/MailerConfig.php +++ b/src/Config/MailerConfig.php @@ -16,7 +16,7 @@ public function __construct( 'from' => '', 'queue' => null, 'queueConnection' => null, - ] + ], ) { parent::__construct($config); } diff --git a/src/Event/MessageNotSent.php b/src/Event/MessageNotSent.php index c4872bc..8e2940a 100644 --- a/src/Event/MessageNotSent.php +++ b/src/Event/MessageNotSent.php @@ -10,7 +10,6 @@ final class MessageNotSent { public function __construct( public readonly Email $message, - public readonly \Throwable $exception - ) { - } + public readonly \Throwable $exception, + ) {} } diff --git a/src/Event/MessageSent.php b/src/Event/MessageSent.php index b52b40a..442351d 100644 --- a/src/Event/MessageSent.php +++ b/src/Event/MessageSent.php @@ -9,7 +9,6 @@ final class MessageSent { public function __construct( - public readonly Email $message - ) { - } + public readonly Email $message, + ) {} } diff --git a/src/Listener/LoggerListener.php b/src/Listener/LoggerListener.php index 89bf8f2..d7eca35 100644 --- a/src/Listener/LoggerListener.php +++ b/src/Listener/LoggerListener.php @@ -13,9 +13,8 @@ final class LoggerListener { public function __construct( - private readonly LoggerInterface $logger - ) { - } + private readonly LoggerInterface $logger, + ) {} public function onMessageSent(MessageSent $event): void { @@ -23,9 +22,9 @@ public function onMessageSent(MessageSent $event): void \sprintf( 'Sent `%s` to "%s"', $event->message->getSubject(), - \implode('", "', $this->getRecipients($event->message)) + \implode('", "', $this->getRecipients($event->message)), ), - ['emails' => $this->getRecipients($event->message)] + ['emails' => $this->getRecipients($event->message)], ); } @@ -36,17 +35,17 @@ public function onMessageNotSent(MessageNotSent $event): void 'Failed to send `%s` to "%s": %s', $event->message->getSubject(), \implode('", "', $this->getRecipients($event->message)), - $event->exception->getMessage() + $event->exception->getMessage(), ), - ['emails' => $this->getRecipients($event->message)] + ['emails' => $this->getRecipients($event->message)], ); } private function getRecipients(Email $message): array { return \array_map( - static fn (Address $address): string => $address->toString(), - \array_merge($message->getTo(), $message->getCc(), $message->getBcc()) + static fn(Address $address): string => $address->toString(), + \array_merge($message->getTo(), $message->getCc(), $message->getBcc()), ); } } diff --git a/src/MailJob.php b/src/MailJob.php index edaad9e..406dad8 100644 --- a/src/MailJob.php +++ b/src/MailJob.php @@ -20,9 +20,8 @@ public function __construct( private readonly MailerConfig $config, private readonly SymfonyMailer $mailer, private readonly RendererInterface $renderer, - private readonly ?EventDispatcherInterface $dispatcher = null - ) { - } + private readonly ?EventDispatcherInterface $dispatcher = null, + ) {} /** * @throws TransportExceptionInterface diff --git a/src/MailQueue.php b/src/MailQueue.php index e60d410..e662952 100644 --- a/src/MailQueue.php +++ b/src/MailQueue.php @@ -16,9 +16,8 @@ final class MailQueue implements MailerInterface public function __construct( private readonly MailerConfig $config, - private readonly QueueInterface $queue - ) { - } + private readonly QueueInterface $queue, + ) {} public function send(MessageInterface ...$message): void { @@ -28,7 +27,7 @@ public function send(MessageInterface ...$message): void $this->queue->push( self::JOB_NAME, MessageSerializer::pack($msg), - $options->withDelay($msg->getOptions()['delay'] ?? null) + $options->withDelay($msg->getOptions()['delay'] ?? null), ); } } diff --git a/src/MessageSerializer.php b/src/MessageSerializer.php index c69b6cb..c10725e 100644 --- a/src/MessageSerializer.php +++ b/src/MessageSerializer.php @@ -9,11 +9,6 @@ final class MessageSerializer { - public function serialize(string $jobType, array $payload): string - { - return \json_encode($payload, JSON_THROW_ON_ERROR); - } - public static function pack(MessageInterface $message): array { return [ @@ -45,4 +40,9 @@ public static function unpack(array $payload): MessageInterface return $message; } + + public function serialize(string $jobType, array $payload): string + { + return \json_encode($payload, JSON_THROW_ON_ERROR); + } } diff --git a/src/Renderer/ViewRenderer.php b/src/Renderer/ViewRenderer.php index 5a3c45e..e07dd3f 100644 --- a/src/Renderer/ViewRenderer.php +++ b/src/Renderer/ViewRenderer.php @@ -14,8 +14,29 @@ final class ViewRenderer implements RendererInterface { public function __construct( - private readonly ViewsInterface $views - ) { + private readonly ViewsInterface $views, + ) {} + + /** + * Copy-pasted form https://stackoverflow.com/a/20806227 + * Make sure the subject is ASCII-clean + * + * @param string $subject Subject to encode + * @return string Encoded subject + */ + public static function escapeSubject(string $subject): string + { + if (!preg_match('/[^\x20-\x7e]/', $subject)) { + // ascii-only subject, return as-is + return $subject; + } + + // Subject is non-ascii, needs encoding + $encoded = \base64_encode($subject); + $prefix = '=?UTF-8?B?'; + $suffix = '?='; + + return $prefix . \str_replace("=\r\n", $suffix . "\r\n " . $prefix, $encoded) . $suffix; } public function render(MessageInterface $message): Email @@ -26,7 +47,7 @@ public function render(MessageInterface $message): Email throw new MailerException( \sprintf('Invalid email template `%s`: %s', $message->getSubject(), $e->getMessage()), $e->getCode(), - $e + $e, ); } @@ -47,32 +68,10 @@ public function render(MessageInterface $message): Email throw new MailerException( \sprintf('Unable to render email `%s`: %s', $message->getSubject(), $e->getMessage()), $e->getCode(), - $e + $e, ); } return $msg; } - - /** - * Copy-pasted form https://stackoverflow.com/a/20806227 - * Make sure the subject is ASCII-clean - * - * @param string $subject Subject to encode - * @return string Encoded subject - */ - public static function escapeSubject(string $subject): string - { - if (!preg_match('/[^\x20-\x7e]/', $subject)) { - // ascii-only subject, return as-is - return $subject; - } - - // Subject is non-ascii, needs encoding - $encoded = \base64_encode($subject); - $prefix = '=?UTF-8?B?'; - $suffix = '?='; - - return $prefix . \str_replace("=\r\n", $suffix . "\r\n " . $prefix, $encoded) . $suffix; - } } diff --git a/src/TransportResolver.php b/src/TransportResolver.php index 947ae63..b1cda97 100644 --- a/src/TransportResolver.php +++ b/src/TransportResolver.php @@ -16,8 +16,7 @@ final class TransportResolver implements TransportResolverInterface, TransportRe public function __construct( private readonly Transport $transport, - ) { - } + ) {} public function registerTransport(TransportFactoryInterface $factory): void { diff --git a/tests/App/config/mailer.php b/tests/App/config/mailer.php index 2d8aea9..124426b 100644 --- a/tests/App/config/mailer.php +++ b/tests/App/config/mailer.php @@ -5,5 +5,5 @@ return [ 'dsn' => 'smtp://user:pass@smtp.example.com', 'queue' => 'local', - 'from' => 'test@spiral.framework' + 'from' => 'test@spiral.framework', ]; diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 1d7f35b..3f14f35 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -19,10 +19,10 @@ public function testConfig(): void 'queueConnection' => 'foo', ]); - $this->assertSame('mailer-dsn', $cfg->getDSN()); - $this->assertSame('admin@spiral.dev', $cfg->getFromAddress()); - $this->assertSame('emails', $cfg->getQueue()); - $this->assertSame('foo', $cfg->getQueueConnection()); + self::assertSame('mailer-dsn', $cfg->getDSN()); + self::assertSame('admin@spiral.dev', $cfg->getFromAddress()); + self::assertSame('emails', $cfg->getQueue()); + self::assertSame('foo', $cfg->getQueueConnection()); } public function testDefaultConfig(): void @@ -36,10 +36,10 @@ public function testDefaultConfig(): void 'queueConnection' => $env->get('MAILER_QUEUE_CONNECTION'), ]); - $this->assertSame('', $config->getDSN()); - $this->assertSame('Spiral ', $config->getFromAddress()); - $this->assertSame('local', $config->getQueue()); - $this->assertNull($config->getQueueConnection()); + self::assertSame('', $config->getDSN()); + self::assertSame('Spiral ', $config->getFromAddress()); + self::assertSame('local', $config->getQueue()); + self::assertNull($config->getQueueConnection()); } public function testDefaultConfigWithQueue(): void @@ -50,7 +50,7 @@ public function testDefaultConfigWithQueue(): void 'queue' => $env->get('MAILER_QUEUE', 'local'), ]); - $this->assertSame('emails', $config->getQueue()); + self::assertSame('emails', $config->getQueue()); } public function testQueueWithNull(): void @@ -59,12 +59,12 @@ public function testQueueWithNull(): void 'queue' => null, ]); - $this->assertNull($config->getQueue()); + self::assertNull($config->getQueue()); } public function testGetsQueueConnectionWithoutKey(): void { $cfg = new MailerConfig(); - $this->assertNull($cfg->getQueueConnection()); + self::assertNull($cfg->getQueueConnection()); } } diff --git a/tests/JobTest.php b/tests/JobTest.php index 18e0e40..9fa1e4c 100644 --- a/tests/JobTest.php +++ b/tests/JobTest.php @@ -23,17 +23,10 @@ class JobTest extends TestCase { /** @var MailerInterface */ protected $mailer; + /** @var RendererInterface */ protected $renderer; - public function setUp(): void - { - parent::setUp(); - - $this->mailer = m::mock(MailerInterface::class); - $this->renderer = m::mock(RendererInterface::class); - } - public function testHandler(): void { $email = $this->getEmail(); @@ -45,7 +38,7 @@ public function testHandler(): void $this->getHandler()->handle( MailQueue::JOB_NAME, 'id', - json_encode(MessageSerializer::pack($this->getMail())) + json_encode(MessageSerializer::pack($this->getMail())), ); } @@ -61,7 +54,7 @@ public function testHandlerError(): void $this->getHandler()->handle( MailQueue::JOB_NAME, 'id', - json_encode(MessageSerializer::pack($this->getMail())) + json_encode(MessageSerializer::pack($this->getMail())), ); } catch (TransportException) { } @@ -84,7 +77,7 @@ public function testMessageSentEventShouldBeDispatched(): void $this->getHandler($dispatcher)->handle( MailQueue::JOB_NAME, 'id', - \json_encode(MessageSerializer::pack($this->getMail())) + \json_encode(MessageSerializer::pack($this->getMail())), ); } @@ -106,10 +99,18 @@ public function testMessageNotSentEventShouldBeDispatched(): void $this->getHandler($dispatcher)->handle( MailQueue::JOB_NAME, 'id', - \json_encode(MessageSerializer::pack($this->getMail())) + \json_encode(MessageSerializer::pack($this->getMail())), ); } + protected function setUp(): void + { + parent::setUp(); + + $this->mailer = m::mock(MailerInterface::class); + $this->renderer = m::mock(RendererInterface::class); + } + private function getEmail(): Email { $email = new Email(); @@ -121,10 +122,10 @@ private function getEmail(): Email private function expectRenderer(Email $email): void { $this->renderer->expects('render')->withArgs( - function (Message $message) { - $this->assertSame($message->getSubject(), 'test'); + function (Message $message): bool { + self::assertSame('test', $message->getSubject()); return true; - } + }, )->andReturn($email); } @@ -134,7 +135,7 @@ private function getHandler(?EventDispatcherInterface $dispatcher = null): MailJ new MailerConfig(['from' => 'no-reply@spiral.dev']), $this->mailer, $this->renderer, - $dispatcher + $dispatcher, ); } diff --git a/tests/JobsQueueTest.php b/tests/JobsQueueTest.php index a8e55ac..c38b1fa 100644 --- a/tests/JobsQueueTest.php +++ b/tests/JobsQueueTest.php @@ -23,7 +23,7 @@ public function testQueue(): void new MailerConfig([ 'queue' => 'mailer', ]), - $queue + $queue, ); $mail = new Message('test', ['email@domain.com'], ['key' => 'value']); @@ -33,13 +33,13 @@ public function testQueue(): void $mail->setBCC('admin2@google.com'); $queue->expects('push')->withArgs( - function ($job, $data, Options $options) use ($mail) { - $this->assertSame(MailQueue::JOB_NAME, $job); - $this->assertSame($data, MessageSerializer::pack($mail)); - $this->assertSame('mailer', $options->getQueue()); + function ($job, $data, Options $options) use ($mail): bool { + self::assertSame(MailQueue::JOB_NAME, $job); + self::assertSame($data, MessageSerializer::pack($mail)); + self::assertSame('mailer', $options->getQueue()); return true; - } + }, ); $mailer->send($mail); diff --git a/tests/QueueTest.php b/tests/QueueTest.php index a779ca6..16a6cac 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -17,22 +17,8 @@ class QueueTest extends TestCase { /** @var m\LegacyMockInterface|m\MockInterface|QueueInterface */ private $queue; - /** @var MailQueue */ - private $mailer; - protected function setUp(): void - { - parent::setUp(); - - $this->queue = m::mock(QueueInterface::class); - - $this->mailer = new MailQueue( - new MailerConfig([ - 'queue' => 'mailer', - ]), - $this->queue - ); - } + private MailQueue $mailer; public function testQueue(): void { @@ -43,14 +29,14 @@ public function testQueue(): void $mail->setBCC('admin2@google.com'); $this->queue->expects('push')->withArgs( - function ($job, $data, Options $options) use ($mail) { - $this->assertSame(MailQueue::JOB_NAME, $job); - $this->assertSame($data, MessageSerializer::pack($mail)); - $this->assertSame('mailer', $options->getQueue()); - $this->assertNull($options->getDelay()); + function ($job, $data, Options $options) use ($mail): bool { + self::assertSame(MailQueue::JOB_NAME, $job); + self::assertSame($data, MessageSerializer::pack($mail)); + self::assertSame('mailer', $options->getQueue()); + self::assertNull($options->getDelay()); return true; - } + }, ); $this->mailer->send($mail); @@ -68,26 +54,40 @@ public function testQueueWithDelay(): void $mail3->setDelay(200); $this->queue->expects('push')->once()->withArgs( - function ($job, $data, Options $options) { - $this->assertSame(30, $options->getDelay()); + function ($job, $data, Options $options): bool { + self::assertSame(30, $options->getDelay()); return true; - } + }, ); $this->queue->expects('push')->once()->withArgs( - function ($job, $data, Options $options) { - $this->assertSame(100, $options->getDelay()); + function ($job, $data, Options $options): bool { + self::assertSame(100, $options->getDelay()); return true; - } + }, ); $this->queue->expects('push')->once()->withArgs( - function ($job, $data, Options $options) { - $this->assertSame(200, $options->getDelay()); + function ($job, $data, Options $options): bool { + self::assertSame(200, $options->getDelay()); return true; - } + }, ); $this->mailer->send($mail1, $mail2, $mail3); } + + protected function setUp(): void + { + parent::setUp(); + + $this->queue = m::mock(QueueInterface::class); + + $this->mailer = new MailQueue( + new MailerConfig([ + 'queue' => 'mailer', + ]), + $this->queue, + ); + } } diff --git a/tests/RenderTest.php b/tests/RenderTest.php index 2c33b99..58bd8b4 100644 --- a/tests/RenderTest.php +++ b/tests/RenderTest.php @@ -31,16 +31,9 @@ public function defineBootloaders(): array public function defineDirectories(string $root): array { return [ - 'root' => __DIR__ . '/App', - 'app' => __DIR__ . '/App' - ] + parent::defineDirectories($root); - } - - public function tearDown(): void - { - foreach (glob(__DIR__ . '/App/runtime/cache/views/*.php') as $file) { - @unlink($file); - } + 'root' => __DIR__ . '/App', + 'app' => __DIR__ . '/App', + ] + parent::defineDirectories($root); } public function testRenderError(): void @@ -53,11 +46,20 @@ public function testRender(): void { $email = $this->send(new Message('email', ['email@domain.com'], ['name' => 'Antony'])); - $this->assertSame('Demo Email', $email->getSubject()); + self::assertSame('Demo Email', $email->getSubject()); $body = $email->getBody()->toString(); - $this->assertStringContainsString('bootstrap.txt', $body); - $this->assertStringContainsString('

Hello, Antony!

', $body); + self::assertStringContainsString('bootstrap.txt', $body); + self::assertStringContainsString('

Hello, Antony!

', $body); + } + + protected function tearDown(): void + { + parent::tearDown(); + + foreach (glob(__DIR__ . '/App/runtime/cache/views/*.php') as $file) { + @unlink($file); + } } private function send(MessageInterface $message): Email @@ -65,7 +67,7 @@ private function send(MessageInterface $message): Email $this->getContainer()->get(MailJob::class)->handle( MailQueue::JOB_NAME, 'id', - json_encode(MessageSerializer::pack($message)) + json_encode(MessageSerializer::pack($message)), ); return $this->getContainer()->get(MailerInterface::class)->getLast(); diff --git a/tests/SerializerTest.php b/tests/SerializerTest.php index f538975..4d063a4 100644 --- a/tests/SerializerTest.php +++ b/tests/SerializerTest.php @@ -21,10 +21,7 @@ public function testSerializeUnserialize(): void $data = MessageSerializer::pack($mail); - $this->assertSame( - ['subject', 'data', 'to', 'cc', 'bcc', 'from', 'replyTo', 'options'], - array_keys($data) - ); - $this->assertEquals($mail, MessageSerializer::unpack($data)); + self::assertSame(['subject', 'data', 'to', 'cc', 'bcc', 'from', 'replyTo', 'options'], array_keys($data)); + self::assertEquals($mail, MessageSerializer::unpack($data)); } } diff --git a/tests/TransportResolverTest.php b/tests/TransportResolverTest.php index f3d1b07..30d4c3c 100644 --- a/tests/TransportResolverTest.php +++ b/tests/TransportResolverTest.php @@ -22,13 +22,13 @@ public function testCanRegisterTransport(): void $transportResolver = new TransportResolver(new Transport([])); $transportResolver->registerTransport($transportFactory); - $this->assertCount(1, $transportResolver->getTransports()); + self::assertCount(1, $transportResolver->getTransports()); } public function testCanResolveRegisteredTransport(): void { $transportFactory = m::mock(TransportFactoryInterface::class); - $arg = fn(Transport\Dsn $dsn) => $dsn->getHost() === 'localhost' and $dsn->getScheme() === 'smtp'; + $arg = static fn(Transport\Dsn $dsn): bool => $dsn->getHost() === 'localhost' and $dsn->getScheme() === 'smtp'; $transportFactory->shouldReceive('supports')->once()->withArgs($arg)->andReturn(true); $transportFactory->shouldReceive('create')->once()->withArgs($arg) @@ -38,13 +38,13 @@ public function testCanResolveRegisteredTransport(): void $transportResolver->registerTransport($transportFactory); - $this->assertSame($transport, $transportResolver->resolve('smtp://localhost')); + self::assertSame($transport, $transportResolver->resolve('smtp://localhost')); } public function testCanResolveRegisteredDefaultTransport(): void { $transportFactory = m::mock(TransportFactoryInterface::class); - $arg = fn(Transport\Dsn $dsn) => $dsn->getHost() === 'localhost' and $dsn->getScheme() === 'smtp'; + $arg = static fn(Transport\Dsn $dsn): bool => $dsn->getHost() === 'localhost' and $dsn->getScheme() === 'smtp'; $transportFactory->shouldReceive('supports')->once()->withArgs($arg)->andReturn(true); $transportFactory->shouldReceive('create')->once()->withArgs($arg) @@ -52,7 +52,7 @@ public function testCanResolveRegisteredDefaultTransport(): void $transportResolver = new TransportResolver(new Transport([$transportFactory])); - $this->assertSame($transport, $transportResolver->resolve('smtp://localhost')); + self::assertSame($transport, $transportResolver->resolve('smtp://localhost')); } public function testNotRegisteredTransportShouldTrowAnException(): void