@@ -28,7 +28,7 @@ public function registerBundles(): iterable
28
28
{
29
29
yield from parent ::registerBundles ();
30
30
31
- if (FoundryTestKernel ::usesMigrations ()) {
31
+ if (self ::usesMigrations ()) {
32
32
yield new DoctrineMigrationsBundle ();
33
33
}
34
34
}
@@ -43,18 +43,18 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
43
43
GlobalInvokableService::class,
44
44
],
45
45
'orm ' => [
46
- 'reset ' => FoundryTestKernel ::usesMigrations ()
46
+ 'reset ' => self ::usesMigrations ()
47
47
? [
48
48
'mode ' => ResetDatabaseMode::MIGRATE ,
49
49
'migrations ' => [
50
- 'configurations ' => ($ configFile = \getenv ( ' MIGRATION_CONFIGURATION_FILE ' )) ? [ $ configFile] : [],
50
+ 'configurations ' => ($ configFile = self :: migrationFiles ( )) ? $ configFile : [],
51
51
],
52
52
]
53
53
: ['mode ' => ResetDatabaseMode::SCHEMA ],
54
54
],
55
55
]);
56
56
57
- if (FoundryTestKernel ::usesMigrations () && ! \getenv ( ' MIGRATION_CONFIGURATION_FILE ' ) ) {
57
+ if (self ::usesMigrations () && self :: migrationFiles () === [] ) {
58
58
// if no configuration file was given in Foundry's config, let's use the main one as default.
59
59
$ c ->loadFromExtension (
60
60
'doctrine_migrations ' ,
@@ -72,4 +72,29 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
72
72
$ c ->register (MongoResetterDecorator::class)->setAutowired (true )->setAutoconfigured (true );
73
73
}
74
74
}
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
+ }
75
100
}
0 commit comments