PHP code example of protonemedia / laravel-dusk-fakes

1. Go to this page and download the library: Download protonemedia/laravel-dusk-fakes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

protonemedia / laravel-dusk-fakes example snippets




namespace Tests\Browser\Auth;

use App\Jobs\SendOrderInvoice;
use App\Models\Order;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Mail;
use Laravel\Dusk\Browser;
use ProtoneMedia\LaravelDuskFakes\Bus\PersistentBus;
use Tests\DuskTestCase;

class OrderInvoiceTest extends DuskTestCase
{
    use DatabaseMigrations;
    use PersistentBus;

    public function test_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);
        });
    }
}

Bus::jobsToFake(ShipOrder::class);

$browser->visit(...);

Bus::assertDispatched(SendOrderInvoice::class);



namespace Tests\Browser\Auth;

use App\Mail\OrderConfirmed;
use App\Models\Order;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Mail;
use Laravel\Dusk\Browser;
use ProtoneMedia\LaravelDuskFakes\Mails\PersistentMails;
use Tests\DuskTestCase;

class OrderConfirmTest extends DuskTestCase
{
    use DatabaseMigrations;
    use PersistentMails;

    public function test_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);
            });
        });
    }
}



namespace Tests\Browser\Auth;

use App\Models\User;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Notification;
use Laravel\Dusk\Browser;
use ProtoneMedia\LaravelDuskFakes\Notifications\PersistentNotifications;
use Tests\DuskTestCase;

class PasswordResetTest extends DuskTestCase
{
    use DatabaseMigrations;
    use PersistentNotifications;

    public function test_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);
        });
    }
}



namespace Tests\Browser\Auth;

use App\Jobs\SendOrderInvoice;
use App\Models\Order;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Mail;
use Laravel\Dusk\Browser;
use ProtoneMedia\LaravelDuskFakes\Queue\PersistentQueue;
use Tests\DuskTestCase;

class OrderInvoiceTest extends DuskTestCase
{
    use DatabaseMigrations;
    use PersistentQueue;

    public function test_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);
        });
    }
}

Queue::jobsToFake(ShipOrder::class);

$browser->visit(...);

Queue::assertDispatched(SendOrderInvoice::class);