From 265fbc6c40c4ead9d4e4bc5ef7aae99cf7076b47 Mon Sep 17 00:00:00 2001 From: spiralbot Date: Wed, 11 Sep 2024 17:19:15 +0000 Subject: [PATCH] Merge pull request #1147: Fix Stempler in Container Scopes --- composer.json | 1 + tests/App/App.php | 38 ---------------------------------- tests/RenderTest.php | 49 ++++++++++++++++++++++++++++++++------------ 3 files changed, 37 insertions(+), 51 deletions(-) delete mode 100644 tests/App/App.php diff --git a/composer.json b/composer.json index d2af074..0a1bdeb 100644 --- a/composer.json +++ b/composer.json @@ -48,6 +48,7 @@ "mockery/mockery": "^1.5", "spiral/boot": "^3.15", "spiral/stempler-bridge": "^3.15", + "spiral/testing": "^2.8", "vimeo/psalm": "^5.9" }, "autoload": { diff --git a/tests/App/App.php b/tests/App/App.php deleted file mode 100644 index b25924e..0000000 --- a/tests/App/App.php +++ /dev/null @@ -1,38 +0,0 @@ -container->get(MailJob::class)->handle( - MailQueue::JOB_NAME, - 'id', - json_encode(MessageSerializer::pack($message)) - ); - - return $this->container->get(MailerInterface::class)->getLast(); - } -} diff --git a/tests/RenderTest.php b/tests/RenderTest.php index b6756d9..2c33b99 100644 --- a/tests/RenderTest.php +++ b/tests/RenderTest.php @@ -4,24 +4,36 @@ namespace Spiral\Tests\SendIt; -use PHPUnit\Framework\TestCase; -use Spiral\Tests\SendIt\App\App; +use Spiral\Mailer\MessageInterface; +use Spiral\SendIt\Bootloader\BuilderBootloader; +use Spiral\SendIt\Bootloader\MailerBootloader; +use Spiral\SendIt\MailJob; +use Spiral\SendIt\MailQueue; +use Spiral\SendIt\MessageSerializer; +use Spiral\Testing\TestCase; use Spiral\Mailer\Exception\MailerException; use Spiral\Mailer\Message; +use Spiral\Tests\SendIt\App\MailInterceptorBootloader; +use Symfony\Component\Mailer\MailerInterface; +use Symfony\Component\Mime\Email; -/** - * @requires function \Spiral\Framework\Kernel::create - */ class RenderTest extends TestCase { - private $app; + public function defineBootloaders(): array + { + return [ + MailerBootloader::class, + BuilderBootloader::class, + MailInterceptorBootloader::class, + ]; + } - public function setUp(): void + public function defineDirectories(string $root): array { - $this->app = App::create([ - 'root' => __DIR__ . '/App', - 'app' => __DIR__ . '/App' - ])->run(); + return [ + 'root' => __DIR__ . '/App', + 'app' => __DIR__ . '/App' + ] + parent::defineDirectories($root); } public function tearDown(): void @@ -34,12 +46,12 @@ public function tearDown(): void public function testRenderError(): void { $this->expectException(MailerException::class); - $this->app->send(new Message('test', ['email@domain.com'], ['name' => 'Antony'])); + $this->send(new Message('test', ['email@domain.com'], ['name' => 'Antony'])); } public function testRender(): void { - $email = $this->app->send(new Message('email', ['email@domain.com'], ['name' => 'Antony'])); + $email = $this->send(new Message('email', ['email@domain.com'], ['name' => 'Antony'])); $this->assertSame('Demo Email', $email->getSubject()); @@ -47,4 +59,15 @@ public function testRender(): void $this->assertStringContainsString('bootstrap.txt', $body); $this->assertStringContainsString('

Hello, Antony!

', $body); } + + private function send(MessageInterface $message): Email + { + $this->getContainer()->get(MailJob::class)->handle( + MailQueue::JOB_NAME, + 'id', + json_encode(MessageSerializer::pack($message)) + ); + + return $this->getContainer()->get(MailerInterface::class)->getLast(); + } }