diff --git a/src/Bus/PersistentBusFake.php b/src/Bus/PersistentBusFake.php index caf5ab7..b974fc7 100644 --- a/src/Bus/PersistentBusFake.php +++ b/src/Bus/PersistentBusFake.php @@ -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(), diff --git a/src/Mails/PersistentMailFake.php b/src/Mails/PersistentMailFake.php index 400b5f8..95ec819 100644 --- a/src/Mails/PersistentMailFake.php +++ b/src/Mails/PersistentMailFake.php @@ -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, diff --git a/src/Notifications/PersistentNotificationFake.php b/src/Notifications/PersistentNotificationFake.php index da26c6f..ab73490 100644 --- a/src/Notifications/PersistentNotificationFake.php +++ b/src/Notifications/PersistentNotificationFake.php @@ -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)); } } diff --git a/src/Queue/PersistentQueueFake.php b/src/Queue/PersistentQueueFake.php index dd95c34..58c8ad1 100644 --- a/src/Queue/PersistentQueueFake.php +++ b/src/Queue/PersistentQueueFake.php @@ -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; @@ -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, ])); } diff --git a/tests/BusTest.php b/tests/BusTest.php index dc4d8c6..6b92a05 100644 --- a/tests/BusTest.php +++ b/tests/BusTest.php @@ -1,5 +1,6 @@ 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); diff --git a/tests/MailTest.php b/tests/MailTest.php index 4cd46ed..26b4c3d 100644 --- a/tests/MailTest.php +++ b/tests/MailTest.php @@ -1,5 +1,6 @@ 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); diff --git a/tests/NotificationTest.php b/tests/NotificationTest.php index 012b4d3..a887501 100644 --- a/tests/NotificationTest.php +++ b/tests/NotificationTest.php @@ -1,5 +1,6 @@ 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); diff --git a/tests/QueueTest.php b/tests/QueueTest.php index cc77b6e..b74a41d 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -1,5 +1,6 @@ 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);