mirror of
https://github.com/flarum/core.git
synced 2025-06-12 17:42:07 +02:00
Configurable Tmp Dir Location (#2)
This commit is contained in:
committed by
GitHub
parent
6eafce0660
commit
e8f3d23ded
@ -14,9 +14,12 @@ use Flarum\Install\AdminUser;
|
|||||||
use Flarum\Install\BaseUrl;
|
use Flarum\Install\BaseUrl;
|
||||||
use Flarum\Install\DatabaseConfig;
|
use Flarum\Install\DatabaseConfig;
|
||||||
use Flarum\Install\Installation;
|
use Flarum\Install\Installation;
|
||||||
|
use Flarum\Testing\integration\UsesTmpDir;
|
||||||
|
|
||||||
class SetupScript
|
class SetupScript
|
||||||
{
|
{
|
||||||
|
use UsesTmpDir;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test database host.
|
* Test database host.
|
||||||
*
|
*
|
||||||
@ -71,23 +74,31 @@ class SetupScript
|
|||||||
|
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
|
$tmp = $this->tmpDir();
|
||||||
|
|
||||||
echo "Connecting to database $this->name at $this->host:$this->port.\n";
|
echo "Connecting to database $this->name at $this->host:$this->port.\n";
|
||||||
echo "Logging in as $this->user with password '$this->pass'.\n";
|
echo "Logging in as $this->user with password '$this->pass'.\n";
|
||||||
echo "Table prefix: '$this->pref'\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 "\n\nCancel now if that's not what you want...\n";
|
||||||
echo "Use the following environment variables for configuration:\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);
|
sleep(4);
|
||||||
|
|
||||||
echo "\nOff we go...\n";
|
echo "\nOff we go...\n";
|
||||||
|
|
||||||
|
$this->setupTmpDir();
|
||||||
|
|
||||||
$installation = new Installation(
|
$installation = new Installation(
|
||||||
new Paths([
|
new Paths([
|
||||||
'base' => __DIR__.'/../tmp',
|
'base' => $tmp,
|
||||||
'public' => __DIR__.'/../tmp/public',
|
'public' => "$tmp/public",
|
||||||
'storage' => __DIR__.'/../tmp/storage',
|
'storage' => "$tmp/storage",
|
||||||
'vendor' => __DIR__.'/../../../../../',
|
'vendor' => getcwd().'/vendor',
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ use Psr\Http\Server\RequestHandlerInterface;
|
|||||||
abstract class TestCase extends \PHPUnit\Framework\TestCase
|
abstract class TestCase extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
use BuildsHttpRequests;
|
use BuildsHttpRequests;
|
||||||
|
use UsesTmpDir;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
@ -45,14 +46,16 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
|
|||||||
protected function app()
|
protected function app()
|
||||||
{
|
{
|
||||||
if (is_null($this->app)) {
|
if (is_null($this->app)) {
|
||||||
|
$tmp = $this->tmpDir();
|
||||||
|
|
||||||
$site = new InstalledSite(
|
$site = new InstalledSite(
|
||||||
new Paths([
|
new Paths([
|
||||||
'base' => __DIR__.'/tmp',
|
'base' => $tmp,
|
||||||
'vendor' => __DIR__.'/../../../../',
|
'public' => "$tmp/public",
|
||||||
'public' => __DIR__.'/tmp/public',
|
'storage' => "$tmp/storage",
|
||||||
'storage' => __DIR__.'/tmp/storage',
|
'vendor' => getcwd().'/vendor',
|
||||||
]),
|
]),
|
||||||
new Config(include __DIR__ . '/tmp/config.php')
|
new Config(include "$tmp/config.php")
|
||||||
);
|
);
|
||||||
|
|
||||||
$extenders = array_merge([
|
$extenders = array_merge([
|
||||||
|
44
php-packages/testing/src/integration/UsesTmpDir.php
Normal file
44
php-packages/testing/src/integration/UsesTmpDir.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Flarum\Testing\integration;
|
||||||
|
|
||||||
|
trait UsesTmpDir
|
||||||
|
{
|
||||||
|
public function tmpDir() {
|
||||||
|
return getenv('FLARUM_TEST_TMP_DIR_LOCAL') ?: getenv('FLARUM_TEST_TMP_DIR') ?: __DIR__.'/tmp';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setupTmpDir() {
|
||||||
|
$DIRS_NEEDED = [
|
||||||
|
'/',
|
||||||
|
'/public',
|
||||||
|
'/public/assets',
|
||||||
|
'/storage',
|
||||||
|
'/storage/formatter',
|
||||||
|
'/storage/sessions',
|
||||||
|
'/storage/views',
|
||||||
|
'/vendor',
|
||||||
|
'/vendor/composer'
|
||||||
|
];
|
||||||
|
|
||||||
|
$FILES_NEEDED = [
|
||||||
|
'/vendor/composer/installed.json' => '{}'
|
||||||
|
];
|
||||||
|
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1 +0,0 @@
|
|||||||
{}
|
|
Reference in New Issue
Block a user