Skip to content

Commit

Permalink
Update SendIt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Sep 11, 2024
1 parent 3ebf8ff commit dcd438d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 66 deletions.
3 changes: 2 additions & 1 deletion src/Bridge/Stempler/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
"spiral/core": "^3.15"
},
"require-dev": {
"spiral/boot": "^3.15",
"phpunit/phpunit": "^10.1",
"spiral/boot": "^3.15",
"spiral/testing": "^2.8",
"mockery/mockery": "^1.5",
"vimeo/psalm": "^5.9"
},
Expand Down
14 changes: 0 additions & 14 deletions src/Bridge/Stempler/tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,11 @@

namespace Spiral\Tests\Stempler;

use Spiral\Boot\BootloadManager\StrategyBasedBootloadManager;
use Spiral\Boot\BootloadManager\DefaultInvokerStrategy;
use Spiral\Boot\BootloadManager\Initializer;
use Spiral\Boot\Directories;
use Spiral\Boot\DirectoriesInterface;
use Spiral\Boot\Environment;
use Spiral\Boot\EnvironmentInterface;
use Spiral\Config\ConfigManager;
use Spiral\Config\ConfiguratorInterface;
use Spiral\Config\Loader\DirectoryLoader;
use Spiral\Config\Loader\JsonLoader;
use Spiral\Config\Loader\PhpLoader;
use Spiral\Core\ConfigsInterface;
use Spiral\Core\Container;
use Spiral\Stempler\Bootloader\PrettyPrintBootloader;
use Spiral\Stempler\Bootloader\StemplerBootloader;
use Spiral\Stempler\StemplerEngine;
use Spiral\Testing\TestCase;
use Spiral\Views\ViewManager;
use Spiral\Views\ViewsInterface;

abstract class BaseTestCase extends TestCase
Expand Down
1 change: 1 addition & 0 deletions src/SendIt/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 src/SendIt/tests/App/App.php

This file was deleted.

49 changes: 36 additions & 13 deletions src/SendIt/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 dcd438d

Please sign in to comment.