From e8f3d23deda2cf4f892c800efb5051877c787b34 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com> Date: Wed, 10 Feb 2021 08:59:08 -0500 Subject: [PATCH] Configurable Tmp Dir Location (#2) --- .../src/integration/Setup/SetupScript.php | 21 ++++++--- .../testing/src/integration/TestCase.php | 13 +++--- .../testing/src/integration/UsesTmpDir.php | 44 +++++++++++++++++++ .../integration/tmp/public/assets/.gitkeep | 0 .../tmp/storage/formatter/.gitkeep | 0 .../integration/tmp/storage/sessions/.gitkeep | 0 .../integration/tmp/storage/views/.gitkeep | 0 .../tmp/vendor/composer/installed.json | 1 - 8 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 php-packages/testing/src/integration/UsesTmpDir.php delete mode 100644 php-packages/testing/src/integration/tmp/public/assets/.gitkeep delete mode 100644 php-packages/testing/src/integration/tmp/storage/formatter/.gitkeep delete mode 100644 php-packages/testing/src/integration/tmp/storage/sessions/.gitkeep delete mode 100644 php-packages/testing/src/integration/tmp/storage/views/.gitkeep delete mode 100644 php-packages/testing/src/integration/tmp/vendor/composer/installed.json diff --git a/php-packages/testing/src/integration/Setup/SetupScript.php b/php-packages/testing/src/integration/Setup/SetupScript.php index 1c23e8689..15c7cf490 100644 --- a/php-packages/testing/src/integration/Setup/SetupScript.php +++ b/php-packages/testing/src/integration/Setup/SetupScript.php @@ -14,9 +14,12 @@ use Flarum\Install\AdminUser; use Flarum\Install\BaseUrl; use Flarum\Install\DatabaseConfig; use Flarum\Install\Installation; +use Flarum\Testing\integration\UsesTmpDir; class SetupScript { + use UsesTmpDir; + /** * Test database host. * @@ -71,23 +74,31 @@ class SetupScript public function run() { + $tmp = $this->tmpDir(); + echo "Connecting to database $this->name at $this->host:$this->port.\n"; echo "Logging in as $this->user with password '$this->pass'.\n"; echo "Table prefix: '$this->pref'\n"; + echo "\nStoring test config in '$tmp'\n"; echo "\n\nCancel now if that's not what you want...\n"; echo "Use the following environment variables for configuration:\n"; - echo "DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD, DB_PREFIX\n"; + echo "Database: DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD, DB_PREFIX\n"; + echo "Test Config: FLARUM_TEST_TMP_DIR or FLARUM_TEST_TMP_DIR_LOCAL\n"; + sleep(4); echo "\nOff we go...\n"; + + $this->setupTmpDir(); + $installation = new Installation( new Paths([ - 'base' => __DIR__.'/../tmp', - 'public' => __DIR__.'/../tmp/public', - 'storage' => __DIR__.'/../tmp/storage', - 'vendor' => __DIR__.'/../../../../../', + 'base' => $tmp, + 'public' => "$tmp/public", + 'storage' => "$tmp/storage", + 'vendor' => getcwd().'/vendor', ]) ); diff --git a/php-packages/testing/src/integration/TestCase.php b/php-packages/testing/src/integration/TestCase.php index 7b385b173..bba228879 100644 --- a/php-packages/testing/src/integration/TestCase.php +++ b/php-packages/testing/src/integration/TestCase.php @@ -23,6 +23,7 @@ use Psr\Http\Server\RequestHandlerInterface; abstract class TestCase extends \PHPUnit\Framework\TestCase { use BuildsHttpRequests; + use UsesTmpDir; /** * @inheritDoc @@ -45,14 +46,16 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase protected function app() { if (is_null($this->app)) { + $tmp = $this->tmpDir(); + $site = new InstalledSite( new Paths([ - 'base' => __DIR__.'/tmp', - 'vendor' => __DIR__.'/../../../../', - 'public' => __DIR__.'/tmp/public', - 'storage' => __DIR__.'/tmp/storage', + 'base' => $tmp, + 'public' => "$tmp/public", + 'storage' => "$tmp/storage", + 'vendor' => getcwd().'/vendor', ]), - new Config(include __DIR__ . '/tmp/config.php') + new Config(include "$tmp/config.php") ); $extenders = array_merge([ diff --git a/php-packages/testing/src/integration/UsesTmpDir.php b/php-packages/testing/src/integration/UsesTmpDir.php new file mode 100644 index 000000000..23f2eb279 --- /dev/null +++ b/php-packages/testing/src/integration/UsesTmpDir.php @@ -0,0 +1,44 @@ + '{}' + ]; + + $tmpDir = $this->tmpDir(); + + foreach ($DIRS_NEEDED as $path) { + $fullPath = $tmpDir.$path; + if (!file_exists($fullPath)) { + mkdir($fullPath); + } + } + + foreach ($FILES_NEEDED as $path => $contents) { + $fullPath = $tmpDir.$path; + if (!file_exists($fullPath)) { + file_put_contents($fullPath, $contents); + } + } + } +} diff --git a/php-packages/testing/src/integration/tmp/public/assets/.gitkeep b/php-packages/testing/src/integration/tmp/public/assets/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/php-packages/testing/src/integration/tmp/storage/formatter/.gitkeep b/php-packages/testing/src/integration/tmp/storage/formatter/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/php-packages/testing/src/integration/tmp/storage/sessions/.gitkeep b/php-packages/testing/src/integration/tmp/storage/sessions/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/php-packages/testing/src/integration/tmp/storage/views/.gitkeep b/php-packages/testing/src/integration/tmp/storage/views/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/php-packages/testing/src/integration/tmp/vendor/composer/installed.json b/php-packages/testing/src/integration/tmp/vendor/composer/installed.json deleted file mode 100644 index 0967ef424..000000000 --- a/php-packages/testing/src/integration/tmp/vendor/composer/installed.json +++ /dev/null @@ -1 +0,0 @@ -{}