-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract reset:migration tests in another testsuite
- Loading branch information
Showing
22 changed files
with
473 additions
and
214 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,5 +1,4 @@ | ||
DATABASE_URL="mysql://root:[email protected]:3307/foundry_test?serverVersion=5.7.42" | ||
MONGO_URL="mongodb://127.0.0.1:27018/dbName?compressors=disabled&gssapiServiceName=mongodb" | ||
DATABASE_RESET_MODE="schema" | ||
USE_DAMA_DOCTRINE_TEST_BUNDLE="0" | ||
PHPUNIT_VERSION="9" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,16 +5,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 | ||
*/ | ||
|
@@ -24,15 +24,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,16 +9,17 @@ | |
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 function Zenstruck\Foundry\runCommand; | ||
|
||
/** | ||
* @author Nicolas PHILIPPE <[email protected]> | ||
* @internal | ||
*/ | ||
abstract class BaseOrmResetter | ||
{ | ||
use SymfonyCommandRunner; | ||
|
||
/** | ||
* @param list<string> $managers | ||
* @param list<string> $connections | ||
|
@@ -39,29 +40,24 @@ 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 | ||
|
||
if ($dbPath = $connection->getParams()['path'] ?? null) { | ||
(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.