Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions database/mysql/create-testing-database.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

mysql --user=root --password="$MYSQL_ROOT_PASSWORD" <<-EOSQL
CREATE DATABASE IF NOT EXISTS testing;
GRANT ALL PRIVILEGES ON testing.* TO '$MYSQL_USER'@'%';
EOSQL
2 changes: 2 additions & 0 deletions database/pgsql/create-testing-database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT 'CREATE DATABASE testing'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'testing')\gexec
16 changes: 16 additions & 0 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function handle()

$this->buildDockerCompose($services);
$this->replaceEnvVariables($services);
$this->configurePhpUnit();

if ($this->option('devcontainer')) {
$this->installDevContainer();
Expand Down Expand Up @@ -148,6 +149,21 @@ protected function replaceEnvVariables(array $services)
file_put_contents($this->laravel->basePath('.env'), $environment);
}

/**
* Configure PHPUnit to use the dedicated testing database.
*
* @return void
*/
protected function configurePhpUnit()
{
$phpunit = file_get_contents($this->laravel->basePath('phpunit.xml'));

$phpunit = preg_replace('/^.*DB_CONNECTION.*\n/m', '', $phpunit);
$phpunit = str_replace('<!-- <env name="DB_DATABASE" value=":memory:"/> -->', '<env name="DB_DATABASE" value="testing"/>', $phpunit);

file_put_contents($this->laravel->basePath('phpunit.xml'), $phpunit);
}

/**
* Install the devcontainer.json configuration file.
*
Expand Down
1 change: 1 addition & 0 deletions stubs/mariadb.stub
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sail-mariadb:/var/lib/mysql'
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
healthcheck:
Expand Down
1 change: 1 addition & 0 deletions stubs/mysql.stub
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'sail-mysql:/var/lib/mysql'
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
healthcheck:
Expand Down
1 change: 1 addition & 0 deletions stubs/pgsql.stub
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}'
volumes:
- 'sail-pgsql:/var/lib/postgresql/data'
- './vendor/laravel/sail/database/pgsql/create-testing-database.sql:/docker-entrypoint-initdb.d/10-create-testing-database.sql'
networks:
- sail
healthcheck:
Expand Down