Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/event-bus/src/Testing/EventBusTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function assertDispatched(string|object $event, ?Closure $callback = null
{
$this->assertFaked();

Assert::assertNotNull(
Assert::assertNotEmpty(
actual: $dispatches = $this->findDispatches($event),
message: 'The event was not dispatched.',
);
Expand Down
8 changes: 5 additions & 3 deletions packages/mail/src/Testing/TestingMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use Tempest\Mail\EmailWasSent;
use Tempest\Mail\Mailer;

use function Tempest\get;

final class TestingMailer implements Mailer
{
public function __construct(
private readonly ?EventBus $eventBus = null,
) {}
private ?EventBus $eventBus {
get => get(className: EventBus::class);
}

/**
* List of emails that would have been sent.
Expand Down
5 changes: 1 addition & 4 deletions src/Tempest/Framework/Testing/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use Tempest\Database\Testing\DatabaseTester;
use Tempest\DateTime\DateTimeInterface;
use Tempest\Discovery\DiscoveryLocation;
use Tempest\EventBus\EventBus;
use Tempest\EventBus\Testing\EventBusTester;
use Tempest\Framework\Testing\Http\HttpRouterTester;
use Tempest\Http\GenericRequest;
Expand Down Expand Up @@ -142,9 +141,7 @@ protected function setupTesters(): self
$this->eventBus = new EventBusTester($this->container);
$this->storage = new StorageTester($this->container);
$this->cache = new CacheTester($this->container);
$this->mailer = new MailTester(new TestingMailer(
eventBus: $this->container->get(EventBus::class),
));
$this->mailer = new MailTester(new TestingMailer());

$this->process = $this->container->get(ProcessTester::class);
$this->process->disableProcessExecution();
Expand Down
12 changes: 12 additions & 0 deletions tests/Integration/EventBus/EventBusTesterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ public function test_assert_dispatched_object_with_callback_failure(): void
});
}

public function test_assert_dispatched_failure(): void
{
$this->eventBus->preventEventHandling();

$this->container->get(EventBus::class)->dispatch('event-bus-fake-event');

$this->expectException(ExpectationFailedException::class);
$this->expectExceptionMessage('The event was not dispatched.');

$this->eventBus->assertDispatched('this-was-not-dispatched');
}

public function test_assert_not_dispatched(): void
{
$this->eventBus->preventEventHandling();
Expand Down
19 changes: 19 additions & 0 deletions tests/Integration/Mailer/MailerTesterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPUnit\Framework\AssertionFailedError;
use Tempest\Mail\Attachment;
use Tempest\Mail\Email;
use Tempest\Mail\EmailWasSent;
use Tempest\Mail\GenericEmail;
use Tests\Tempest\Integration\FrameworkIntegrationTestCase;
use Tests\Tempest\Integration\Mailer\Fixtures\SendWelcomeEmail;
Expand Down Expand Up @@ -79,4 +80,22 @@ public function test_assertions(): void
$this->assertSame('hello!', ($email->attachments[0]->resolve)());
});
}

public function test_email_was_sent_event_was_dispatched(): void
{
$this->eventBus->preventEventHandling();

$this->mailer
->send(email: new GenericEmail(
subject: 'Hello',
to: '[email protected]',
html: 'Hello Jon',
from: '[email protected]',
attachments: [
Attachment::fromClosure(callable: fn () => 'hello!'),
],
));

$this->eventBus->assertDispatched(event: EmailWasSent::class);
}
}