<?php

namespace Tests\Browser;

use App\Models\User;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

class BreadcrumbsTest extends DuskTestCase
{
    /**
     * @dataProvider guestPagesBreadcrumbs
     */
    public function testBreadcrumbsForPagesThatDoNotRequiredAuthentication(string $url, array $crumbs): void
    {
        $this->browse(function (Browser $browser) use ($url, $crumbs) {
            $browser->visit($url)
                ->assertSeeIn('.breadcrumb', strtoupper(implode("\n", $crumbs)));
        });
    }

    public function guestPagesBreadcrumbs(): array
    {
        return [
            'Homepage'           => ['/', ['Home']],
            'Login'              => ['/login', ['Home', 'Login']],
            'Register'           => ['/register', ['Home', 'Register']],
            'Forgotten password' => ['/password/reset', ['Home', 'Forgotten password']],
        ];
    }

    /**
     * @dataProvider authPagesBreadcrumbs
     */
    public function testBreadcrumbsForPagesThatRequiredAuthentication(string $url, array $crumbs): void
    {
        $this->browse(function (Browser $browser) use ($url, $crumbs) {
            $browser->loginAs(factory(User::class)->create())
                ->visit($url)
                ->assertSeeIn('.breadcrumb', strtoupper(implode("\n", $crumbs)));
        });
    }

    public function authPagesBreadcrumbs(): array
    {
        return [
            'Dashboard' => ['/dashboard', ['Home', 'Dashboard']],
        ];
    }
}

<?php

namespace Tests\Browser;

use App\Models\User;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

class BreadcrumbsTest extends DuskTestCase
{
    public function testBreadcrumbsForPagesThatDoNotRequiredAuthentication(): void
    {
        $breadcrumbs = $this->guestPagesBreadcrumbs();

        $this->browse(function (Browser $browser) use ($breadcrumbs) {
            foreach ($breadcrumbs as $url => $crumbs) {
                $browser->visit($url)
                    ->assertSeeIn('.breadcrumb', strtoupper(implode("\n", $crumbs)));
            }
        });
    }

    public function guestPagesBreadcrumbs(): array
    {
        return [
            '/' => ['Home'],
            '/login' => ['Home', 'Login'],
            '/register' => ['Home', 'Register'],
            '/password/reset' => ['Home', 'Forgotten password'],
        ];
    }

    public function testBreadcrumbsForPagesThatRequiredAuthentication(): void
    {
        $breadcrumbs = $this->authPagesBreadcrumbs();

        $this->browse(function (Browser $browser) use ($breadcrumbs) {
            $browser->loginAs(factory(User::class)->create());
            foreach ($breadcrumbs as $url => $crumbs) {
                $browser->visit($url)
                    ->assertSeeIn('.breadcrumb', strtoupper(implode("\n", $crumbs)));
            }
        });
    }

    public function authPagesBreadcrumbs(): array
    {
        return [
            '/dashboard' => ['Home', 'Dashboard'],
        ];
    }
}

Refactor Dusk Breadcrumbs test to be more efficient
Refactor Dusk Breadcrumbs test to be more efficient
