Skip to content

Commit

Permalink
Merge pull request shlinkio#20 from acelaya-forks/feature/parametriza…
Browse files Browse the repository at this point in the history
…ble-db-creation

Allowed to customize the commands to run when invoking TestHelper::cr…
  • Loading branch information
acelaya authored Oct 23, 2021
2 parents adae13f + b15f5fa commit 6067fcc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## [2.3.0] - 2021-10-23
### Added
* Allowed to customize the commands to run when invoking `TestHelper::createTestDb`.

### Changed
* *Nothing*

### Deprecated
* *Nothing*

### Removed
* *Nothing*

### Fixed
* *Nothing*


## [2.2.0] - 2021-08-04
### Added
* *Nothing*
Expand Down
21 changes: 13 additions & 8 deletions src/Helper/TestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@

class TestHelper
{
public function createTestDb(): void
{
$process = new Process(['vendor/bin/doctrine', 'orm:schema-tool:drop', '--force', '--no-interaction', '-q']);
public function createTestDb(
array $createDbCommand = ['vendor/bin/doctrine', 'orm:schema-tool:create'],
array $migrateDbCommand = ['vendor/bin/doctrine-migrations', 'migrations:migrate'],
): void {
$process = new Process($this->withFlags(['vendor/bin/doctrine', 'orm:schema-tool:drop', '--force']));
$process->mustRun();

$process = new Process(
['vendor/bin/doctrine', 'dbal:run-sql', 'DROP TABLE migrations', '--no-interaction', '-q'],
);
$process = new Process($this->withFlags(['vendor/bin/doctrine', 'dbal:run-sql', 'DROP TABLE migrations']));
$process->run(); // The table may not exist, so let's not enforce the successful run

$process = new Process(['vendor/bin/doctrine', 'orm:schema-tool:create', '--no-interaction', '-q']);
$process = new Process($this->withFlags($createDbCommand));
$process->mustRun();

$process = new Process(['vendor/bin/doctrine-migrations', 'migrations:migrate', '--no-interaction', '-q']);
$process = new Process($this->withFlags($migrateDbCommand));
$process->mustRun();
}

Expand All @@ -44,4 +44,9 @@ public function seedFixtures(EntityManagerInterface $em, array $config): void
$executor = new ORMExecutor($em, new ORMPurger());
$executor->execute($loader->getFixtures());
}

private function withFlags(array $command): array
{
return [...$command, '--no-interaction', '-q'];
}
}

0 comments on commit 6067fcc

Please sign in to comment.