New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

baijunyao/laravel-test-support

Laravel Test Support
20,507 1
Install
composer require baijunyao/laravel-test-support
Latest Version:v15.0.0
PHP:^8.2
Laravel:7 – 13
Older releases:5 · 6
License:MIT
Last Updated:Oct 29, 2026
Links: GitHub  ·  Packagist
Maintainer: baijunyao

Laravel Test Support

Laravel Test Support is an extension package developed for the Laravel project to help simplify writing PHPUnit or Pest tests

Compatibility

The package allows Illuminate 7–13, Pest 3–5, and PHPUnit 11–13. Pest determines the compatible PHPUnit major version: Pest 3 uses PHPUnit 11, Pest 4 uses PHPUnit 12, and Pest 5 uses PHPUnit 13.

The package requires PHP 8.2 or newer. Laravel 13 requires PHP 8.3 or newer; Pest 5 requires PHP 8.4 or newer. Composer selects a compatible combination for the current PHP version.

Installation

Require this package with composer using the following command:

composer require baijunyao/laravel-test-support

Usage

Modify the tests/TestCase.php file

<?php

namespace Tests;

- use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
+ use Baijunyao\LaravelTestSupport\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
}

After each test, the base test case truncates every table written by that test. If a matching table seeder exists, it then runs the seeder to restore the table's baseline data. Foreign key constraints are temporarily disabled during cleanup.

Modify the phpunit.xml file

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         colors="true"
>
+   <extensions>
+       <bootstrap class="Baijunyao\LaravelTestSupport\Extensions\CreateRandomDatabaseExtension"/>
+   </extensions>
    <testsuites>
        <testsuite name="Unit">
            <directory>tests/Unit</directory>
        </testsuite>
        <testsuite name="Feature">
            <directory>tests/Feature</directory>
        </testsuite>
    </testsuites>
    <source>
        <include>
            <directory>app</directory>
        </include>
    </source>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="BCRYPT_ROUNDS" value="4"/>
        <env name="CACHE_DRIVER" value="array"/>
        <!-- <env name="DB_CONNECTION" value="sqlite"/> -->
        <!-- <env name="DB_DATABASE" value=":memory:"/> -->
+       <env name="DB_HOST" value="127.0.0.1"/>
        <env name="MAIL_MAILER" value="array"/>
        <env name="QUEUE_CONNECTION" value="sync"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="TELESCOPE_ENABLED" value="false"/>
    </php>
</phpunit>

Example

Package development

composer update --with-all-dependencies
composer test

Run the full suite with composer test or ./vendor/bin/pest. It includes Pest test functions, so running ./vendor/bin/phpunit directly cannot load the full suite. The Pest runner executes both the Pest tests and the PHPUnit test classes.

The test suite covers the nine resource snapshot helpers, date/cookie normalization, SQLite dirty-table cleanup, and database subscriber success and failure paths. Snapshot baselines are stored in tests/.pest/snapshots.

Verified on Laravel 13.39.0 (each combination: 16 tests, 46 assertions):

PHP Pest PHPUnit
8.3.33 3.8.7 11.5.56
8.3.33 4.7.8 12.5.33
8.5.6 5.3.4 13.4.5

MySQL/PostgreSQL database creation and removal are tested using mocks, without connecting to a real database server.

Related Packages

oilstone/support

Support classes

6,458 1
tipoff/support

Laravel Package for core support features used in Ecommerce packages

85,490 0
baijunyao/laravel-support

Laravel Support

17,262 2
taskforcedev/laravel-support

Laravel support package. Used by other Taskforcedev packages.

9,494 1
northeastern-web/kernl-ui-blade

Package of Blade components for Northeastern University websites

4,120 1

Version History

Version Released PHP Laravel License
v15.0.0 ^8.2 ^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0 MIT
v14.0.0 ^7.0|^8.0|^9.0|^10.0|^11.0 MIT
v13.0.0 ^7.0|^8.0|^9.0|^10.0|^11.0 MIT
v12.0.0 ^7.0|^8.0|^9.0|^10.0|^11.0 MIT
v11.0.0 ^7.0|^8.0|^9.0|^10.0|^11.0 MIT