Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet committed Apr 4, 2023
1 parent 952556e commit 1982ce4
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/Bus/PersistentBusFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public function cleanupCommand(array $jobs): array

private function storeBus()
{
(new Filesystem)->ensureDirectoryExists($this->directory);

file_put_contents($this->storage, serialize([
'jobsToFake' => $this->jobsToFake,
'commands' => collect($this->commands)->map([$this, 'cleanupCommand'])->all(),
Expand Down
2 changes: 2 additions & 0 deletions src/Mails/PersistentMailFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public function queue($view, $queue = null)

private function storeMails()
{
(new Filesystem)->ensureDirectoryExists($this->directory);

file_put_contents($this->storage, serialize([
'mailables' => $this->mailables,
'queuedMailables' => $this->queuedMailables,
Expand Down
2 changes: 2 additions & 0 deletions src/Notifications/PersistentNotificationFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public function sendNow($notifiables, $notification, array $channels = null)

private function storeNotifications()
{
(new Filesystem)->ensureDirectoryExists($this->directory);

file_put_contents($this->storage, serialize($this->notifications));
}
}
8 changes: 6 additions & 2 deletions src/Queue/PersistentQueueFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function loadQueue(): self
? rescue(fn () => unserialize(file_get_contents($this->storage)), [], false)
: [];

$this->jobsToFake = Collection::wrap($unserialized['jobsToFake'] ?? []);
$this->jobsToFake = Collection::make($unserialized['jobsToFake'] ?? []);
$this->jobsToBeQueued = Collection::make($unserialized['jobsToBeQueued'] ?? []);
$this->jobs = $unserialized['jobs'] ?? [];

return $this;
Expand All @@ -58,8 +59,11 @@ public function push($job, $data = '', $queue = null)

private function storeQueue()
{
(new Filesystem)->ensureDirectoryExists($this->directory);

file_put_contents($this->storage, serialize([
'jobsToFake' => Collection::wrap($this->jobsToFake)->all(),
'jobsToFake' => $this->jobsToFake->all(),
'jobsToBeQueued' => $this->jobsToBeQueued->all(),
'jobs' => $this->jobs,
]));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/BusTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Testing\Fakes\PendingBatchFake;
use ProtoneMedia\LaravelDuskFakes\Bus\PersistentBus;
Expand All @@ -13,8 +14,7 @@
use PersistentBus;
};

beforeEach(fn () => app(PersistentBusFake::class)->cleanStorage());
afterEach(fn () => app(PersistentBusFake::class)->cleanStorage());
afterEach(fn () => (new Filesystem)->cleanDirectory(storage_path('framework/testing')));

it('can persist a queued job', function () use ($dummyTest) {
expect(Bus::getFacadeRoot())->toBeInstanceOf(PersistentBusFake::class);
Expand Down
4 changes: 2 additions & 2 deletions tests/MailTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Mail;
use ProtoneMedia\LaravelDuskFakes\Mails\PersistentMailFake;
use ProtoneMedia\LaravelDuskFakes\Mails\PersistentMails;
Expand All @@ -11,8 +12,7 @@
use PersistentMails;
};

beforeEach(fn () => app(PersistentMailFake::class)->cleanStorage());
afterEach(fn () => app(PersistentMailFake::class)->cleanStorage());
afterEach(fn () => (new Filesystem)->cleanDirectory(storage_path('framework/testing')));

it('can persist sent mails', function () use ($dummyTest) {
expect(Mail::getFacadeRoot())->toBeInstanceOf(PersistentMailFake::class);
Expand Down
4 changes: 2 additions & 2 deletions tests/NotificationTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Notification;
use ProtoneMedia\LaravelDuskFakes\Notifications\PersistentNotificationFake;
use ProtoneMedia\LaravelDuskFakes\Notifications\PersistentNotifications;
Expand All @@ -12,8 +13,7 @@
use PersistentNotifications;
};

beforeEach(fn () => app(PersistentNotificationFake::class)->cleanStorage());
afterEach(fn () => app(PersistentNotificationFake::class)->cleanStorage());
afterEach(fn () => (new Filesystem)->cleanDirectory(storage_path('framework/testing')));

it('can persist sent notifications', function () use ($dummyTest) {
expect(Notification::getFacadeRoot())->toBeInstanceOf(PersistentNotificationFake::class);
Expand Down
4 changes: 2 additions & 2 deletions tests/QueueTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Queue;
use ProtoneMedia\LaravelDuskFakes\Queue\PersistentQueue;
use ProtoneMedia\LaravelDuskFakes\Queue\PersistentQueueFake;
Expand All @@ -12,8 +13,7 @@
use PersistentQueue;
};

beforeEach(fn () => app(PersistentQueueFake::class)->cleanStorage());
afterEach(fn () => app(PersistentQueueFake::class)->cleanStorage());
afterEach(fn () => (new Filesystem)->cleanDirectory(storage_path('framework/testing')));

it('can persist a queued job', function () use ($dummyTest) {
expect(Queue::getFacadeRoot())->toBeInstanceOf(PersistentQueueFake::class);
Expand Down

0 comments on commit 1982ce4

Please sign in to comment.