Download the PHP package othmanhaba/laravel-test-container without Composer

On this page you can find all versions of the php package othmanhaba/laravel-test-container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-test-container

laravel-test-container

Run your Laravel test suite in parallel against a disposable MySQL or PostgreSQL container. Boots the database, runs the tests, throws the container away.

No container left behind — including when you hit Ctrl-C.

Install

Docker must be running. That's the whole setup — the config file is optional.

Usage

Every option it doesn't recognise is forwarded to artisan test, so what you already know keeps working:

Its own options:

Option Effect
--driver= mysql or pgsql. Defaults to config.
--tag= Image tag, e.g. --tag=8.0. Defaults to mysql:8.4 / postgres:16.
--reuse Keep the container alive for the next run.
--no-parallel Single process, for when parallel output makes debugging hard.
--skip-container-check Skip the post-run check described below.

Publish the config if you want different defaults:

How it works

One container, many databases. Laravel's --parallel mode already gives each worker its own schema — testing_test_1, testing_test_2, and so on — created and migrated for you. So this package boots one database server and lets Laravel do the rest. Eight containers for eight workers would cost a minute of boot time and several gigabytes of RAM for no isolation you don't already have.

Because Laravel creates those databases at runtime, the container's superuser is used. Don't swap it for a restricted account; parallel mode needs CREATE DATABASE.

*The connection is injected through a service provider, not `DB_env vars.** This is the part that isn't obvious. A typicalphpunit.xml` contains:

With force="true", PHPUnit overwrites any environment variable we export. The suite then runs green against in-memory SQLite while a MySQL container sits idle next to it — passing, and testing nothing you booted. So the connection is applied in a service provider instead, which registers when the app boots inside each worker, after PHPUnit is done setting env vars. It also layers over cached config, so config:cache is harmless.

And it's verified afterwards. Once the suite finishes, the command checks that worker databases actually exist in the container. If nothing was written, it fails with a pointer at your phpunit.xml rather than reporting a green run.

Disposable means disposable. The data directory is a tmpfs and durability is turned off (innodb-flush-log-at-trx-commit=0, fsync=off), which is free speed when the data is discarded regardless.

The host port is chosen by Docker, never guessed. The container is published on port 0, which means "allocate a free port and bind it" in one atomic step. Your locally-installed MySQL keeps 3306, your Postgres keeps 5432, other projects' containers keep theirs, and two runs of this command at the same time cannot collide. Nothing probes a port and hopes it is still free a moment later.

Cleanup

Situation Handled by
Tests finish, pass or fail finally
Uncaught exception finally
Ctrl-C, kill Signal handler
PHP fatal error Shutdown backstop
kill -9, machine loses power Nothing — run test:container:prune

Removes anything this package left running. Also the reset button for a stale --reuse container.

--reuse

Skips the ~8s boot by keeping the container between runs:

The trade-off is real and worth stating: state survives from the previous run. If you change migrations while using --reuse, expect confusing failures. test:container:prune clears it.

Requirements

On Windows, pcntl is unavailable, so Ctrl-C won't clean up. test:container:prune covers it.

Testing this package

License

MIT


All versions of laravel-test-container with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/console Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.0
symfony/process Version ^7.0
testcontainers/testcontainers Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package othmanhaba/laravel-test-container contains the following files

Loading the files please wait ...