Giter Site home page Giter Site logo

laravel-test-assertions's Introduction

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.

laravel-test-assertions's People

Contributors

jasonmccreary avatar simonvomeyser avatar a-lawrence avatar faustbrian avatar devoncmather avatar morpheus7cs avatar mmghunaim avatar devmsh avatar niveshsaharan avatar svenluijten avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.