Skip to content
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

Tests: Speedup local execution #2002

Closed
wants to merge 5 commits into from
Closed
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
33 changes: 0 additions & 33 deletions tests/Fixtures/migration-command/propel.yaml.dist

This file was deleted.

47 changes: 30 additions & 17 deletions tests/Propel/Tests/Generator/Command/MigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@
*/
class MigrationTest extends TestCaseFixturesDatabase
{

/**
* Directory with default connection (can be any, schema.xml files use a
* schema prefix for tables, so initial connection does not matter)
*
* @var string
*/
private const CONNECTION_CONFIG_DIR = __DIR__ . '/../../../../Fixtures/migration';

/**
* Used when retrieving connection by name
* (can be any, same as CONNECTION_CONFIG_DIR)
*
* @var string
*/
private const DATABASE_NAME = 'migration';

/**
* @var bool
*/
Expand All @@ -34,7 +51,7 @@ class MigrationTest extends TestCaseFixturesDatabase
/**
* @var string
*/
private const SCHEMA_DIR = __DIR__ . '/../../../../Fixtures/migration-command';
private const BASE_SCHEMA_DIR = __DIR__ . '/util/migrate-to-version/base';

/**
* @var string
Expand All @@ -44,7 +61,7 @@ class MigrationTest extends TestCaseFixturesDatabase
/**
* @var string
*/
private const SCHEMA_DIR_MIGRATE_TO_VERSION = __DIR__ . '/../../../../Fixtures/migrate-to-version';
private const SCHEMA_DIR_MIGRATE_TO_VERSION_PATTERN = __DIR__ . '/util/migrate-to-version/version-*';

/**
* @see \Propel\Generator\Command\MigrationMigrateCommand::COMMAND_OPTION_MIGRATE_TO_VERSION
Expand Down Expand Up @@ -78,7 +95,7 @@ class MigrationTest extends TestCaseFixturesDatabase
public function testDiffCommandCreatesFiles(): void
{
$this->deleteMigrationFiles();
$this->runCommandAndAssertSuccess('migration:diff', new MigrationDiffCommand(), ['--schema-dir' => self::SCHEMA_DIR]);
$this->runCommandAndAssertSuccess('migration:diff', new MigrationDiffCommand(), ['--schema-dir' => self::BASE_SCHEMA_DIR]);
$this->assertGeneratedFileContainsCreateTableStatement(true, 'PropelMigration_*.php');
}

Expand All @@ -89,7 +106,7 @@ public function testDiffCommandCreatesSuffixedFiles(): void
{
$this->deleteMigrationFiles();
$suffix = 'an_explanatory_filename_suffix';
$this->runCommandAndAssertSuccess('migration:diff', new MigrationDiffCommand(), ['--schema-dir' => self::SCHEMA_DIR, '--suffix' => $suffix]);
$this->runCommandAndAssertSuccess('migration:diff', new MigrationDiffCommand(), ['--schema-dir' => self::BASE_SCHEMA_DIR, '--suffix' => $suffix]);
$this->assertGeneratedFileContainsCreateTableStatement(true, "PropelMigration_*_$suffix.php");
}

Expand All @@ -99,7 +116,7 @@ public function testDiffCommandCreatesSuffixedFiles(): void
public function testCreateCommandCreatesFiles(): void
{
$this->deleteMigrationFiles();
$this->runCommandAndAssertSuccess('migration:create', new MigrationCreateCommand(), ['--schema-dir' => self::SCHEMA_DIR]);
$this->runCommandAndAssertSuccess('migration:create', new MigrationCreateCommand(), ['--schema-dir' => self::BASE_SCHEMA_DIR]);
$this->assertGeneratedFileContainsCreateTableStatement(false, 'PropelMigration_*.php');
}

Expand All @@ -110,7 +127,7 @@ public function testCreateCommandCreatesSuffixedFiles(): void
{
$this->deleteMigrationFiles();
$suffix = 'an_explanatory_filename_suffix';
$this->runCommandAndAssertSuccess('migration:create', new MigrationCreateCommand(), ['--schema-dir' => self::SCHEMA_DIR, '--suffix' => $suffix]);
$this->runCommandAndAssertSuccess('migration:create', new MigrationCreateCommand(), ['--schema-dir' => self::BASE_SCHEMA_DIR, '--suffix' => $suffix]);
$this->assertGeneratedFileContainsCreateTableStatement(false, "PropelMigration_*_$suffix.php");
}

Expand Down Expand Up @@ -379,11 +396,11 @@ private function buildApplicationInputArguments(string $commandName, array $addi
{
$additionalArguments['command'] = $commandName;

$dsn = $this->getConnectionDsn('bookstore', true);
$dsn = $this->getConnectionDsn(static::DATABASE_NAME, true);
$connectionOption = ['migration_command=' . $dsn];

$defaultAppArguments = [
'--config-dir' => self::SCHEMA_DIR,
'--config-dir' => self::CONNECTION_CONFIG_DIR,
'--output-dir' => self::OUTPUT_DIR,
'--platform' => ucfirst($this->getDriver()) . 'Platform',
'--connection' => $connectionOption,
Expand Down Expand Up @@ -434,26 +451,22 @@ private function assertIsCurrentVersion(int $version): void
}

/**
* Creates migratoins according to the schemas in the folders
* ./util/migrate-to-version/version-* and applies them.
*
* @return void
*/
private function setUpMigrateToVersion(): void
{
$this->deleteMigrationFiles();

/** @var array<string> $versionDirectories */
$versionDirectories = glob(
sprintf(
'%s%s*',
self::SCHEMA_DIR_MIGRATE_TO_VERSION,
DIRECTORY_SEPARATOR,
),
GLOB_ONLYDIR,
);
$versionDirectories = glob(self::SCHEMA_DIR_MIGRATE_TO_VERSION_PATTERN, GLOB_ONLYDIR);

foreach ($versionDirectories as $versionDirectory) {
$this->runCommand('migration:diff', new MigrationDiffCommand(), ['--schema-dir' => $versionDirectory]);
$this->migrateUp();
sleep(1);
time_nanosleep(1, 0); // sleep one second to ensure distinct timestamps on migration files
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<database name="migration_command">
<database name="migration_command" schema="migration_command_db">

<table name="table1">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" description="Book Id"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<database name="migration_command">
<database name="migration_command" schema="migration_command_db">

<table name="table1">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" description="Book Id"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<database name="migration_command">
<database name="migration_command" schema="migration_command_db">

<table name="table1">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" description="Book Id"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<database name="migration_command">
<database name="migration_command" schema="migration_command_db">

<table name="table1">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" description="Book Id"/>
Expand Down
8 changes: 8 additions & 0 deletions tests/Propel/Tests/Generator/Platform/DefaultPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,12 @@ public function testGetColumnBindingPHP($column, $default)
{
$this->assertStringContainsString($default, $this->getPlatform()->getColumnBindingPHP($column, 'ID', 'ACCESSOR'));
}

/**
* @return void
*/
public function testDoesNotSupportNativeOnDeleteTriggers()
{
$this->assertFalse($this->getPlatform()->supportsNativeDeleteTrigger());
}
}
2 changes: 2 additions & 0 deletions tests/bin/setup.mysql.bat
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ DROP SCHEMA IF EXISTS second_hand_books;^
DROP SCHEMA IF EXISTS contest;^
DROP SCHEMA IF EXISTS bookstore_schemas;^
DROP SCHEMA IF EXISTS migration;^
DROP SCHEMA IF EXISTS migration_command_db;^
SET FOREIGN_KEY_CHECKS = 1;^
"
call %DIR%\base.bat :check
Expand All @@ -49,6 +50,7 @@ CREATE SCHEMA bookstore_schemas;^
CREATE SCHEMA contest;^
CREATE SCHEMA second_hand_books;^
CREATE SCHEMA migration;^
CREATE SCHEMA migration_command_db;^
"
call %DIR%\base.bat :check
if "%errorlevel%" == "1" exit /B 1
2 changes: 2 additions & 0 deletions tests/bin/setup.mysql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ DB_PORT=${DB_PORT-3306};
DROP SCHEMA IF EXISTS contest;
DROP SCHEMA IF EXISTS bookstore_schemas;
DROP SCHEMA IF EXISTS migration;
DROP SCHEMA IF EXISTS migration_command_db;
SET FOREIGN_KEY_CHECKS = 1;
" || exit 1;

Expand All @@ -41,6 +42,7 @@ DB_PORT=${DB_PORT-3306};
CREATE SCHEMA contest;
CREATE SCHEMA second_hand_books;
CREATE SCHEMA migration;
CREATE SCHEMA migration_command_db;
" || exit 1;
) || exit 1;

Expand Down
1 change: 1 addition & 0 deletions tests/bin/setup.pgsql.bat
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CREATE SCHEMA bookstore_schemas;^
CREATE SCHEMA contest;^
CREATE SCHEMA second_hand_books;^
CREATE SCHEMA migration;^
CREATE SCHEMA migration_command_db;^
" "%DB_NAME%"

call %DIR%\base.bat :check
Expand Down
3 changes: 2 additions & 1 deletion tests/bin/setup.pgsql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if [ "$DB_NAME" = "" ]; then
fi

DB_HOSTNAME=${DB_HOSTNAME-127.0.0.1};
DB_PW=${DB_PW-$PGPASSWORD};.0.1};
DB_PW=${DB_PW-$PGPASSWORD};
DB_PORT=${DB_PORT-5432};

if [ -z "$DB_PW" ]; then
Expand All @@ -40,6 +40,7 @@ fi
CREATE SCHEMA contest;
CREATE SCHEMA second_hand_books;
CREATE SCHEMA migration;
CREATE SCHEMA migration_command_db;
' "$DB_NAME" >/dev/null;
) || exit 1;

Expand Down
Loading