-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #692 from nikophil/refactor/remove-migrate-test-pe…
…rmutation
- Loading branch information
Showing
25 changed files
with
520 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
# DBMS can be changed by adding the following in .env.local: | ||
#DATABASE_URL="postgresql://zenstruck:[email protected]:5433/zenstruck_foundry?serverVersion=15" | ||
#DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" | ||
DATABASE_URL="mysql://root:[email protected]:3307/foundry_test?serverVersion=5.7.42" | ||
|
||
# Mongo ca be disabled with the following in .env.local: | ||
# MONGO_URL="" | ||
MONGO_URL="mongodb://127.0.0.1:27018/dbName?compressors=disabled&gssapiServiceName=mongodb" | ||
DATABASE_RESET_MODE="schema" | ||
|
||
USE_DAMA_DOCTRINE_TEST_BUNDLE="0" | ||
USE_FOUNDRY_PHPUNIT_EXTENSION="0" | ||
PHPUNIT_VERSION="9" | ||
PHPUNIT_VERSION="9" # allowed values: 9, 10, 11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,20 +47,15 @@ $ docker compose up --detach | |
# install dependencies | ||
$ composer update | ||
|
||
# run test suite with all available permutations | ||
$ composer test | ||
|
||
# run only one permutation | ||
# run main testsuite (with "schema" reset database strategy) | ||
$ composer test-schema | ||
# or | ||
$ ./phpunit | ||
|
||
# run test suite with dama/doctrine-test-bundle | ||
$ USE_DAMA_DOCTRINE_TEST_BUNDLE=1 vendor/bin/phpunit | ||
|
||
# run test suite with postgreSQL instead of MySQL | ||
$ DATABASE_URL="postgresql://zenstruck:[email protected]:5433/zenstruck_foundry?serverVersion=15" vendor/bin/phpunit | ||
|
||
# run test suite with another PHPUnit version | ||
$ PHPUNIT_VERSION=10 vendor/bin/phpunit | ||
# run "migrate" testsuite (with "migrate" reset database strategy) | ||
$ composer test-migrate | ||
# or | ||
$ ./phpunit --testsuite migrate --bootstrap tests/bootstrap-migrate.php | ||
``` | ||
|
||
### Overriding the default configuration | ||
|
@@ -69,11 +64,20 @@ You can override default environment variables by creating a `.env.local` file, | |
|
||
```bash | ||
# .env.local | ||
DATABASE_URL="postgresql://zenstruck:[email protected]:5433/zenstruck_foundry?serverVersion=15" # enables postgreSQL instead of MySQL | ||
|
||
# change the database to postgreSQL... | ||
DATABASE_URL="postgresql://zenstruck:[email protected]:5433/zenstruck_foundry?serverVersion=15" | ||
# ...or to SQLite | ||
DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" | ||
|
||
MONGO_URL="" # disables Mongo | ||
USE_DAMA_DOCTRINE_TEST_BUNDLE="1" # enables dama/doctrine-test-bundle | ||
PHPUNIT_VERSION="11" # possible values: 9, 10, 11, 11.4 | ||
|
||
# test reset database with configuration migration, | ||
# only relevant for "migrate" testsuite | ||
WITH_MIGRATION_CONFIGURATION_FILE="tests/Fixture/MigrationTests/configs/migration-configuration.php" | ||
|
||
# run test suite with postgreSQL | ||
$ vendor/bin/phpunit | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,16 +14,16 @@ | |
namespace Zenstruck\Foundry\Mongo; | ||
|
||
use Symfony\Component\HttpKernel\KernelInterface; | ||
use Zenstruck\Foundry\Persistence\SymfonyCommandRunner; | ||
|
||
use function Zenstruck\Foundry\application; | ||
use function Zenstruck\Foundry\runCommand; | ||
|
||
/** | ||
* @internal | ||
* @author Nicolas PHILIPPE <[email protected]> | ||
*/ | ||
final class MongoSchemaResetter implements MongoResetter | ||
{ | ||
use SymfonyCommandRunner; | ||
|
||
/** | ||
* @param list<string> $managers | ||
*/ | ||
|
@@ -33,15 +33,15 @@ public function __construct(private array $managers) | |
|
||
public function resetBeforeEachTest(KernelInterface $kernel): void | ||
{ | ||
$application = self::application($kernel); | ||
$application = application($kernel); | ||
|
||
foreach ($this->managers as $manager) { | ||
try { | ||
self::runCommand($application, 'doctrine:mongodb:schema:drop', ['--dm' => $manager]); | ||
runCommand($application, "doctrine:mongodb:schema:drop --dm={$manager}"); | ||
} catch (\Exception) { | ||
} | ||
|
||
self::runCommand($application, 'doctrine:mongodb:schema:create', ['--dm' => $manager]); | ||
runCommand($application, "doctrine:mongodb:schema:create --dm={$manager}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,20 @@ | |
use Doctrine\DBAL\Platforms\PostgreSQLPlatform; | ||
use Doctrine\DBAL\Platforms\SQLitePlatform; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Zenstruck\Foundry\Persistence\SymfonyCommandRunner; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
|
||
use Zenstruck\Foundry\ORM\DoctrineOrmVersionGuesser; | ||
|
||
use function Zenstruck\Foundry\runCommand; | ||
|
||
/** | ||
* @author Nicolas PHILIPPE <[email protected]> | ||
* @internal | ||
*/ | ||
abstract class BaseOrmResetter | ||
abstract class BaseOrmResetter implements OrmResetter | ||
{ | ||
use SymfonyCommandRunner; | ||
private static bool $inFirstTest = true; | ||
|
||
/** | ||
* @param list<string> $managers | ||
|
@@ -30,6 +35,19 @@ public function __construct( | |
) { | ||
} | ||
|
||
final public function resetBeforeEachTest(KernelInterface $kernel): void | ||
{ | ||
if (self::$inFirstTest) { | ||
self::$inFirstTest = false; | ||
|
||
return; | ||
} | ||
|
||
$this->doResetBeforeEachTest($kernel); | ||
} | ||
|
||
abstract protected function doResetBeforeEachTest(KernelInterface $kernel): void; | ||
|
||
final protected function dropAndResetDatabase(Application $application): void | ||
{ | ||
foreach ($this->connections as $connectionName) { | ||
|
@@ -39,29 +57,26 @@ final protected function dropAndResetDatabase(Application $application): void | |
|
||
if ($databasePlatform instanceof SQLitePlatform) { | ||
// we don't need to create the sqlite database - it's created when the schema is created | ||
// let's only drop the .db file | ||
|
||
$dbPath = $connection->getParams()['path'] ?? null; | ||
$fs = new Filesystem(); | ||
if (DoctrineOrmVersionGuesser::isOrmV3() && $dbPath && $fs->exists($dbPath)) { | ||
(new Filesystem())->remove($dbPath); | ||
} | ||
|
||
continue; | ||
} | ||
|
||
if ($databasePlatform instanceof PostgreSQLPlatform) { | ||
// let's drop all connections to the database to be able to drop it | ||
self::runCommand( | ||
$application, | ||
'dbal:run-sql', | ||
[ | ||
'--connection' => $connectionName, | ||
'sql' => 'SELECT pid, pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = current_database() AND pid <> pg_backend_pid()', | ||
], | ||
canFail: true, | ||
); | ||
$sql = 'SELECT pid, pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = current_database() AND pid <> pg_backend_pid()'; | ||
runCommand($application, "dbal:run-sql --connection={$connectionName} '{$sql}'", canFail: true); | ||
} | ||
|
||
self::runCommand( | ||
$application, | ||
'doctrine:database:drop', | ||
['--connection' => $connectionName, '--force' => true, '--if-exists' => true] | ||
); | ||
runCommand($application, "doctrine:database:drop --connection={$connectionName} --force --if-exists"); | ||
|
||
self::runCommand($application, 'doctrine:database:create', ['--connection' => $connectionName]); | ||
runCommand($application, "doctrine:database:create --connection={$connectionName}"); | ||
} | ||
} | ||
} |
Oops, something went wrong.