mirror of
https://github.com/flarum/core.git
synced 2025-08-06 08:27:42 +02:00
chore: improve test suite (#3814)
Allows running tests without constantly running `composer install` on each extension.
This commit is contained in:
42
php-packages/testing/bootstrap/monorepo.php
Normal file
42
php-packages/testing/bootstrap/monorepo.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
|
||||
| This is specific to a monorepo setup. If you're using a single
|
||||
| repository for your extension, checkout the extension skeleton
|
||||
| at https://github.com/flarum/cli/tree/main/boilerplate/skeleton/extension.
|
||||
|
|
||||
| ---------------------------------------------------------------
|
||||
|
|
||||
| We symlink local vendor bins to the framework vendor bin
|
||||
| to be able to run scripts from the extension directory.
|
||||
|
|
||||
| We also use a `FLARUM_TEST_VENDOR_PATH` environment variable
|
||||
| to tell each extension where to find the framework vendor,
|
||||
| instead of a SetupScript property, because it is also needed
|
||||
| when running the tests.
|
||||
|
|
||||
*/
|
||||
|
||||
$monorepoVendor = __DIR__.'/../../../vendor';
|
||||
|
||||
// The root directory of the extension where tests are run from.
|
||||
$localVendor = getcwd().'/vendor';
|
||||
|
||||
if (! file_exists("$localVendor/bin")) {
|
||||
mkdir("$localVendor");
|
||||
symlink("$monorepoVendor/bin", "$localVendor/bin");
|
||||
}
|
||||
|
||||
require $monorepoVendor.'/autoload.php';
|
||||
|
||||
putenv('FLARUM_TEST_VENDOR_PATH='.$monorepoVendor);
|
||||
|
||||
return new Flarum\Testing\integration\Setup\SetupScript();
|
@@ -54,21 +54,11 @@ class ExtensionManagerIncludeCurrent extends ExtensionManager
|
||||
$extensions = parent::getExtensions();
|
||||
|
||||
$package = json_decode($this->filesystem->get($this->paths->vendor.'/../composer.json'), true);
|
||||
$packagePath = $this->paths->vendor.'/../';
|
||||
|
||||
if (Arr::get($package, 'type') === 'flarum-extension') {
|
||||
$current = new Extension($this->paths->vendor.'/../', $package);
|
||||
$current->setInstalled(true);
|
||||
$current->setVersion(Arr::get($package, 'version', '0.0'));
|
||||
$current->calculateDependencies([]);
|
||||
$extensions = $this->includeCurrentExtension($extensions, $package, $packagePath);
|
||||
|
||||
$extensions->put($current->getId(), $current);
|
||||
|
||||
$this->extensions = $extensions->sortBy(function ($extension) {
|
||||
return $extension->composerJsonAttribute('extra.flarum-extension.title');
|
||||
});
|
||||
}
|
||||
|
||||
return $this->extensions;
|
||||
return $this->extensions = $this->includeMonorepoExtensions($extensions, $package, $packagePath);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,4 +101,36 @@ class ExtensionManagerIncludeCurrent extends ExtensionManager
|
||||
|
||||
return new FilesystemAdapter(new \League\Flysystem\Filesystem($adapter), $adapter);
|
||||
}
|
||||
|
||||
protected function includeCurrentExtension(Collection $extensions, $package, string $packagePath): Collection
|
||||
{
|
||||
if (Arr::get($package, 'type') === 'flarum-extension') {
|
||||
$current = new Extension($packagePath, $package);
|
||||
$current->setInstalled(true);
|
||||
$current->setVersion(Arr::get($package, 'version', '0.0'));
|
||||
$current->calculateDependencies([]);
|
||||
|
||||
$extensions->put($current->getId(), $current);
|
||||
|
||||
$extensions = $extensions->sortBy(function ($extension, $name) {
|
||||
return $extension->composerJsonAttribute('extra.flarum-extension.title');
|
||||
});
|
||||
}
|
||||
|
||||
return $extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows symlinking the vendor directory in extensions when running tests on monorepos.
|
||||
*/
|
||||
protected function includeMonorepoExtensions(Collection $extensions, $package, string $packagePath): Collection
|
||||
{
|
||||
foreach ($this->subExtensionConfsFromJson($package, $packagePath) ?? [] as $path => $package) {
|
||||
$extension = $this->extensionFromJson($package, $path);
|
||||
$extension->calculateDependencies([]);
|
||||
$extensions->put($extension->getId(), $extension);
|
||||
}
|
||||
|
||||
return $extensions;
|
||||
}
|
||||
}
|
||||
|
@@ -116,7 +116,7 @@ class SetupScript
|
||||
'base' => $tmp,
|
||||
'public' => "$tmp/public",
|
||||
'storage' => "$tmp/storage",
|
||||
'vendor' => getcwd().'/vendor',
|
||||
'vendor' => getenv('FLARUM_TEST_VENDOR_PATH') ?: getcwd().'/vendor',
|
||||
])
|
||||
);
|
||||
|
||||
|
@@ -64,7 +64,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
|
||||
'base' => $tmp,
|
||||
'public' => "$tmp/public",
|
||||
'storage' => "$tmp/storage",
|
||||
'vendor' => getcwd().'/vendor',
|
||||
'vendor' => getenv('FLARUM_TEST_VENDOR_PATH') ?: getcwd().'/vendor',
|
||||
]),
|
||||
new Config($config)
|
||||
);
|
||||
|
@@ -7,10 +7,6 @@
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flarum\Testing\integration\Setup\SetupScript;
|
||||
|
||||
require __DIR__.'/../../vendor/autoload.php';
|
||||
|
||||
$setup = new SetupScript();
|
||||
$setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
|
||||
|
||||
$setup->run();
|
||||
|
@@ -10,6 +10,7 @@
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="true"
|
||||
stopOnFailure="false"
|
||||
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
|
||||
>
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
|
@@ -10,6 +10,7 @@
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
|
||||
>
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
|
Reference in New Issue
Block a user