1
0
mirror of https://github.com/flarum/core.git synced 2025-07-25 18:51:40 +02:00

If current package is an extension, add it to the extension manager (#1)

Core's ExtensionManager only looks for extensions in the vendor directory, which makes sense for a Flarum instance, but is problematic if used in the context of a test suite for an extension. This PR:

- Adds a class extending ExtensionManager to include the current package
- Adds an extender that replaces ExtensionManager with this new class in container bindings

Effectively, this package can now be used to test extensions.
This commit is contained in:
Alexander Skvortsov
2021-01-24 12:13:27 -05:00
committed by GitHub
parent 167ffced5d
commit 6eafce0660
3 changed files with 94 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ use Flarum\Extend\ExtenderInterface;
use Flarum\Foundation\Config;
use Flarum\Foundation\InstalledSite;
use Flarum\Foundation\Paths;
use Flarum\Testing\integration\Extend\OverrideExtensionManagerForTests;
use Illuminate\Database\ConnectionInterface;
use Laminas\Diactoros\ServerRequest;
use Psr\Http\Message\ResponseInterface;
@@ -51,10 +52,14 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
'public' => __DIR__.'/tmp/public',
'storage' => __DIR__.'/tmp/storage',
]),
new Config(include __DIR__.'/tmp/config.php')
new Config(include __DIR__ . '/tmp/config.php')
);
$site->extendWith($this->extenders);
$extenders = array_merge([
new OverrideExtensionManagerForTests($this->extensions)
], $this->extenders);
$site->extendWith($extenders);
$this->app = $site->bootApp();
@@ -76,6 +81,16 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
$this->extenders = array_merge($this->extenders, $extenders);
}
/**
* @var string[]
*/
protected $extensions = [];
protected function extension(string ...$extensions)
{
$this->extensions = array_merge($this->extensions, $extensions);
}
/**
* @var RequestHandlerInterface
*/