2017 © Pedro Peláez
 

library setup-test-db

Get efficient with seeding your database for tests in Laravel

image

socialengine/setup-test-db

Get efficient with seeding your database for tests in Laravel

  • Tuesday, September 22, 2015
  • by Danno040
  • Repository
  • 5 Watchers
  • 10 Stars
  • 8,317 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 8 Versions
  • 11 % Grown

The README.md

Setup Test DB Command for Laravel

Latest Stable Version License, (*1)

Integration tests in laravel are great, but the common way to maintain the database is a giant time sink of re-seeding and re-migrating for every single test., (*2)

This command and bootstrap file aims to remove the needless reseeding and migrating (since you're using transactions anyways, right?) for every test and instead gives your tests a "clean" migrated and seeded db., (*3)

Works with sqlite and any others supported by Eloquent., (*4)

Installation

Require this package in composer:, (*5)

$ composer require socialengine/setup-test-db

After updating composer, add the ServiceProvider to the providers array in app/config/app.php., (*6)

'SocialEngine\TestDbSetup\ServiceProvider',

Add a bootstrap/testing.php or copy from vendor/socialengine/setup-test-db/bootstrap/testing.php, (*7)

<?php

// bootstrap/testing.php
$testEnv = (getenv('APP_ENV')) ? : 'testing';

passthru("php " . __DIR__ . "/../artisan db:seed-test --env={$testEnv}");

require __DIR__ . '/autoload.php';

Change your phpunit (or any other framework) bootstrap file from bootstrap/autoload.php to bootstrap/testing.php:, (*8)

<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="./bootstrap/testing.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false"
         syntaxCheck="false"
>

Remove all the migration stuff from your TestCase.php, (*9)

Finally, run your tests in 1/3 the time they used to., (*10)

You can also publish the config-file to change seeder class used and enable truncation., (*11)

$ php artisan config:publish socialengine/setup-test-db

Further reading and inspiration

Most of this is based on the work outlined by Chris Duell in his Speeding up PHP unit tests 15 times blog post:, (*12)

An app I’m currently working on has less that 50% code coverage, and the tests took over 35 seconds to complete., (*13)

It was enough for me to no longer bother consistently running tests, which almost defeats the purpose of self testing code. Until I got fed up enough to spend the time on speeding up the tests, by fifteen times (and almost halving memory usage)., (*14)

License

MIT, (*15)

The Versions

22/09 2015

dev-master

9999999-dev https://github.com/socialengine/setup-test-db

Get efficient with seeding your database for tests in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stepan Mazurov

laravel test phpunit testing db seed codeception seeding

22/09 2015

2.0

2.0.0.0 https://github.com/socialengine/setup-test-db

Get efficient with seeding your database for tests in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stepan Mazurov

laravel test phpunit testing db seed codeception seeding

13/08 2015

1.0.5

1.0.5.0 https://github.com/socialengine/setup-test-db

Get efficient with seeding your database for tests in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stepan Mazurov

laravel test phpunit testing db seed codeception seeding

19/06 2015

1.0.4

1.0.4.0 https://github.com/socialengine/setup-test-db

Get efficient with seeding your database for tests in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stepan Mazurov

laravel test phpunit testing db seed codeception seeding

09/03 2015

1.0.3

1.0.3.0 https://github.com/socialengine/setup-test-db

Get efficient with seeding your database for tests in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stepan Mazurov

laravel test phpunit testing db seed codeception seeding

28/02 2015

1.0.2

1.0.2.0 https://github.com/socialengine/setup-test-db

Get efficient with seeding your database for tests in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stepan Mazurov

laravel test phpunit testing db seed codeception seeding

02/01 2015

1.0.1

1.0.1.0 https://github.com/socialengine/setup-test-db

Get efficient with seeding your database for tests in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stepan Mazurov

laravel test phpunit testing db seed codeception seeding

02/01 2015

1.0.0

1.0.0.0 https://github.com/socialengine/setup-test-db

Get efficient with seeding your database for tests in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stepan Mazurov

laravel test phpunit testing db seed codeception seeding