Laravel Cloud is here! Zero-config managed infrastructure for Laravel apps. Deploy now.

Browser Kit Testing

laravel/browser-kit-testing image

Browser Kit Testing stats

Downloads
6.1M
Stars
493
Open Issues
0
Forks
74

View on GitHub →

Provides backwards compatibility for BrowserKit testing in the latest Laravel release.

Laravel BrowserKit Testing

Laravel BrowserKit Testing is a package that offers a fluent API for simulating HTTP requests within your Laravel application, allowing you to test output, interact with forms, and more. It aims to simplify the process of writing tests that mimic user interactions.

Key Features

  • HTTP Requests: Easily simulate GET and POST requests using methods like visit and visitRoute.
  • Assertions: Assert specific texts, URLs, and JSON structures in responses with methods like see, dontSee, seePageIs, and various JSON assertions.
  • Form Interaction: Interact with forms through methods like type, select, check, and press.
  • Session and Authentication: Manipulate session data and authenticate users within tests.
  • Middleware Control: Optionally disable middleware to test routes and controllers in isolation.
  • Custom HTTP Requests: Create custom HTTP requests and inspect raw Illuminate\Http\Response objects.
  • PHPUnit Assertions: Utilize a variety of custom assertion methods tailored for Laravel applications.

Installation

  1. Install via Composer:

    composer require laravel/browser-kit-testing --dev
  2. Update your base TestCase to extend Laravel\BrowserKitTesting\TestCase:

    namespace Tests;
     
    use Laravel\BrowserKitTesting\TestCase as BaseTestCase;
     
    abstract class TestCase extends BaseTestCase
    {
    use CreatesApplication;
    public $baseUrl = 'http://localhost';
    }

Usage Examples

  • Basic Page Visit and Text Assertions:

    public function testBasicExample()
    {
    $this->visit('/')
    ->see('Laravel')
    ->dontSee('Rails');
    }
  • Form Interaction:

    public function testNewUserRegistration()
    {
    $this->visit('/register')
    ->type('Taylor', 'name')
    ->check('terms')
    ->press('Register')
    ->seePageIs('/dashboard');
    }
  • JSON API Testing:

    public function testBasicExample()
    {
    $this->json('POST', '/user', ['name' => 'Sally'])
    ->seeJson([
    'created' => true,
    ]);
    }
  • Session and Authentication:

    public function testApplication()
    {
    $user = factory(App\User::class)->create();
     
    $this->actingAs($user)
    ->withSession(['foo' => 'bar'])
    ->visit('/')
    ->see('Hello, '.$user->name);
    }

This package is essential for developers looking to thoroughly test Laravel applications by simulating and asserting a wide range of user interactions, enhancing test reliability and application robustness.

laravel photo

Laravel is a web ecosystem full of delightful tools that are supercharged for developer happiness and productivity.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Laravel Browser Kit Testing Related Articles

Authentication With Laravel and MongoDB image

Authentication With Laravel and MongoDB

Read article
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Tighten logo

Tighten

We help companies turn great ideas into amazing apps, products, and services.

Tighten
Honeybadger logo

Honeybadger

Simple developer-focused application monitoring for Laravel. Error tracking, log management, uptime monitoring, status pages, and more!

Honeybadger
DreamzTech logo

DreamzTech

Hire 6-10+ Yrs. experienced skilled Laravel Developers from DreamzTech. We ensure NDA protected, 100% quality delivery. Contact Us & Discuss Your Need.

DreamzTech