@@ -28,7 +28,7 @@ public function registerBundles(): iterable
2828 {
2929 yield from parent ::registerBundles ();
3030
31- if (FoundryTestKernel ::usesMigrations ()) {
31+ if (self ::usesMigrations ()) {
3232 yield new DoctrineMigrationsBundle ();
3333 }
3434 }
@@ -43,18 +43,18 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
4343 GlobalInvokableService::class,
4444 ],
4545 'orm ' => [
46- 'reset ' => FoundryTestKernel ::usesMigrations ()
46+ 'reset ' => self ::usesMigrations ()
4747 ? [
4848 'mode ' => ResetDatabaseMode::MIGRATE ,
4949 'migrations ' => [
50- 'configurations ' => ($ configFile = \getenv ( ' MIGRATION_CONFIGURATION_FILE ' )) ? [ $ configFile] : [],
50+ 'configurations ' => ($ configFile = self :: migrationFiles ( )) ? $ configFile : [],
5151 ],
5252 ]
5353 : ['mode ' => ResetDatabaseMode::SCHEMA ],
5454 ],
5555 ]);
5656
57- if (FoundryTestKernel ::usesMigrations () && ! \getenv ( ' MIGRATION_CONFIGURATION_FILE ' ) ) {
57+ if (self ::usesMigrations () && self :: migrationFiles () === [] ) {
5858 // if no configuration file was given in Foundry's config, let's use the main one as default.
5959 $ c ->loadFromExtension (
6060 'doctrine_migrations ' ,
@@ -72,4 +72,29 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
7272 $ c ->register (MongoResetterDecorator::class)->setAutowired (true )->setAutoconfigured (true );
7373 }
7474 }
75+
76+ public static function usesMigrations (): bool
77+ {
78+ return 'migrate ' === \getenv ('DATABASE_RESET_MODE ' );
79+ }
80+
81+ /**
82+ * @return list<string>
83+ */
84+ public static function migrationFiles (): array
85+ {
86+ $ files = json_decode (\getenv ('MIGRATION_CONFIGURATION_FILE ' )?: '[] ' , flags: JSON_THROW_ON_ERROR );
87+
88+ if (!\is_array ($ files )) {
89+ throw new \InvalidArgumentException ('MIGRATION_CONFIGURATION_FILE must be a JSON array. ' );
90+ }
91+
92+ foreach ($ files as $ file ) {
93+ if (!\file_exists ($ file )) {
94+ throw new \InvalidArgumentException (\sprintf ('Migration configuration file "%s" does not exist. ' , $ file ));
95+ }
96+ }
97+
98+ return $ files ; // @phpstan-ignore return.type
99+ }
75100}
0 commit comments