baijunyao / laravel-test-support
Laravel Test Support
Installs: 19 877
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- baijunyao/laravel-support: ^1.3
- illuminate/database: ^7.0|^8.0|^9.0|^10.0
- illuminate/support: ^7.0|^8.0|^9.0|^10.0
- illuminate/testing: ^7.0|^8.0|^9.0|^10.0
- phpunit/phpunit: ^8.0|^9.0|^10.0
- spatie/phpunit-snapshot-assertions: dev-main
- vlucas/phpdotenv: ^5.3
Requires (Dev)
- baijunyao/php-cs-fixer-config: ^0.3
- orchestra/testbench: ^5.0|^6.0|^7.0|^8.0
README
Laravel Test Support is an extension package developed for the Laravel project to help simplify writing PHPUnit tests
Installation
Require this package with composer using the following command:
composer config repositories.phpunit-snapshot-assertions vcs https://github.com/baijunyao/phpunit-snapshot-assertions 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 { use CreatesApplication; }
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>