{"id":16754731,"url":"https://github.com/socialengine/setup-test-db","last_synced_at":"2025-04-10T16:14:04.765Z","repository":{"id":25275016,"uuid":"28700620","full_name":"SocialEngine/setup-test-db","owner":"SocialEngine","description":"Get efficient with seeding your database for tests in Laravel","archived":false,"fork":false,"pushed_at":"2016-12-27T20:31:08.000Z","size":176,"stargazers_count":9,"open_issues_count":1,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-24T14:07:25.663Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SocialEngine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-02T01:46:24.000Z","updated_at":"2021-11-16T05:27:22.000Z","dependencies_parsed_at":"2022-08-24T06:00:47.468Z","dependency_job_id":null,"html_url":"https://github.com/SocialEngine/setup-test-db","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SocialEngine%2Fsetup-test-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SocialEngine%2Fsetup-test-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SocialEngine%2Fsetup-test-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SocialEngine%2Fsetup-test-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SocialEngine","download_url":"https://codeload.github.com/SocialEngine/setup-test-db/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248251705,"owners_count":21072692,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T03:05:45.860Z","updated_at":"2025-04-10T16:14:04.722Z","avatar_url":"https://github.com/SocialEngine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Setup Test DB Command for Laravel\n====\n[![Latest Stable Version](https://poser.pugx.org/socialengine/setup-test-db/version.png)](https://packagist.org/packages/socialengine/setup-test-db) [![License](https://poser.pugx.org/socialengine/setup-test-db/license.svg)](https://packagist.org/packages/socialengine/setup-test-db)\n\nIntegration tests in laravel are great, but the common way to maintain the database is a giant time sink\nof re-seeding and re-migrating for every single test.\n\nThis command and bootstrap file aims to remove the needless reseeding and migrating (since you're using\ntransactions anyways, right?) for every test and instead gives your tests a \"clean\" migrated and seeded db.\n\nWorks with `sqlite` and any others supported by Eloquent.\n\n## Installation\n\nRequire this package in composer:\n```\n$ composer require socialengine/setup-test-db\n```\n\nAfter updating composer, add the ServiceProvider to the providers array in `app/config/app.php`.\n\n```\n'SocialEngine\\TestDbSetup\\ServiceProvider',\n```\n\nAdd a `bootstrap/testing.php` or copy from `vendor/socialengine/setup-test-db/bootstrap/testing.php`\n\n```php\n\u003c?php\n\n// bootstrap/testing.php\n$testEnv = (getenv('APP_ENV')) ? : 'testing';\n\npassthru(\"php \" . __DIR__ . \"/../artisan db:seed-test --env={$testEnv}\");\n\nrequire __DIR__ . '/autoload.php';\n```\n\nChange your `phpunit` (or any other framework) bootstrap file from `bootstrap/autoload.php` to `bootstrap/testing.php`:\n```xml\n\u003cphpunit backupGlobals=\"false\"\n         backupStaticAttributes=\"false\"\n         bootstrap=\"./bootstrap/testing.php\"\n         colors=\"true\"\n         convertErrorsToExceptions=\"true\"\n         convertNoticesToExceptions=\"true\"\n         convertWarningsToExceptions=\"true\"\n         processIsolation=\"false\"\n         stopOnFailure=\"false\"\n         syntaxCheck=\"false\"\n\u003e\n```\n\nRemove all the migration stuff from your `TestCase.php`\n\nFinally, run your tests in 1/3 the time they used to.\n\nYou can also publish the config-file to change seeder class used and enable truncation.\n\n```\n$ php artisan config:publish socialengine/setup-test-db\n```\n\n## Further reading and inspiration\n\nMost of this is based on the work outlined by Chris Duell in his\n[Speeding up PHP unit tests 15 times](http://www.chrisduell.com/blog/development/speeding-up-unit-tests-in-php/)\nblog post:\n\n\u003e An app I’m currently working on has less that 50% code coverage, and the tests took over 35 seconds to complete.\n\u003e\n\u003e It was enough for me to no longer bother consistently running tests, which almost defeats the purpose of self\n\u003e testing code. Until I got fed up enough to spend the time on speeding up the tests,\n\u003e **by fifteen times** (and almost halving memory usage).\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocialengine%2Fsetup-test-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsocialengine%2Fsetup-test-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocialengine%2Fsetup-test-db/lists"}