https://github.com/dees040/festing
  
  
    Fasten up your unit tests in Laravel by more than 100% 
    https://github.com/dees040/festing
  
laravel php unit-testing
        Last synced: 7 months ago 
        JSON representation
    
Fasten up your unit tests in Laravel by more than 100%
- Host: GitHub
- URL: https://github.com/dees040/festing
- Owner: dees040
- Created: 2018-03-20T10:32:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-03-04T15:30:49.000Z (over 5 years ago)
- Last Synced: 2025-03-27T06:44:41.462Z (7 months ago)
- Topics: laravel, php, unit-testing
- Language: PHP
- Size: 28.3 KB
- Stars: 36
- Watchers: 4
- Forks: 0
- Open Issues: 0
- 
            Metadata Files:
            - Readme: README.md
 
Awesome Lists containing this project
README
          # Fast Laravel Testing
Festing is a very very great name made by combining the words fast and testing. Because that is what this package is for. Faster tests in Laravel. The package is inspired by a great article from [Nate Denlinger](https://natedenlinger.com/my-suggestions-to-speed-up-testing-with-laravel-and-phpunit/).
Before 'Festing':

After 'Festing':

## Installation
Installation and setup time is estimated to be around 5 minutes in existing Laravel projects and 2 minutes in new projects. Install this package via composer.
```bash
composer require --dev dees040/festing
```
If you're using Laravel >= 5.5 this package will automatically be added to your providers list. If using a lower version, add the service provider to the `providers` array in `config/app.php`.
```php
Dees040\Festing\ServiceProvider::class,
```
You're now ready for setup.
The package comes with a small config file. The default config should be good in most use cases. However, feel free to change it. To publish the config file run the following command
```bash
php artisan vendor:publish --provider="Dees040\Festing\ServiceProvider" --tag="config"
```
## Setup
First you should update the `database.php` config file. We should add a connection specifically for testing. You can use the following array.
```php
'testing' => [
    'driver' => 'sqlite',
    'database' => database_path('testing.sqlite'),
    'prefix'   => '',
],
```
In the package config you can specify which connection to use while testing. By default it will use the `testing` connection, which we've just added to the `connections` array. You should also add or update this in `` tag located in the `phpunit.xml` file.
```xml
```
Because Laravel don't have an option to boot your testing traits like the model traits we need to add a little bit of functionality in our `tests/TestCase.php` file. If you haven't overwritten the `setUpTraits()` method yet, you can add this to the `TestCase.php`.
```php
use Dees040\Festing\FestTheDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
    use CreatesApplication, FestTheDatabase;
    /**
     * Boot the testing helper traits.
     *
     * @return array
     */
    protected function setUpTraits()
    {
        $uses = parent::setUpTraits();
    
        if (isset($uses[\Dees040\Festing\ShouldFest::class])) {
            $this->runFester();
        }
    
        return $uses;
    }
```
If you already have overwritten the `setUpTraits()` method just add the if statement to the method body. **Also your `TestCase.php` should use the `FestTheDatabase` trait.** In the examples directory you can see an example `TestCase.php` and unit test.
### In test cases
To actually execute the database refresher you need to use `ShouldFest` trait in your test cases. This traits is used like the `ShouldQueue` interface, it only executes the code if it's detected. It also replaces the `RefreshDatabase` trait from Laravel.
```php
assertTrue(true);
    }
}
```
### Command
The package come with a command (`make:fest`) which is the same as `php artisan make:test`. The only difference is that it uses the `ShouldFest` trait instead of the default `RefreshDatabase` trait provided by Laravel.
## Config
Check the [config file](https://github.com/dees040/festing/blob/master/src/config/festing.php) for descriptions about all the config.
### Cached data
Before we cache the data to make the tests significantly faster we run a list of artisan commands. Be default we run `php artisan migrate`. But if you'd like to change this or want to run more commands (i.e. `php artisan db:seed`) you can change the `commands` array config value.