From 92d3d77e76aa21dafca14ee515f664fb81290866 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Wed, 31 Oct 2018 11:03:15 +0100 Subject: [PATCH] Bufixing environment specific assertion problem --- tests/Util/VFSTrait.php | 3 +- tests/datasets/ini/assert_db.ini.php | 56 ------------------- .../AutomaticInstallationConsoleTest.php | 47 ++++++++++++---- 3 files changed, 39 insertions(+), 67 deletions(-) delete mode 100644 tests/datasets/ini/assert_db.ini.php diff --git a/tests/Util/VFSTrait.php b/tests/Util/VFSTrait.php index 34763b1385..972119134a 100644 --- a/tests/Util/VFSTrait.php +++ b/tests/Util/VFSTrait.php @@ -20,7 +20,8 @@ trait VFSTrait // the used directories inside the App class $structure = [ 'config' => [], - 'bin' => [] + 'bin' => [], + 'test' => [] ]; // create a virtual directory and copy all needed files and folders to it diff --git a/tests/datasets/ini/assert_db.ini.php b/tests/datasets/ini/assert_db.ini.php deleted file mode 100644 index f42c9ddba2..0000000000 --- a/tests/datasets/ini/assert_db.ini.php +++ /dev/null @@ -1,56 +0,0 @@ -mockConfigGet('config', 'php_path', false); - $this->assertFile = dirname(__DIR__) . DIRECTORY_SEPARATOR . + $assertFile = dirname(__DIR__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'datasets' . DIRECTORY_SEPARATOR . 'ini' . DIRECTORY_SEPARATOR . 'assert.ini.php'; - $this->assertFileDb = dirname(__DIR__) . DIRECTORY_SEPARATOR . - '..' . DIRECTORY_SEPARATOR . - '..' . DIRECTORY_SEPARATOR . - 'datasets' . DIRECTORY_SEPARATOR . - 'ini' . DIRECTORY_SEPARATOR . - 'assert_db.ini.php'; + $this->assertFile = vfsStream::newFile('assert.ini.php') + ->at($this->root->getChild('test')) + ->setContent($this->replaceEnvironmentSettings($assertFile, false)); + $this->assertFileDb = vfsStream::newFile('assert_db.ini.php') + ->at($this->root->getChild('test')) + ->setContent($this->replaceEnvironmentSettings($assertFile, true)); + } + + /** + * Replacing environment specific variables in the assertion file + * + * @param string $file The file to compare in later tests + * @param bool $withDb If true, db settings are replaced too + * @return string The file content + */ + private function replaceEnvironmentSettings($file, $withDb) + { + $fileContent = file_get_contents($file); + $fileContent = str_replace("/usr/bin/php", trim(shell_exec('which php')), $fileContent); + if ($withDb) { + $fileContent = str_replace("hostname = \"\"", "hostname = \"" . $this->db_host . (!empty($this->db_port) ? ":" . $this->db_port : "") . "\"", $fileContent); + $fileContent = str_replace("username = \"\"", "username = \"" . $this->db_user . "\"", $fileContent); + $fileContent = str_replace("password = \"\"", "password = \"" . $this->db_pass . "\"", $fileContent); + $fileContent = str_replace("database = \"\"", "database = \"" . $this->db_data . "\"", $fileContent); + } + return $fileContent; } private function assertFinished($txt, $withconfig = false, $copyfile = false) @@ -232,7 +259,7 @@ CONF; $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')); $this->assertFileEquals( - $this->assertFileDb, + $this->assertFileDb->url(), $this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')->url()); } @@ -260,7 +287,7 @@ CONF; $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')); $this->assertFileEquals( - $this->assertFile, + $this->assertFile->url(), $this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')->url()); } @@ -299,7 +326,7 @@ CONF; $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')); $this->assertFileEquals( - $this->assertFileDb, + $this->assertFileDb->url(), $this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')->url()); }