-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
175 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.yml] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Zenstruck\Mailer\Test; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\Mailer\Event\MessageEvent; | ||
use Symfony\Component\Mailer\Event\MessageEvents; | ||
|
||
/** | ||
* @author Kevin Bond <kevinbond@gmail.com> | ||
* | ||
* @internal | ||
*/ | ||
final class MessageEventCollector implements EventSubscriberInterface | ||
{ | ||
private static ?MessageEvents $events = null; | ||
|
||
public function onMessage(MessageEvent $event): void | ||
{ | ||
if (self::$events) { | ||
self::$events->add($event); | ||
} | ||
} | ||
|
||
public function mailer(): TestMailer | ||
{ | ||
if (!self::$events) { | ||
throw new \LogicException('Cannot access mailer as email collection has not yet been started.'); | ||
} | ||
|
||
return new TestMailer(self::$events); | ||
} | ||
|
||
public static function start(): void | ||
{ | ||
self::$events = new MessageEvents(); | ||
} | ||
|
||
public static function reset(): void | ||
{ | ||
self::$events = null; | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
MessageEvent::class => ['onMessage', -255], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Zenstruck\Mailer\Test; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; | ||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
/** | ||
* @author Kevin Bond <kevinbond@gmail.com> | ||
*/ | ||
final class ZenstruckMailerTestBundle extends Bundle | ||
{ | ||
public function build(ContainerBuilder $container): void | ||
{ | ||
$container->register('zenstruck_mailer_test.event_collector', MessageEventCollector::class) | ||
->addTag('kernel.event_subscriber') | ||
; | ||
} | ||
|
||
public function getContainerExtension(): ?ExtensionInterface | ||
{ | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
imports: | ||
- { resource: test.yaml } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Zenstruck\Mailer\Test\Tests; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Zenstruck\Mailer\Test\Tests\Fixture\Email1; | ||
|
||
/** | ||
* @author Kevin Bond <kevinbond@gmail.com> | ||
*/ | ||
final class NonInteractsWithMailerTest extends KernelTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function ensure_emails_are_not_collected(): void | ||
{ | ||
self::bootKernel(); | ||
|
||
self::$container->get('mailer')->send(new Email1()); | ||
|
||
$this->expectException(\LogicException::class); | ||
$this->expectExceptionMessage('Cannot access mailer as email collection has not yet been started.'); | ||
|
||
self::$container->get('zenstruck_mailer_test.event_collector')->mailer(); | ||
} | ||
} |