Skip to content

Commit

Permalink
Log emails only one time - log mailer
Browse files Browse the repository at this point in the history
  • Loading branch information
glorand committed Feb 24, 2025
1 parent d230e9d commit 02f8195
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Ray.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Spatie\LaravelRay\Watchers\HttpClientWatcher;
use Spatie\LaravelRay\Watchers\InsertQueryWatcher;
use Spatie\LaravelRay\Watchers\JobWatcher;
use Spatie\LaravelRay\Watchers\LoggedMailWatcher;
use Spatie\LaravelRay\Watchers\MailWatcher;
use Spatie\LaravelRay\Watchers\QueryWatcher;
use Spatie\LaravelRay\Watchers\RequestWatcher;
Expand Down Expand Up @@ -105,6 +106,8 @@ public function showMails($callable = null)
return $this;
}

app(LoggedMailWatcher::class)->disable();

$watcher = app(MailWatcher::class);

return $this->handleWatcherCallable($watcher, $callable);
Expand All @@ -114,6 +117,8 @@ public function stopShowingMails(): self
{
app(MailWatcher::class)->disable();

app(LoggedMailWatcher::class)->enable();

return $this;
}

Expand Down
7 changes: 6 additions & 1 deletion tests/Unit/MailableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Illuminate\Support\Facades\Mail;
use Spatie\LaravelRay\Tests\TestClasses\TestMailable;
use Spatie\LaravelRay\Watchers\MailWatcher;
use Illuminate\Support\Arr;

it('can send the mailable payload', function () {
ray()->mailable(new TestMailable());
Expand Down Expand Up @@ -46,5 +47,9 @@
->to(['freek@spatie.be', 'ruben@spatie.be'])
->sendNow(new TestMailable());

expect($this->client->sentRequests())->toHaveCount(3);
$requests = $this->client->sentRequests();

expect($requests)->toHaveCount(2);
expect(Arr::get($requests, '0.payloads.0.origin.file'))->toContain('Mailer.php');
expect(Arr::get($requests, '1.payloads.0.origin.file'))->toContain('LogTransport.php');
});

0 comments on commit 02f8195

Please sign in to comment.