@@ -14,16 +14,16 @@ final class RedmineInstance
1414 /**
1515 * @param InstanceRegistration $tracer Required to ensure that RedmineInstance is created while Test Runner is running
1616 */
17- public static function create (InstanceRegistration $ tracer , RedmineVersion $ version ): void
17+ public static function create (InstanceRegistration $ tracer , RedmineVersion $ version, string $ rootPath ): void
1818 {
19- $ tracer ->registerInstance (new self ($ tracer , $ version ));
19+ $ tracer ->registerInstance (new self ($ tracer , $ version, $ rootPath ));
2020 }
2121
2222 private InstanceRegistration $ tracer ;
2323
2424 private RedmineVersion $ version ;
2525
26- private string $ rootPath ;
26+ private string $ dataPath ;
2727
2828 private string $ workingDB ;
2929
@@ -41,14 +41,19 @@ public static function create(InstanceRegistration $tracer, RedmineVersion $vers
4141
4242 private string $ apiKey ;
4343
44- private function __construct (InstanceRegistration $ tracer , RedmineVersion $ version )
44+ private function __construct (InstanceRegistration $ tracer , RedmineVersion $ version, string $ rootPath )
4545 {
4646 $ this ->tracer = $ tracer ;
4747 $ this ->version = $ version ;
4848
4949 $ versionId = strval ($ version ->asId ());
5050
51- $ this ->rootPath = dirname (__FILE__ , 3 ) . '/.docker/redmine- ' . $ versionId . '_data/ ' ;
51+ // Default to .docker folder
52+ if ($ rootPath === '' ) {
53+ $ rootPath = dirname (__FILE__ , 3 ) . '/.docker ' ;
54+ }
55+
56+ $ this ->dataPath = $ rootPath . '/redmine- ' . $ versionId . '_data/ ' ;
5257
5358 $ this ->workingDB = 'sqlite/redmine.db ' ;
5459 $ this ->migratedDB = 'sqlite/redmine-migrated.db ' ;
@@ -108,10 +113,10 @@ private function runHealthChecks(RedmineVersion $version): void
108113 ));
109114 }
110115
111- if (! file_exists ($ this ->rootPath . $ this ->workingDB )) {
116+ if (! file_exists ($ this ->dataPath . $ this ->workingDB )) {
112117 throw new InvalidArgumentException (sprintf (
113118 'Could not find database file in %s, please make sure that Redmine %s has a docker service in /docker-composer.yml and is correctly configured in /tests/Behat/behat.yml. ' ,
114- $ this ->rootPath . $ this ->workingDB ,
119+ $ this ->dataPath . $ this ->workingDB ,
115120 $ version ->asString (),
116121 ));
117122 }
@@ -146,7 +151,7 @@ public function shutdown(InstanceRegistration $tracer): void
146151 */
147152 public function excecuteDatabaseQuery (string $ query , array $ options = [], array $ params = null ): void
148153 {
149- $ pdo = new PDO ('sqlite: ' . $ this ->rootPath . $ this ->workingDB );
154+ $ pdo = new PDO ('sqlite: ' . $ this ->dataPath . $ this ->workingDB );
150155 $ pdo ->setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
151156
152157 $ stmt = $ pdo ->prepare ($ query , $ options );
@@ -156,7 +161,7 @@ public function excecuteDatabaseQuery(string $query, array $options = [], array
156161 private function runDatabaseMigration ()
157162 {
158163 $ now = new DateTimeImmutable ();
159- $ pdo = new PDO ('sqlite: ' . $ this ->rootPath . $ this ->workingDB );
164+ $ pdo = new PDO ('sqlite: ' . $ this ->dataPath . $ this ->workingDB );
160165
161166 // Get admin user to check sqlite connection
162167 $ stmt = $ pdo ->prepare ('SELECT * FROM users WHERE login = :login; ' );
@@ -191,9 +196,9 @@ private function runDatabaseMigration()
191196 */
192197 private function createDatabaseBackup ()
193198 {
194- $ workingDB = new SQLite3 ($ this ->rootPath . $ this ->workingDB );
199+ $ workingDB = new SQLite3 ($ this ->dataPath . $ this ->workingDB );
195200
196- $ backupDB = new SQLite3 ($ this ->rootPath . $ this ->backupDB );
201+ $ backupDB = new SQLite3 ($ this ->dataPath . $ this ->backupDB );
197202
198203 $ workingDB ->backup ($ backupDB );
199204
@@ -206,9 +211,9 @@ private function createDatabaseBackup()
206211 */
207212 private function saveMigratedDatabase ()
208213 {
209- $ workingDB = new SQLite3 ($ this ->rootPath . $ this ->workingDB );
214+ $ workingDB = new SQLite3 ($ this ->dataPath . $ this ->workingDB );
210215
211- $ migratedDB = new SQLite3 ($ this ->rootPath . $ this ->migratedDB );
216+ $ migratedDB = new SQLite3 ($ this ->dataPath . $ this ->migratedDB );
212217
213218 $ workingDB ->backup ($ migratedDB );
214219
@@ -218,9 +223,9 @@ private function saveMigratedDatabase()
218223
219224 private function restoreFromMigratedDatabase (): void
220225 {
221- $ workingDB = new SQLite3 ($ this ->rootPath . $ this ->workingDB );
226+ $ workingDB = new SQLite3 ($ this ->dataPath . $ this ->workingDB );
222227
223- $ migratedDB = new SQLite3 ($ this ->rootPath . $ this ->migratedDB );
228+ $ migratedDB = new SQLite3 ($ this ->dataPath . $ this ->migratedDB );
224229
225230 $ migratedDB ->backup ($ workingDB );
226231
@@ -230,9 +235,9 @@ private function restoreFromMigratedDatabase(): void
230235
231236 private function restoreDatabaseFromBackup (): void
232237 {
233- $ workingDB = new SQLite3 ($ this ->rootPath . $ this ->workingDB );
238+ $ workingDB = new SQLite3 ($ this ->dataPath . $ this ->workingDB );
234239
235- $ backupDB = new SQLite3 ($ this ->rootPath . $ this ->backupDB );
240+ $ backupDB = new SQLite3 ($ this ->dataPath . $ this ->backupDB );
236241
237242 $ backupDB ->backup ($ workingDB );
238243
@@ -242,66 +247,66 @@ private function restoreDatabaseFromBackup(): void
242247
243248 private function removeDatabaseBackups (): void
244249 {
245- unlink ($ this ->rootPath . $ this ->migratedDB );
246- unlink ($ this ->rootPath . $ this ->backupDB );
250+ unlink ($ this ->dataPath . $ this ->migratedDB );
251+ unlink ($ this ->dataPath . $ this ->backupDB );
247252 }
248253
249254 private function createFilesBackup ()
250255 {
251256 // Add an empty file to avoid warnings about copying and removing content from an empty folder
252- touch ($ this ->rootPath . $ this ->workingFiles . 'empty ' );
257+ touch ($ this ->dataPath . $ this ->workingFiles . 'empty ' );
253258 exec (sprintf (
254259 'cp -r %s %s ' ,
255- $ this ->rootPath . $ this ->workingFiles ,
256- $ this ->rootPath . rtrim ($ this ->backupFiles , '/ ' ),
260+ $ this ->dataPath . $ this ->workingFiles ,
261+ $ this ->dataPath . rtrim ($ this ->backupFiles , '/ ' ),
257262 ));
258263 }
259264
260265 private function saveMigratedFiles ()
261266 {
262267 exec (sprintf (
263268 'cp -r %s %s ' ,
264- $ this ->rootPath . $ this ->workingFiles ,
265- $ this ->rootPath . rtrim ($ this ->migratedFiles , '/ ' ),
269+ $ this ->dataPath . $ this ->workingFiles ,
270+ $ this ->dataPath . rtrim ($ this ->migratedFiles , '/ ' ),
266271 ));
267272 }
268273
269274 private function restoreFromMigratedFiles (): void
270275 {
271276 exec (sprintf (
272277 'rm -r %s ' ,
273- $ this ->rootPath . $ this ->workingFiles . '* ' ,
278+ $ this ->dataPath . $ this ->workingFiles . '* ' ,
274279 ));
275280
276281 exec (sprintf (
277282 'cp -r %s %s ' ,
278- $ this ->rootPath . $ this ->migratedFiles . '* ' ,
279- $ this ->rootPath . rtrim ($ this ->workingFiles , '/ ' ),
283+ $ this ->dataPath . $ this ->migratedFiles . '* ' ,
284+ $ this ->dataPath . rtrim ($ this ->workingFiles , '/ ' ),
280285 ));
281286 }
282287
283288 private function restoreFilesFromBackup (): void
284289 {
285290 exec (sprintf (
286291 'rm -r %s ' ,
287- $ this ->rootPath . $ this ->workingFiles . '* ' ,
292+ $ this ->dataPath . $ this ->workingFiles . '* ' ,
288293 ));
289294
290295 exec (sprintf (
291296 'cp -r %s %s ' ,
292- $ this ->rootPath . $ this ->backupFiles . '* ' ,
293- $ this ->rootPath . rtrim ($ this ->workingFiles , '/ ' ),
297+ $ this ->dataPath . $ this ->backupFiles . '* ' ,
298+ $ this ->dataPath . rtrim ($ this ->workingFiles , '/ ' ),
294299 ));
295300 }
296301
297302 private function removeFilesBackups (): void
298303 {
299304 exec (sprintf (
300305 'rm -r %s %s ' ,
301- $ this ->rootPath . $ this ->migratedFiles ,
302- $ this ->rootPath . $ this ->backupFiles ,
306+ $ this ->dataPath . $ this ->migratedFiles ,
307+ $ this ->dataPath . $ this ->backupFiles ,
303308 ));
304309
305- unlink ($ this ->rootPath . $ this ->workingFiles . 'empty ' );
310+ unlink ($ this ->dataPath . $ this ->workingFiles . 'empty ' );
306311 }
307312}
0 commit comments