Skip to content

defstudio/pest-plugin-laravel-expectations

Repository files navigation

A Pest plugin to add Laravel specific expectations

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads License

This Pest plugin adds Laravel specific expectations to the testing ecosystem

it('can check model exists', function(){
  $user = User::factory()->create();
  
  expect($user)->toExist();
});

Installation

You can install the package via composer:

composer require --dev defstudio/pest-plugin-laravel-expectations

Usage

The expectations added by this plugin are authomatically loaded into Pest's expectation system. They can be used along other expectations.

Authentication Expectations

toBeAuthenticated()

Assert that the given User is authenticated

expect($user)->toBeAuthenticated();

toBeValidCredentials()

Assert that the given credentials are valid.

expect(['email' => 'test@email.it', 'password' => 'foo'])->toBeValidCredentials();

toBeInvalidCredentials()

Assert that the given credentials are invalid.

expect(['email' => 'test@email.it', 'password' => 'wrongpassword'])->toBeInvalidCredentials();

Database Expectations

toBeCollection()

Assert that the value is an instance of \Illuminate\Support\Collection

expect(collect[1,2,3])->toBeCollection();

toBeDeleted()

Assert the given model to be deleted.

expect($model)->toBeDeleted();

toBeSoftDeleted()

Assert the given model to be soft deleted.

expect($model)->toBeSoftDeleted();

toBeEloquentCollection()

Assert that the value is an instance of \Illuminate\Database\Eloquent\Collection

expect(User::all())->toBeCollection();

toExist()

Assert the given model exists in the database.

expect($model)->toExist();

Tests

Run all tests:

composer test

Check types:

composer test:types

Unit tests:

composer test:unit

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

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