mirror of
https://github.com/flarum/core.git
synced 2025-08-06 08:27:42 +02:00
chore(phpstan): upgrade to be compatible with latest dependency updates (#3835)
This commit is contained in:
80
php-packages/testing/src/integration/Setup/Bootstrapper.php
Normal file
80
php-packages/testing/src/integration/Setup/Bootstrapper.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Testing\integration\Setup;
|
||||
|
||||
use Flarum\Foundation\Config;
|
||||
use Flarum\Foundation\InstalledSite;
|
||||
use Flarum\Foundation\Paths;
|
||||
use Flarum\Testing\integration\Extend\BeginTransactionAndSetDatabase;
|
||||
use Flarum\Testing\integration\Extend\OverrideExtensionManagerForTests;
|
||||
use Flarum\Testing\integration\Extend\SetSettingsBeforeBoot;
|
||||
use Flarum\Testing\integration\UsesTmpDir;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class Bootstrapper
|
||||
{
|
||||
use UsesTmpDir;
|
||||
|
||||
public ?ConnectionInterface $database = null;
|
||||
|
||||
public function __construct(
|
||||
protected array $config = [],
|
||||
protected array $extensions = [],
|
||||
protected array $settings = [],
|
||||
protected array $extenders = []
|
||||
) {
|
||||
}
|
||||
|
||||
public function setupOnce(): void
|
||||
{
|
||||
$tmp = $this->tmpDir();
|
||||
|
||||
if (! file_exists("$tmp/config.php")) {
|
||||
$setup = new SetupScript();
|
||||
$setup->run();
|
||||
}
|
||||
}
|
||||
|
||||
public function run(): InstalledSite
|
||||
{
|
||||
$this->setupOnce();
|
||||
|
||||
$tmp = $this->tmpDir();
|
||||
|
||||
$config = include "$tmp/config.php";
|
||||
|
||||
foreach ($this->config as $key => $value) {
|
||||
Arr::set($config, $key, $value);
|
||||
}
|
||||
|
||||
$site = new InstalledSite(
|
||||
new Paths([
|
||||
'base' => $tmp,
|
||||
'public' => "$tmp/public",
|
||||
'storage' => "$tmp/storage",
|
||||
'vendor' => getenv('FLARUM_TEST_VENDOR_PATH') ?: getcwd().'/vendor',
|
||||
]),
|
||||
new Config($config)
|
||||
);
|
||||
|
||||
$extenders = array_merge([
|
||||
new OverrideExtensionManagerForTests($this->extensions),
|
||||
new BeginTransactionAndSetDatabase(function (ConnectionInterface $db) {
|
||||
$this->database = $db;
|
||||
}),
|
||||
new SetSettingsBeforeBoot($this->settings),
|
||||
], $this->extenders);
|
||||
|
||||
$site->extendWith($extenders);
|
||||
|
||||
return $site;
|
||||
}
|
||||
}
|
@@ -10,12 +10,7 @@
|
||||
namespace Flarum\Testing\integration;
|
||||
|
||||
use Flarum\Extend\ExtenderInterface;
|
||||
use Flarum\Foundation\Config;
|
||||
use Flarum\Foundation\InstalledSite;
|
||||
use Flarum\Foundation\Paths;
|
||||
use Flarum\Testing\integration\Extend\BeginTransactionAndSetDatabase;
|
||||
use Flarum\Testing\integration\Extend\OverrideExtensionManagerForTests;
|
||||
use Flarum\Testing\integration\Extend\SetSettingsBeforeBoot;
|
||||
use Flarum\Testing\integration\Setup\Bootstrapper;
|
||||
use Illuminate\Contracts\Cache\Store;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Support\Arr;
|
||||
@@ -51,35 +46,16 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
|
||||
protected function app()
|
||||
{
|
||||
if (is_null($this->app)) {
|
||||
$tmp = $this->tmpDir();
|
||||
|
||||
$config = include "$tmp/config.php";
|
||||
|
||||
foreach ($this->config as $key => $value) {
|
||||
Arr::set($config, $key, $value);
|
||||
}
|
||||
|
||||
$site = new InstalledSite(
|
||||
new Paths([
|
||||
'base' => $tmp,
|
||||
'public' => "$tmp/public",
|
||||
'storage' => "$tmp/storage",
|
||||
'vendor' => getenv('FLARUM_TEST_VENDOR_PATH') ?: getcwd().'/vendor',
|
||||
]),
|
||||
new Config($config)
|
||||
$bootstrapper = new Bootstrapper(
|
||||
$this->config,
|
||||
$this->extensions,
|
||||
$this->settings,
|
||||
$this->extenders
|
||||
);
|
||||
|
||||
$extenders = array_merge([
|
||||
new OverrideExtensionManagerForTests($this->extensions),
|
||||
new BeginTransactionAndSetDatabase(function (ConnectionInterface $db) {
|
||||
$this->database = $db;
|
||||
}),
|
||||
new SetSettingsBeforeBoot($this->settings),
|
||||
], $this->extenders);
|
||||
$this->app = $bootstrapper->run()->bootApp();
|
||||
|
||||
$site->extendWith($extenders);
|
||||
|
||||
$this->app = $site->bootApp();
|
||||
$this->database = $bootstrapper->database;
|
||||
|
||||
$this->populateDatabase();
|
||||
}
|
||||
|
Reference in New Issue
Block a user