• Stars
    star
    319
  • Rank 131,491 (Top 3 %)
  • Language
    PHP
  • Created over 5 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A set of helpful assertions when testing Laravel applications.

Laravel Test Assertions

A set of helpful assertions when testing Laravel applications.

Requirements

Your application must be running the latest LTS version (5.5) or higher and using Laravel's testing harness.

Installation

You may install these assertions with Composer by running:

composer require --dev jasonmccreary/laravel-test-assertions

Afterwards, add the trait to your base TestCase class:

<?php
namespace Tests;

use JMac\Testing\Traits\AdditionalAssertions;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication, AdditionalAssertions;
}

Assertions

This package adds several assertions helpful when writing Http Tests.

assertActionUsesFormRequest(string $controller, string $method, string $form_request)

Verifies the action for a given controller performs validation using the given form request.

assertRouteUsesFormRequest(string $routeName, string $formRequest)

Verifies that the corresponding action/controller, for a given route name performs the validation using the given form request.

assertActionUsesMiddleware(string $controller, string $method, string|array $middleware)

Verifies the action for a given controller uses the given middleware or set of middleware.

assertRouteUsesMiddleware(string $routeName, array $middlewares, bool $exact)

Verifies the route for a given route name uses all the given middlewares or only the given set of middlewares.

assertValidationRules(array $expected, array $actual)

Verifies the expected subset of validation rules for fields are within a set of validation rules. Rules may be passed as a delimited string or array.

assertExactValidationRules(array $expected, array $actual)

Verifies the expected set of validation rules for fields exactly match a set of validation rules. Rules may be passed as a delimited string or array.

assertValidationRuleContains($rule, string $class)

Verifies the rule or rules contains an instance of the given Rule class.

Matchers

LaravelMatchers::isModel(Model $model = null)

Matches an argument is the same as $model. When called without $model, will match any argument of type Illuminate\Database\Eloquent\Model.

LaravelMatchers::isCollection(Collection $collection = null)

Matches an argument equals $collection. When called without $collection, will match any argument of type Illuminate\Support\Collection.

LaravelMatchers::isEloquentCollection(Collection $collection = null)

Matches an argument equals $collection. When called without $collection, will match any argument of type \Illuminate\Database\Eloquent\Collection.

Creation Methods

This package also provides methods for quickly creating common objects used within Laravel application to use when testing.

createFormRequest(string $class, array $data = [])

Creates an instance of the given Form Request class with the given request data.

Support Policy

Starting with version 2, this package will only support the latest stable version of Laravel (currently Laravel 8). If you need to support older versions of Laravel, you may use version 1 or upgrade your application (try using Shift).

This package still follows semantic versioning. However, it does so with respect to its own code. Any breaking changes will increase its major version number. Otherwise, minor version number increases will contain new features. This includes changes for future versions of Laravel.

More Repositories

1

git-trim

Shell
366
star
2

gh

gh - A shell script to open the GitHub page for a repository.
62
star
3

local-docker-stack

This repository contains the Docker stack for my local LAMP development
Shell
56
star
4

start-testing-laravel

An app to demo testing Laravel.
PHP
26
star
5

what-the-fake

Example app for my Laracon 2023 talk.
PHP
25
star
6

dotfiles

Local system files to quickly set up my command line, shell, and Git preferences.
Shell
18
star
7

test-double

A simple helper method to make using Mockery easier.
PHP
12
star
8

start-testing-php

A sample project for my "Start Testing PHP" workshop.
12
star
9

orfail

PHP OrFail Trait.
PHP
9
star
10

ludicrous-speed

A demo of PHP + Redis + nginx
PHP
8
star
11

furry-umbrella

A Laravel application used in my conference workshops
PHP
7
star
12

og-image-generator

PHP
6
star
13

you-dont-know-git

Sample repo for Git talk.
PHP
6
star
14

expect

BDD-style assertions for PHP.
PHP
5
star
15

processcon-ci

Demo project for ProcessCon '23
PHP
5
star
16

tasty-brisket

Examples using GitHub Actions for PHP projects.
PHP
5
star
17

jmacs-hot-chicken

A modern PHP app for ordering Hot Chicken
Vue
4
star
18

bluecasts

PHP
3
star
19

BaseLaravel-Streamlines

A sample application to demo the practices from BaseLaravel
PHP
3
star
20

laravel-stubs

2
star
21

oxc

Type `oxc` to open Xcode with a workspace, project, or file from the command line.
Shell
2
star
22

looselycoupledpodcast.com

The Loosely Coupled Podcast Website
Blade
2
star
23

javascript-cookie-object

A JavaScript class for encapsulating common HTTP Cookie methods.
JavaScript
1
star
24

sample.com

PHP
1
star
25

testing-strategies

Code from my talk at LonghornPHP 2021.
PHP
1
star
26

blog-posts

Posts from my blog.
1
star
27

pspec

PSpec is a modern, BDD-style testing framework for PHP.
PHP
1
star
28

turbo-zonda

A sample Laravel application to demo the Laravel Fixer.
PHP
1
star
29

legendary-goggles

CodePalousa Workshop
1
star
30

laravel-fixer-demo

A demo repo for the Laravel Fixer
PHP
1
star
31

json-sample-data

Sample data for testing the JSON grammar. Currently simple. Eventually more complete.
1
star