Tutorial by Examples

Writing testable code is an important part of building a robust, maintainable, and agile project. Support for PHP's most widely used testing framework, PHPUnit, is built right into Laravel. PHPUnit is configured using the phpunit.xml file, which resides in the root directory of every new Laravel app...
To make artisan migrate a fresh database before running tests, use DatabaseMigrations. Also if you want to avoid middleware like Auth, use WithoutMiddleware. <?php use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\DatabaseMigrations; class ExampleTest ...
DatabaseTransactions trait allows databases to rollback all the change during the tests. If you want to rollback multiple databases , you need to set $connectionsToTransact properties use Illuminate\Foundation\Testing\DatabaseMigrations; class ExampleTest extends TestCase { use Databas...
Following setup ensures that testing framework (PHPUnit) uses :memory: database. config/database.php 'connections' => [ 'sqlite_testing' => [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', ], . . . ./phpun...
The phpunit.xml file is the default configuration file for tests and is already setup for testing with PHPUnit. The default testing environment APP_ENV is defined as testing with array being the cache driver CACHE_DRIVER. With this setup, no data (session/cache) will be retained while testing. T...

Page 1 of 1