mirror of
https://github.com/flarum/framework.git
synced 2025-02-17 02:02:47 +08:00
Configurable Tmp Dir Location (#2)
This commit is contained in:
parent
6eafce0660
commit
e8f3d23ded
|
@ -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',
|
||||
])
|
||||
);
|
||||
|
||||
|
|
|
@ -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([
|
||||
|
|
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 @@
|
|||
{}
|
Loading…
Reference in New Issue
Block a user