Skip to content

[9.x] Adds support for Parallel Testing #35778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 52 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
6418fed
Adds parallel testing
nunomaduro Jan 4, 2021
dcc5112
Fixes "Class MysqlBuilder" not found
nunomaduro Jan 4, 2021
bb004e5
Updates wording when drivers do not support create/drop databases
nunomaduro Jan 4, 2021
8e30c93
Avoids "getenv" and "putenv" in favour of $_SERVER
nunomaduro Jan 5, 2021
36d5e7a
Moves "createDatabaseIfNotExists" to "createDatabase"
nunomaduro Jan 5, 2021
a546cf2
Adds support to "Postgres"
nunomaduro Jan 5, 2021
b0b6243
Fixes CS
nunomaduro Jan 5, 2021
5697ee4
Uses a database per process regardless of the used database testing t…
nunomaduro Jan 7, 2021
07d9cb3
Apply fixes from StyleCI
nunomaduro Jan 7, 2021
d9ba522
Merge pull request #3 from nunomaduro/analysis-wj2l5w
nunomaduro Jan 7, 2021
83f648d
Removes unused catch
nunomaduro Jan 7, 2021
d4afcf2
Merge branch 'feat/adds-parallel-testing' of https://github.com/nunom…
nunomaduro Jan 7, 2021
66d2dcc
Refactors into service providers
nunomaduro Jan 7, 2021
70a231e
Apply fixes from StyleCI
nunomaduro Jan 7, 2021
f08a714
Merge pull request #4 from nunomaduro/analysis-KZ6kV6
nunomaduro Jan 7, 2021
2f60c87
Removes token resolver from the public API
nunomaduro Jan 7, 2021
208bf65
Renames Parallel Testing register callbacks
nunomaduro Jan 7, 2021
447c27b
Fixes CS
nunomaduro Jan 7, 2021
27a2c49
Adds "setUp" process and "tearDown" test case
nunomaduro Jan 8, 2021
e18d25d
Updates Parallel Testing facade
nunomaduro Jan 8, 2021
f140288
Suffixes _test_ on storage too
nunomaduro Jan 8, 2021
2793882
Fixes missing envs for process callbacks
nunomaduro Jan 8, 2021
0cd2df7
Apply fixes from StyleCI
nunomaduro Jan 8, 2021
9749170
Merge pull request #5 from nunomaduro/analysis-OMYD5l
nunomaduro Jan 8, 2021
8c560a6
Ensures "drops" only happen when needed
nunomaduro Jan 8, 2021
0f1e621
Apply fixes from StyleCI
nunomaduro Jan 8, 2021
f690305
Merge pull request #6 from nunomaduro/analysis-e7kaPv
nunomaduro Jan 8, 2021
29d705c
Adds support for SQLite file databases
nunomaduro Jan 11, 2021
52de4b4
Adds tests for SQLite file databases
nunomaduro Jan 11, 2021
f255cee
Lower case create/drop statements
nunomaduro Jan 11, 2021
3d62d42
Adds support for SQL Server
nunomaduro Jan 11, 2021
2a5c678
Apply fixes from StyleCI
nunomaduro Jan 11, 2021
0bb1ca2
Merge pull request #7 from nunomaduro/analysis-d02NGv
nunomaduro Jan 11, 2021
d29bb9d
Adds tests against Parallel Testing callbacks
nunomaduro Jan 11, 2021
b2c3296
Adds tests for parallel console output
nunomaduro Jan 11, 2021
49c4b28
Apply fixes from StyleCI
nunomaduro Jan 11, 2021
df2107d
Merge pull request #8 from nunomaduro/analysis-Zl51bP
nunomaduro Jan 11, 2021
e85ed40
Removes unused lines in tests
nunomaduro Jan 11, 2021
3c6d8d1
Merge branch 'feat/adds-parallel-testing' of https://github.com/nunom…
nunomaduro Jan 11, 2021
cc4bffa
Calls Parallel Testing setUp callbacks after refresh app only
nunomaduro Jan 11, 2021
4f57aac
Cleans folders for parallel testing
nunomaduro Jan 11, 2021
69b9eb0
Makes test databases persist
nunomaduro Jan 12, 2021
b389c43
Apply fixes from StyleCI
nunomaduro Jan 12, 2021
f280ffa
Merge pull request #9 from nunomaduro/analysis-3w0NZr
nunomaduro Jan 12, 2021
528b6bd
Resolve parallel testing callbacks from container
nunomaduro Jan 12, 2021
c15917c
Merge branch 'feat/adds-parallel-testing' of https://github.com/nunom…
nunomaduro Jan 12, 2021
0f4c024
Apply fixes from StyleCI
nunomaduro Jan 12, 2021
85c5558
Merge pull request #10 from nunomaduro/analysis-gOgb36
nunomaduro Jan 12, 2021
f52fa9e
Update TestDatabases.php
taylorotwell Jan 12, 2021
985c3d3
Update ParallelTesting.php
taylorotwell Jan 12, 2021
a3109db
Renames "refresh-databases" to "recreate-databases"
nunomaduro Jan 13, 2021
8e0c299
Merge branch 'feat/adds-parallel-testing' of https://github.com/nunom…
nunomaduro Jan 13, 2021
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"ext-posix": "Required to use all features of the queue worker.",
"ext-redis": "Required to use the Redis cache and queue drivers (^4.0|^5.0).",
"aws/aws-sdk-php": "Required to use the SQS queue driver, DynamoDb failed job storage and SES mail driver (^3.155).",
"brianium/paratest": "Required to run tests in parallel (^6.0).",
"doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6|^3.0).",
"filp/whoops": "Required for friendly error pages in development (^2.8).",
"fakerphp/faker": "Required to use the eloquent factory builder (^1.9.1).",
Expand Down
22 changes: 22 additions & 0 deletions src/Illuminate/Database/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,28 @@ public static function morphUsingUuids()
return static::defaultMorphKeyType('uuid');
}

