Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Persistent Fakes for Laravel Dusk

License

NotificationsYou must be signed in to change notification settings

protonemedia/laravel-dusk-fakes

Repository files navigation

Latest Version on Packagistrun-testsTotal DownloadsBuy us a tree

Sponsor Us

❤️ We proudly support the community by developing Laravel packages and giving them away for free. If this package saves you time or if you're relying on it professionally, please considersponsoring the maintenance and development and check out our latest premium package:Inertia Table. Keeping track of issues and pull requests takes time, but we're happy to help!

Installation

You can install the package via composer:

composer require protonemedia/laravel-dusk-fakes --dev

Persist Bus (queued jobs)

Make sure you've set theDUSK_FAKE_BUS environment variable totrue in theDusk environment.

Finally, add thePersistentBus trait to your test. You don't have to manually call thefake() method on theBus facade.

<?phpnamespaceTests\Browser\Auth;useApp\Jobs\SendOrderInvoice;useApp\Models\Order;useIlluminate\Foundation\Testing\DatabaseMigrations;useIlluminate\Support\Facades\Mail;useLaravel\Dusk\Browser;useProtoneMedia\LaravelDuskFakes\Bus\PersistentBus;useTests\DuskTestCase;class OrderInvoiceTestextends DuskTestCase{use DatabaseMigrations;use PersistentBus;publicfunctiontest_dispatch_invoice_job_after_confirming_order()    {$this->browse(function (Browser$browser) {$order = Order::factory()->create();$browser->visit('/order/'.$order->id)                ->press('Confirm')                ->waitForText('We will generate an invoice!');            Bus::assertDispatched(SendOrderInvoice::class);        });    }}

If you only need to fake specific jobs while allowing your other jobs to execute normally, you may pass the class names of the jobs that should be faked to thejobsToFake() method:

Bus::jobsToFake(ShipOrder::class);$browser->visit(...);Bus::assertDispatched(SendOrderInvoice::class);

Persist Mails

Make sure you've set theDUSK_FAKE_MAILS environment variable totrue in theDusk environment.

Finally, add thePersistentMails trait to your test. You don't have to manually call thefake() method on theMail facade.

<?phpnamespaceTests\Browser\Auth;useApp\Mail\OrderConfirmed;useApp\Models\Order;useIlluminate\Foundation\Testing\DatabaseMigrations;useIlluminate\Support\Facades\Mail;useLaravel\Dusk\Browser;useProtoneMedia\LaravelDuskFakes\Mails\PersistentMails;useTests\DuskTestCase;class OrderConfirmTestextends DuskTestCase{use DatabaseMigrations;use PersistentMails;publicfunctiontest_send_order_confirmed_mailable_to_user()    {$this->browse(function (Browser$browser) {$order = Order::factory()->create();$browser->visit('/order/'.$order->id)                ->press('Confirm')                ->waitForText('We have emailed your order confirmation!');            Mail::assertSent(OrderConfirmed::class,function ($mail)use ($user) {return$mail->hasTo($user->email);            });        });    }}

Persist Notifications

Make sure you've set theDUSK_FAKE_NOTIFICATIONS environment variable totrue in theDusk environment.

Finally, add thePersistentNotifications trait to your test. You don't have to manually call thefake() method on theNotification facade.

<?phpnamespaceTests\Browser\Auth;useApp\Models\User;useIlluminate\Auth\Notifications\ResetPassword;useIlluminate\Foundation\Testing\DatabaseMigrations;useIlluminate\Support\Facades\Notification;useLaravel\Dusk\Browser;useProtoneMedia\LaravelDuskFakes\Notifications\PersistentNotifications;useTests\DuskTestCase;class PasswordResetTestextends DuskTestCase{use DatabaseMigrations;use PersistentNotifications;publicfunctiontest_reset_password_link_can_be_requested()    {$this->browse(function (Browser$browser) {$user = User::factory()->create();$browser->visit('/forgot-password')                ->type('email',$user->email)                ->press('Email Password Reset Link')                ->waitForText('We have emailed your password reset link!');            Notification::assertSentTo($user, ResetPassword::class);        });    }}

Persist Queue

Make sure you've set theDUSK_FAKE_QUEUE environment variable totrue in theDusk environment.

Finally, add thePersistentQueue trait to your test. You don't have to manually call thefake() method on theQueue facade.

<?phpnamespaceTests\Browser\Auth;useApp\Jobs\SendOrderInvoice;useApp\Models\Order;useIlluminate\Foundation\Testing\DatabaseMigrations;useIlluminate\Support\Facades\Mail;useLaravel\Dusk\Browser;useProtoneMedia\LaravelDuskFakes\Queue\PersistentQueue;useTests\DuskTestCase;class OrderInvoiceTestextends DuskTestCase{use DatabaseMigrations;use PersistentQueue;publicfunctiontest_dispatch_invoice_job_after_confirming_order()    {$this->browse(function (Browser$browser) {$order = Order::factory()->create();$browser->visit('/order/'.$order->id)                ->press('Confirm')                ->waitForText('We will generate an invoice!');            Queue::assertDispatched(SendOrderInvoice::class);        });    }}

If you only need to fake specific jobs while allowing your other jobs to execute normally, you may pass the class names of the jobs that should be faked to thejobsToFake() method:

Queue::jobsToFake(ShipOrder::class);$browser->visit(...);Queue::assertDispatched(SendOrderInvoice::class);

Changelog

Please seeCHANGELOG for more information what has changed recently.

Contributing

Please seeCONTRIBUTING for details.

Other Laravel packages

  • Inertia Table: The Ultimate Table for Inertia.js with built-in Query Builder.
  • Laravel Blade On Demand: Laravel package to compile Blade templates in memory.
  • Laravel Cross Eloquent Search: Laravel package to search through multiple Eloquent models.
  • Laravel Eloquent Scope as Select: Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes and constraints by adding them as a subquery.
  • Laravel FFMpeg: This package provides an integration with FFmpeg for Laravel. The storage of the files is handled by Laravel's Filesystem.
  • Laravel MinIO Testing Tools: Run your tests against a MinIO S3 server.
  • Laravel Mixins: A collection of Laravel goodies.
  • Laravel Paddle: Paddle.com API integration for Laravel with support for webhooks/events.
  • Laravel Task Runner: Write Shell scripts like Blade Components and run them locally or on a remote server.
  • Laravel Verify New Email: This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.
  • Laravel XSS Protection: Laravel Middleware to protect your app against Cross-site scripting (XSS). It sanitizes request input, and it can sanatize Blade echo statements.

Security

If you discover any security related issues, please emailpascal@protone.media instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please seeLicense File for more information.

Contributors3

  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp