chore: improve test suite (#3814)

Allows running tests without constantly running `composer install` on each extension.
This commit is contained in:
Sami Mazouz 2023-06-15 13:26:39 +01:00 committed by GitHub
parent 6bc19e2e52
commit 64b25b26c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
70 changed files with 213 additions and 309 deletions

View File

@ -21,6 +21,12 @@ on:
required: false required: false
default: '.' default: '.'
# Only relevant in mono-repos.
monorepo_tests:
description: "The list of directories to test in a monorepo. This should be a space-separated list of directories relative to the backend directory."
type: string
required: false
php_versions: php_versions:
description: Versions of PHP to test with. Should be array of strings encoded as JSON array description: Versions of PHP to test with. Should be array of strings encoded as JSON array
type: string type: string
@ -47,6 +53,7 @@ on:
env: env:
COMPOSER_ROOT_VERSION: dev-main COMPOSER_ROOT_VERSION: dev-main
# `inputs.composer_directory` defaults to `inputs.backend_directory`
FLARUM_TEST_TMP_DIR_LOCAL: tests/integration/tmp FLARUM_TEST_TMP_DIR_LOCAL: tests/integration/tmp
jobs: jobs:
@ -143,18 +150,27 @@ jobs:
run: composer install run: composer install
working-directory: ${{ inputs.backend_directory }} working-directory: ${{ inputs.backend_directory }}
- name: Setup Composer tests # If we have a `inputs.monorepo_tests`, we will run tests for each item of the provided array in a ::group::item
run: composer test:setup # If we don't have a `inputs.monorepo_tests`, we will run tests for the current repository
# We also have to run the `composer test:setup` script first before running each test
- name: Run tests
run: |
if [ -z "${{ inputs.monorepo_tests }}" ]; then
composer test:setup
composer test
else
for test in ${{ inputs.monorepo_tests }}; do
echo "::group::Running tests for $test"
composer test:setup --working-dir=$test
composer test --working-dir=$test
echo "::endgroup::"
done
fi
working-directory: ${{ inputs.backend_directory }} working-directory: ${{ inputs.backend_directory }}
env: env:
DB_PORT: 13306 DB_PORT: 13306
DB_PASSWORD: root DB_PASSWORD: root
DB_PREFIX: ${{ matrix.prefix }} DB_PREFIX: ${{ matrix.prefix }}
- name: Run Composer tests
run: composer test
working-directory: ${{ inputs.backend_directory }}
env:
COMPOSER_PROCESS_TIMEOUT: 600 COMPOSER_PROCESS_TIMEOUT: 600
phpstan: phpstan:

11
.github/workflows/backend.yml vendored Normal file
View File

@ -0,0 +1,11 @@
name: Backend Tests
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: true
backend_directory: .
monorepo_tests: "framework/core extensions/akismet extensions/approval extensions/flags extensions/likes extensions/mentions extensions/nicknames extensions/statistics extensions/sticky extensions/subscriptions extensions/suspend extensions/tags"

View File

@ -1,11 +0,0 @@
name: Akismet PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: true
backend_directory: ./extensions/akismet

View File

@ -1,11 +0,0 @@
name: Approval PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: true
backend_directory: ./extensions/approval

View File

@ -1,11 +0,0 @@
name: Core PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: true
backend_directory: ./framework/core

View File

@ -1,11 +0,0 @@
name: Embed PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: false
backend_directory: ./extensions/embed

View File

@ -1,11 +0,0 @@
name: Emoji PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: false
backend_directory: ./extensions/emoji

View File

@ -1,11 +0,0 @@
name: Flags PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: true
backend_directory: ./extensions/flags

View File

@ -1,11 +0,0 @@
name: Likes PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: true
backend_directory: ./extensions/likes

View File

@ -1,11 +0,0 @@
name: Lock PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: false
backend_directory: ./extensions/lock

View File

@ -1,11 +0,0 @@
name: Markdown PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: false
backend_directory: ./extensions/markdown

View File

@ -1,11 +0,0 @@
name: Mentions PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: true
backend_directory: ./extensions/mentions

View File

@ -1,11 +0,0 @@
name: Nicknames PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: true
backend_directory: ./extensions/nicknames

View File

@ -1,11 +0,0 @@
name: Package Manager PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: false
backend_directory: ./extensions/package-manager

View File

@ -1,11 +0,0 @@
name: Pusher PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: false
backend_directory: ./extensions/pusher

View File

@ -1,11 +0,0 @@
name: Statistics PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: true
backend_directory: ./extensions/statistics

View File

@ -1,11 +0,0 @@
name: Sticky PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: true
backend_directory: ./extensions/sticky

View File

@ -1,11 +0,0 @@
name: Subscriptions PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: true
backend_directory: ./extensions/subscriptions

View File

@ -1,11 +0,0 @@
name: Suspend PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: true
backend_directory: ./extensions/suspend

View File

@ -1,11 +0,0 @@
name: Tags PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: ./.github/workflows/REUSABLE_backend.yml
with:
enable_backend_testing: true
backend_directory: ./extensions/tags

View File

@ -1,4 +1,4 @@
name: Framework JS name: Frontend Workflow
on: [workflow_dispatch, push, pull_request] on: [workflow_dispatch, push, pull_request]

View File

@ -1,4 +1,4 @@
name: Framework PHP name: Static Code Analysis
on: [workflow_dispatch, push, pull_request] on: [workflow_dispatch, push, pull_request]
@ -8,5 +8,4 @@ jobs:
with: with:
enable_backend_testing: false enable_backend_testing: false
enable_phpstan: true enable_phpstan: true
backend_directory: . backend_directory: .

View File

@ -60,6 +60,26 @@
"framework/core/src/helpers.php" "framework/core/src/helpers.php"
] ]
}, },
"autoload-dev": {
"psr-4": {
"Flarum\\Tests\\": "tests",
"Flarum\\Akismet\\Tests\\": "extensions/akismet/tests",
"Flarum\\Approval\\Tests\\": "extensions/approval/tests",
"Flarum\\Flags\\Tests\\": "extensions/flags/tests",
"Flarum\\Likes\\Tests\\": "extensions/likes/tests",
"Flarum\\Lock\\Tests\\": "extensions/lock/tests",
"Flarum\\Mentions\\Tests\\": "extensions/mentions/tests",
"Flarum\\Nicknames\\Tests\\": "extensions/nicknames/tests",
"Flarum\\PackageManager\\Tests\\": "extensions/package-manager/tests",
"Flarum\\Pusher\\Tests\\": "extensions/pusher/tests",
"Flarum\\Statistics\\Tests\\": "extensions/statistics/tests",
"Flarum\\Sticky\\Tests\\": "extensions/sticky/tests",
"Flarum\\Subscriptions\\Tests\\": "extensions/subscriptions/tests",
"Flarum\\Suspend\\Tests\\": "extensions/suspend/tests",
"Flarum\\Tags\\Tests\\": "extensions/tags/tests",
"Flarum\\Testing\\Tests\\": "php-packages/testing/tests"
}
},
"replace": { "replace": {
"flarum/core": "self.version", "flarum/core": "self.version",
"flarum/akismet": "self.version", "flarum/akismet": "self.version",

View File

@ -7,10 +7,6 @@
* LICENSE file that was distributed with this source code. * LICENSE file that was distributed with this source code.
*/ */
use Flarum\Testing\integration\Setup\SetupScript; $setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
require __DIR__.'/../../vendor/autoload.php';
$setup = new SetupScript();
$setup->run(); $setup->run();

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="true" processIsolation="true"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -7,10 +7,6 @@
* LICENSE file that was distributed with this source code. * LICENSE file that was distributed with this source code.
*/ */
use Flarum\Testing\integration\Setup\SetupScript; $setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
require __DIR__.'/../../vendor/autoload.php';
$setup = new SetupScript();
$setup->run(); $setup->run();

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="true" processIsolation="true"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -7,10 +7,6 @@
* LICENSE file that was distributed with this source code. * LICENSE file that was distributed with this source code.
*/ */
use Flarum\Testing\integration\Setup\SetupScript; $setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
require __DIR__.'/../../vendor/autoload.php';
$setup = new SetupScript();
$setup->run(); $setup->run();

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="true" processIsolation="true"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -7,10 +7,6 @@
* LICENSE file that was distributed with this source code. * LICENSE file that was distributed with this source code.
*/ */
use Flarum\Testing\integration\Setup\SetupScript; $setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
require __DIR__.'/../../vendor/autoload.php';
$setup = new SetupScript();
$setup->run(); $setup->run();

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="true" processIsolation="true"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -7,10 +7,6 @@
* LICENSE file that was distributed with this source code. * LICENSE file that was distributed with this source code.
*/ */
use Flarum\Testing\integration\Setup\SetupScript; $setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
require __DIR__.'/../../vendor/autoload.php';
$setup = new SetupScript();
$setup->run(); $setup->run();

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="true" processIsolation="true"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -7,10 +7,6 @@
* LICENSE file that was distributed with this source code. * LICENSE file that was distributed with this source code.
*/ */
use Flarum\Testing\integration\Setup\SetupScript; $setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
require __DIR__.'/../../vendor/autoload.php';
$setup = new SetupScript();
$setup->run(); $setup->run();

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="true" processIsolation="true"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -8,11 +8,8 @@
*/ */
use Flarum\PackageManager\Tests\integration\SetupComposer; use Flarum\PackageManager\Tests\integration\SetupComposer;
use Flarum\Testing\integration\Setup\SetupScript;
require __DIR__.'/../../vendor/autoload.php'; $setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
$setup = new SetupScript();
$setup->run(); $setup->run();

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="true" processIsolation="true"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -7,10 +7,6 @@
* LICENSE file that was distributed with this source code. * LICENSE file that was distributed with this source code.
*/ */
use Flarum\Testing\integration\Setup\SetupScript; $setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
require __DIR__.'/../../vendor/autoload.php';
$setup = new SetupScript();
$setup->run(); $setup->run();

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="true" processIsolation="true"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -7,10 +7,6 @@
* LICENSE file that was distributed with this source code. * LICENSE file that was distributed with this source code.
*/ */
use Flarum\Testing\integration\Setup\SetupScript; $setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
require __DIR__.'/../../vendor/autoload.php';
$setup = new SetupScript();
$setup->run(); $setup->run();

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="true" processIsolation="true"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -7,10 +7,6 @@
* LICENSE file that was distributed with this source code. * LICENSE file that was distributed with this source code.
*/ */
use Flarum\Testing\integration\Setup\SetupScript; $setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
require __DIR__.'/../../vendor/autoload.php';
$setup = new SetupScript();
$setup->run(); $setup->run();

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="true" processIsolation="true"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -7,10 +7,6 @@
* LICENSE file that was distributed with this source code. * LICENSE file that was distributed with this source code.
*/ */
use Flarum\Testing\integration\Setup\SetupScript; $setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
require __DIR__.'/../../vendor/autoload.php';
$setup = new SetupScript();
$setup->run(); $setup->run();

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="true" processIsolation="true"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -7,10 +7,6 @@
* LICENSE file that was distributed with this source code. * LICENSE file that was distributed with this source code.
*/ */
use Flarum\Testing\integration\Setup\SetupScript; $setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
require __DIR__.'/../../vendor/autoload.php';
$setup = new SetupScript();
$setup->run(); $setup->run();

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="true" processIsolation="true"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -73,31 +73,18 @@ class ExtensionManager
$composerJsonConfs[$packagePath] = $package; $composerJsonConfs[$packagePath] = $package;
} }
if ($subextPaths = Arr::get($package, 'extra.flarum-subextensions', [])) { if ($subExtConfs = $this->subExtensionConfsFromJson($package, $packagePath)) {
foreach ($subextPaths as $subExtPath) { $composerJsonConfs = array_merge($composerJsonConfs, $subExtConfs);
$subPackagePath = "$packagePath/$subExtPath";
$conf = json_decode($this->filesystem->get("$subPackagePath/composer.json"), true);
if (Arr::get($conf, 'type') === 'flarum-extension') {
$composerJsonConfs[$subPackagePath] = $conf;
}
}
} }
} }
foreach ($composerJsonConfs as $path => $package) { foreach ($composerJsonConfs as $path => $package) {
$installedSet[Arr::get($package, 'name')] = true; $installedSet[Arr::get($package, 'name')] = true;
$extension = $this->extensionFromJson($package, $path);
// Instantiates an Extension object using the package path and composer.json file.
$extension = new Extension($path, $package);
// Per default all extensions are installed if they are registered in composer.
$extension->setInstalled(true);
$extension->setVersion(Arr::get($package, 'version'));
$extensions->put($extension->getId(), $extension); $extensions->put($extension->getId(), $extension);
} }
/** @var Extension $extension */
foreach ($extensions as $extension) { foreach ($extensions as $extension) {
$extension->calculateDependencies($installedSet); $extension->calculateDependencies($installedSet);
} }
@ -472,4 +459,36 @@ class ExtensionManager
'circularDependencies' => $circularDependencies 'circularDependencies' => $circularDependencies
]; ];
} }
protected function extensionFromJson(array $package, string $path): Extension
{
// Instantiates an Extension object using the package path and composer.json file.
$extension = new Extension($path, $package);
// Per default all extensions are installed if they are registered in composer.
$extension->setInstalled(true);
$extension->setVersion(Arr::get($package, 'version', '0.0'));
return $extension;
}
protected function subExtensionConfsFromJson(array $package, string $packagePath): ?array
{
if (! ($subExtPaths = Arr::get($package, 'extra.flarum-subextensions', []))) {
return null;
}
$subExtConfs = [];
foreach ($subExtPaths as $subExtPath) {
$subPackagePath = "$packagePath/$subExtPath";
$conf = json_decode($this->filesystem->get("$subPackagePath/composer.json"), true);
if (Arr::get($conf, 'type') === 'flarum-extension') {
$subExtConfs[$subPackagePath] = $conf;
}
}
return $subExtConfs;
}
} }