/**
* Create a database in the schema.
*
* @param string $name
* @return bool
*/
public function createDatabase($name)
{
throw new LogicException('This database driver does not support creating databases.');
}

/**
* Drop a database from the schema if the database exists.
*
* @param string $name
* @return bool
*/
public function dropDatabaseIfExists($name)
{
throw new LogicException('This database driver does not support dropping databases.');
}

/**
* Determine if the given table exists.
*
Expand Down
24 changes: 24 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Database\Query\Expression;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Fluent;
use LogicException;
use RuntimeException;

abstract class Grammar extends BaseGrammar
Expand All @@ -27,6 +28,29 @@ abstract class Grammar extends BaseGrammar
*/
protected $fluentCommands = [];

/**
* Compile a create database command.
*
* @param string $name
* @param \Illuminate\Database\Connection $connection
* @return string
*/
public function compileCreateDatabase($name, $connection)
{
throw new LogicException('This database driver does not support creating databases.');
}

/**
* Compile a drop database if exists command.
*
* @param string $name
* @return string
*/
public function compileDropDatabaseIfExists($name)
{
throw new LogicException('This database driver does not support dropping databases.');
}

/**
* Compile a rename column command.
*
Expand Down
31 changes: 31 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,37 @@ class MySqlGrammar extends Grammar
*/
protected $serials = ['bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger'];

/**
* Compile a create database command.
*
* @param string $name
* @param \Illuminate\Database\Connection $connection
* @return string
*/
public function compileCreateDatabase($name, $connection)
{
return sprintf(
'create database %s default character set %s default collate %s',
$this->wrapValue($name),
$this->wrapValue($connection->getConfig('charset')),
$this->wrapValue($connection->getConfig('collation')),
);
}

/**
* Compile a drop database if exists command.
*
* @param string $name
* @return string
*/
public function compileDropDatabaseIfExists($name)
{
return sprintf(
'drop database if exists %s',
$this->wrapValue($name)
);
}

/**
* Compile the query to determine the list of tables.
*
Expand Down
30 changes: 30 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ class PostgresGrammar extends Grammar
*/
protected $fluentCommands = ['Comment'];

/**
* Compile a create database command.
*
* @param string $name
* @param \Illuminate\Database\Connection $connection
* @return string
*/
public function compileCreateDatabase($name, $connection)
{
return sprintf(
'create database %s encoding %s',
$this->wrapValue($name),
$this->wrapValue($connection->getConfig('charset')),
);
}

/**
* Compile a drop database if exists command.
*
* @param string $name
* @return string
*/
public function compileDropDatabaseIfExists($name)
{
return sprintf(
'drop database if exists %s',
$this->wrapValue($name)
);
}

/**
* Compile the query to determine if a table exists.
*
Expand Down
29 changes: 29 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,35 @@ class SqlServerGrammar extends Grammar
*/
protected $serials = ['tinyInteger', 'smallInteger', 'mediumInteger', 'integer', 'bigInteger'];

/**
* Compile a create database command.
*
* @param string $name
* @param \Illuminate\Database\Connection $connection
* @return string
*/
public function compileCreateDatabase($name, $connection)
{
return sprintf(
'create database %s',
$this->wrapValue($name),
);
}

/**
* Compile a drop database if exists command.
*
* @param string $name
* @return string
*/
public function compileDropDatabaseIfExists($name)
{
return sprintf(
'drop database if exists %s',
$this->wrapValue($name)
);
}

/**
* Compile the query to determine if a table exists.
*
Expand Down
26 changes: 26 additions & 0 deletions src/Illuminate/Database/Schema/MySqlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@

class MySqlBuilder extends Builder
{
/**
* Create a database in the schema.
*
* @param string $name
* @return bool
*/
public function createDatabase($name)
{
return $this->connection->statement(
$this->grammar->compileCreateDatabase($name, $this->connection)
);
}

