百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

laravel-test-assertions

> 编程语言
开源

一套在测试Laravel应用程序时有用的断言.

351 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一套在测试Laravel应用程序时有用的断言.

Laravel Test Assertions

A set of helpful assertions when testing Laravel applications.

Requirements

Your application must be running the Laravel 5.5 or higher and using Laravel's testing harness.

Installation

You may install these additional assertions with Composer by running:

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

Afterwards, add the trait to your base TestCase class:

php
<?php
namespace Tests;

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

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

Documentation

This package adds several assertions, matchers, and helpers aimed at making testing within Laravel easier.

Assertions

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

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

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

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

php
assertRouteUsesFormRequest(string $routeName, string $formRequest)

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

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

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

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

Note: closures within a rule set are compared by presence and position, not by behavior. PHP offers no way to compare two closures functionally. To better cover what a closure does, extract it into a ValidationRule class and test it separately.

php
assertValidationRuleContains($rule, string $class)

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

php
assertViewHasNull($key)

Verifies the view data $key has an explicit value of null. Note: is a TestResponse assertion. It must be called on the response of a view.

php
assertNow(CarbonInterface $datetime, ?CarbonInterface $now = null)

Verifies $datetime is equal to $now, precise to the second. $now defaults to Carbon::now() which can be faked with the freezeNow() testing helper.

Matchers

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

php
LaravelMatchers::isCollection(Collection $collection = null)

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

php
LaravelMatchers::isEloquentCollection(Collection $collection = null)

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

Helpers

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

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

php
freezeNow(bool $subseconds = false)

Similar to Laravel's freezeTime() helper, but defaults with second precision and returns the frozen time. You may pass true to freeze with sub-second precision.

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.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言