PHP code example of paksuco / dusk-time-travel

1. Go to this page and download the library: Download paksuco/dusk-time-travel 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/ */

    

paksuco / dusk-time-travel example snippets



    use \Paksuco\DuskTimeTravel\Browser as TimeTravelBrowser;

    class DuskTestCase extends BaseTestCase {

        protected function newBrowser($driver)
        {
            return new TimeTravelBrowser($driver);
        }

    }

$this->browse(function ($browser) {
    
    $browser->visit('/')
        // (1) Visit home, (2) Travel to tomorrow
        ->visit("home")
        ->travelTo(Carbon::tomorrow())
        // The home page will show today's date (we have NOT reloaded the page)
        ->assertSee(Carbon::today()->format('Y-m-d'));
});

$this->browse(function ($browser) {

    $browser->visit('/')
        // (1) Travel to tomorrow, (2) Visit home
        ->travelTo(Carbon::tomorrow())
        ->visit("home")
        // The home page will show tomorrow's date (we have reloaded the page)
        ->assertSee(Carbon::tomorrow()-format('Y-m-d'));
});

$this->browse(function ($browser) {

    // Do something in yesterdays date and expect to see that it occurred on that date
    $browser->visit('/')
        ->travelTo(Carbon::yesterday())->visit($itemDetailsPage)
        ->doStuffInYesterdaysDate()
        ->travelBack()->visit($itemDetailsPage)
        ->assertSee(Carbon::yesterday());
});

$this->browse(function ($browser) {

    // Log in sometime in the distant future (long after session expiry)
    $user = User::factory()->create(['name' => 'Bob']);
    $browser->visit('/')
        ->travelTo(Carbon::parse('2040-01-01 12:00:00')
        ->actingAs($user)->visit('/dashboard')
        ->assertSee("Welcome Bob, it is the year 2040!");
});

// All PHP versions:
$browser->visit('/')->travelTo(Carbon::tomorrow(), false);

// Or if you'd like to use named parameters (PHP 8.0+):
$browser->visit('/')->travelTo(Carbon::tomorrow(), javascript: false);

return [
    'middleware' => true,
];
bash
php artisan vendor:publish --tag=dusk-time-travel-config