/**
* Drop a database from the schema if the database exists.
*
* @param string $name
* @return bool
*/
public function dropDatabaseIfExists($name)
{
return $this->connection->statement(
$this->grammar->compileDropDatabaseIfExists($name)
);
}

/**
* Determine if the given table exists.
*
Expand Down
26 changes: 26 additions & 0 deletions src/Illuminate/Database/Schema/PostgresBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@

class PostgresBuilder extends Builder
{
/**
* Create a database in the schema.
*
* @param string $name
* @return bool
*/
public function createDatabase($name)
{
return $this->connection->statement(
$this->grammar->compileCreateDatabase($name, $this->connection)
);
}

/**
* Drop a database from the schema if the database exists.
*
* @param string $name
* @return bool
*/
public function dropDatabaseIfExists($name)
{
return $this->connection->statement(
$this->grammar->compileDropDatabaseIfExists($name)
);
}

/**
* Determine if the given table exists.
*
Expand Down
26 changes: 26 additions & 0 deletions src/Illuminate/Database/Schema/SQLiteBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,34 @@

namespace Illuminate\Database\Schema;

use Illuminate\Support\Facades\File;

class SQLiteBuilder extends Builder
{
/**
* Create a database in the schema.
*
* @param string $name
* @return bool
*/
public function createDatabase($name)
{
return File::put($name, '') !== false;
}

/**
* Drop a database from the schema if the database exists.
*
* @param string $name
* @return bool
*/
public function dropDatabaseIfExists($name)
{
return File::exists($name)
? File::delete($name)
: true;
}

/**
* Drop all tables from the database.
*
Expand Down
26 changes: 26 additions & 0 deletions src/Illuminate/Database/Schema/SqlServerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@

class SqlServerBuilder extends Builder
{
/**
* Create a database in the schema.
*
* @param string $name
* @return bool
*/
public function createDatabase($name)
{
return $this->connection->statement(
$this->grammar->compileCreateDatabase($name, $this->connection)
);
}

/**
* Drop a database from the schema if the database exists.
*
* @param string $name
* @return bool
*/
public function dropDatabaseIfExists($name)
{
return $this->connection->statement(
$this->grammar->compileDropDatabaseIfExists($name)
);
}

/**
* Drop all tables from the database.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\AggregateServiceProvider;
use Illuminate\Support\Facades\URL;
use Illuminate\Testing\ParallelTestingServiceProvider;
use Illuminate\Validation\ValidationException;

class FoundationServiceProvider extends AggregateServiceProvider
Expand All @@ -16,6 +17,7 @@ class FoundationServiceProvider extends AggregateServiceProvider
*/
protected $providers = [
FormRequestServiceProvider::class,
ParallelTestingServiceProvider::class,
];

/**
Expand Down
5 changes: 5 additions & 0 deletions src/Illuminate/Foundation/Testing/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Console\Application as Artisan;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\ParallelTesting;
use Illuminate\Support\Str;
use Mockery;
use Mockery\Exception\InvalidCountException;
Expand Down Expand Up @@ -81,6 +82,8 @@ protected function setUp(): void

if (! $this->app) {
$this->refreshApplication();

ParallelTesting::callSetUpTestCaseCallbacks($this);
}

$this->setUpTraits();
Expand Down Expand Up @@ -152,6 +155,8 @@ protected function tearDown(): void
if ($this->app) {
$this->callBeforeApplicationDestroyedCallbacks();

ParallelTesting::callTearDownTestCaseCallbacks($this);

$this->app->flush();

$this->app = null;
Expand Down
25 changes: 25 additions & 0 deletions src/Illuminate/Support/Facades/ParallelTesting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Illuminate\Support\Facades;

/**
* @method static void setUpProcess(callable $callback)
* @method static void setUpTestCase(callable $callback)
* @method static void tearDownProcess(callable $callback)
* @method static void tearDownTestCase(callable $callback)
* @method static string token()
*
* @see \Illuminate\Testing\ParallelTesting
*/
class ParallelTesting extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return \Illuminate\Testing\ParallelTesting::class;
}
}
2 changes: 2 additions & 0 deletions src/Illuminate/Support/Facades/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

/**
* @method static \Illuminate\Database\Schema\Builder create(string $table, \Closure $callback)
* @method static \Illuminate\Database\Schema\Builder createDatabase(string $name)
* @method static \Illuminate\Database\Schema\Builder disableForeignKeyConstraints()
* @method static \Illuminate\Database\Schema\Builder drop(string $table)
* @method static \Illuminate\Database\Schema\Builder dropDatabaseIfExists(string $name)
* @method static \Illuminate\Database\Schema\Builder dropIfExists(string $table)
* @method static \Illuminate\Database\Schema\Builder enableForeignKeyConstraints()
* @method static \Illuminate\Database\Schema\Builder rename(string $from, string $to)
Expand Down
Loading