baijunyao/laravel-test-support

Laravel Test Support
20,410 1
Install
composer require baijunyao/laravel-test-support
Latest Version:v9.1.0
License:MIT
Last Updated:Aug 30, 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

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

Related Packages

benconstable/phpspec-laravel

Test your Laravel applications with PhpSpec

355,091 144
zizaco/testcases-laravel

Some classes to help write tests for laravel 4 applications

50,511 45
taskforcedev/laravel-support

Laravel support package. Used by other Taskforcedev packages.

9,489 1