View File

@ -7,10 +7,6 @@
* LICENSE file that was distributed with this source code. * LICENSE file that was distributed with this source code.
*/ */
use Flarum\Testing\integration\Setup\SetupScript; $setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
require __DIR__.'/../../vendor/autoload.php';
$setup = new SetupScript();
$setup->run(); $setup->run();

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="true" processIsolation="true"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View 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();

View File

@ -54,21 +54,11 @@ class ExtensionManagerIncludeCurrent extends ExtensionManager
$extensions = parent::getExtensions(); $extensions = parent::getExtensions();
$package = json_decode($this->filesystem->get($this->paths->vendor.'/../composer.json'), true); $package = json_decode($this->filesystem->get($this->paths->vendor.'/../composer.json'), true);
$packagePath = $this->paths->vendor.'/../';
if (Arr::get($package, 'type') === 'flarum-extension') { $extensions = $this->includeCurrentExtension($extensions, $package, $packagePath);
$current = new Extension($this->paths->vendor.'/../', $package);
$current->setInstalled(true);
$current->setVersion(Arr::get($package, 'version', '0.0'));
$current->calculateDependencies([]);
$extensions->put($current->getId(), $current); return $this->extensions = $this->includeMonorepoExtensions($extensions, $package, $packagePath);
$this->extensions = $extensions->sortBy(function ($extension) {
return $extension->composerJsonAttribute('extra.flarum-extension.title');
});
}
return $this->extensions;
} }
/** /**
@ -111,4 +101,36 @@ class ExtensionManagerIncludeCurrent extends ExtensionManager
return new FilesystemAdapter(new \League\Flysystem\Filesystem($adapter), $adapter); 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;
}
} }

View File

@ -116,7 +116,7 @@ class SetupScript
'base' => $tmp, 'base' => $tmp,
'public' => "$tmp/public", 'public' => "$tmp/public",
'storage' => "$tmp/storage", 'storage' => "$tmp/storage",
'vendor' => getcwd().'/vendor', 'vendor' => getenv('FLARUM_TEST_VENDOR_PATH') ?: getcwd().'/vendor',
]) ])
); );

View File

@ -64,7 +64,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
'base' => $tmp, 'base' => $tmp,
'public' => "$tmp/public", 'public' => "$tmp/public",
'storage' => "$tmp/storage", 'storage' => "$tmp/storage",
'vendor' => getcwd().'/vendor', 'vendor' => getenv('FLARUM_TEST_VENDOR_PATH') ?: getcwd().'/vendor',
]), ]),
new Config($config) new Config($config)
); );

View File

@ -7,10 +7,6 @@
* LICENSE file that was distributed with this source code. * LICENSE file that was distributed with this source code.
*/ */
use Flarum\Testing\integration\Setup\SetupScript; $setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
require __DIR__.'/../../vendor/autoload.php';
$setup = new SetupScript();
$setup->run(); $setup->run();

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="true" processIsolation="true"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>

View File

@ -10,6 +10,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
> >
<coverage processUncoveredFiles="true"> <coverage processUncoveredFiles="true">
<include> <include>