Skip to content

Commit

Permalink
[8.x] Adds parallel testing (#36034)
Browse files Browse the repository at this point in the history
* Adds parallel testing

* Adds paratest to testing component's "suggest" section
  • Loading branch information
nunomaduro authored Jan 25, 2021
1 parent e720279 commit 958386a
Show file tree
Hide file tree
Showing 32 changed files with 1,479 additions and 3 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,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 int|false 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

0 comments on commit 958386a

Please sign in to comment.