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.

Expectations

toBeCollection()

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

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

toBeDeleted()

Asserts the given model to be deleted.

expect($model)->toBeDeleted();

toBeSoftDeleted()

Asserts the given model to be soft deleted.

expect($model)->toBeSoftDeleted();

toBeEloquentCollection()

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

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

toBeInDatabase()

Asserts that the given where condition exists in the database

expect(['name' => 'Fabio'])->toBeInDatabase(table: 'users');

toExist()

Asserts 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.