Skip to content

Commit

Permalink
Merge pull request #1147: Fix Stempler in Container Scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed Sep 11, 2024
1 parent 7c7f07e commit 265fbc6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 51 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
38 changes: 0 additions & 38 deletions tests/App/App.php

This file was deleted.

49 changes: 36 additions & 13 deletions tests/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,17 +46,28 @@ 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());

$body = $email->getBody()->toString();
$this->assertStringContainsString('bootstrap.txt', $body);
$this->assertStringContainsString('<p>Hello, Antony!</p>', $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();
}
}

0 comments on commit 265fbc6

Please sign in to comment.