From bde0eded7854b2a2050774372b01778c9e43b239 Mon Sep 17 00:00:00 2001 From: Calvin Alkan Date: Tue, 16 Aug 2022 18:07:32 +0200 Subject: [PATCH] feat: allow absolute path in dump files This is highly useful in multi-application setups where dump files may not be inside the project directory but in a shared fixture directory. The current alternative is to symlink each file into the project dir. --- src/Codeception/Module/Db.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Codeception/Module/Db.php b/src/Codeception/Module/Db.php index 6c116b60..df41c702 100644 --- a/src/Codeception/Module/Db.php +++ b/src/Codeception/Module/Db.php @@ -532,18 +532,24 @@ private function readSql($databaseKey = null, $databaseConfig = null): void * @return bool|null|string|string[] * @throws ModuleConfigException */ - private function readSqlFile(string $filePath): ?string + private function readSqlFile(string $configPath): ?string { - if (!file_exists(Configuration::projectDir() . $filePath)) { + if(file_exists($configPath)) { + $dumpFile = $configPath; + }elseif (file_exists(Configuration::projectDir().$configPath)){ + $dumpFile = Configuration::projectDir().$configPath; + }else { throw new ModuleConfigException( __CLASS__, - "\nFile with dump doesn't exist.\n" - . "Please, check path for sql file: " - . $filePath + sprintf( + "Could not find dump file from config value.\nTried:\n%s\nand\n%s", + $configPath, + Configuration::projectDir().$configPath + ) ); } - - $sql = file_get_contents(Configuration::projectDir() . $filePath); + + $sql = file_get_contents($dumpFile); // remove C-style comments (except MySQL directives) return preg_replace('#/\*(?!!\d+).*?\*/#s', '', $sql);