From 64b25b26c34fb786f5fafa8c2e53a757be5a5d83 Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Thu, 15 Jun 2023 13:26:39 +0100 Subject: [PATCH] chore: improve test suite (#3814) Allows running tests without constantly running `composer install` on each extension. --- .github/workflows/REUSABLE_backend.yml | 30 ++++++++--- .github/workflows/backend.yml | 11 ++++ .github/workflows/flarum-akismet-backend.yml | 11 ---- .github/workflows/flarum-approval-backend.yml | 11 ---- .github/workflows/flarum-core-backend.yml | 11 ---- .github/workflows/flarum-embed-backend.yml | 11 ---- .github/workflows/flarum-emoji-backend.yml | 11 ---- .github/workflows/flarum-flags-backend.yml | 11 ---- .github/workflows/flarum-likes-backend.yml | 11 ---- .github/workflows/flarum-lock-backend.yml | 11 ---- .github/workflows/flarum-markdown-backend.yml | 11 ---- .github/workflows/flarum-mentions-backend.yml | 11 ---- .../workflows/flarum-nicknames-backend.yml | 11 ---- .../flarum-package-manager-backend.yml | 11 ---- .github/workflows/flarum-pusher-backend.yml | 11 ---- .../workflows/flarum-statistics-backend.yml | 11 ---- .github/workflows/flarum-sticky-backend.yml | 11 ---- .../flarum-subscriptions-backend.yml | 11 ---- .github/workflows/flarum-suspend-backend.yml | 11 ---- .github/workflows/flarum-tags-backend.yml | 11 ---- .github/workflows/frontend.yml | 2 +- .github/workflows/phpstan.yml | 3 +- composer.json | 20 +++++++ .../akismet/tests/integration/setup.php | 6 +-- .../akismet/tests/phpunit.integration.xml | 1 + extensions/akismet/tests/phpunit.unit.xml | 1 + .../approval/tests/integration/setup.php | 6 +-- .../approval/tests/phpunit.integration.xml | 1 + extensions/approval/tests/phpunit.unit.xml | 1 + extensions/flags/tests/integration/setup.php | 6 +-- .../flags/tests/phpunit.integration.xml | 1 + extensions/flags/tests/phpunit.unit.xml | 1 + extensions/likes/tests/integration/setup.php | 6 +-- .../likes/tests/phpunit.integration.xml | 1 + extensions/likes/tests/phpunit.unit.xml | 1 + .../mentions/tests/integration/setup.php | 6 +-- .../mentions/tests/phpunit.integration.xml | 1 + extensions/mentions/tests/phpunit.unit.xml | 1 + .../nicknames/tests/integration/setup.php | 6 +-- .../nicknames/tests/phpunit.integration.xml | 1 + extensions/nicknames/tests/phpunit.unit.xml | 1 + .../tests/integration/setup.php | 5 +- .../tests/phpunit.integration.xml | 1 + .../package-manager/tests/phpunit.unit.xml | 1 + .../statistics/tests/integration/setup.php | 6 +-- .../statistics/tests/phpunit.integration.xml | 1 + extensions/statistics/tests/phpunit.unit.xml | 1 + extensions/sticky/tests/integration/setup.php | 6 +-- .../sticky/tests/phpunit.integration.xml | 1 + extensions/sticky/tests/phpunit.unit.xml | 1 + .../subscriptions/tests/integration/setup.php | 6 +-- .../tests/phpunit.integration.xml | 1 + .../subscriptions/tests/phpunit.unit.xml | 1 + .../suspend/tests/integration/setup.php | 6 +-- .../suspend/tests/phpunit.integration.xml | 1 + extensions/suspend/tests/phpunit.unit.xml | 1 + extensions/tags/tests/integration/setup.php | 6 +-- extensions/tags/tests/phpunit.integration.xml | 1 + extensions/tags/tests/phpunit.unit.xml | 1 + .../core/src/Extension/ExtensionManager.php | 53 +++++++++++++------ framework/core/tests/integration/setup.php | 6 +-- framework/core/tests/phpunit.integration.xml | 1 + framework/core/tests/phpunit.unit.xml | 1 + php-packages/testing/bootstrap/monorepo.php | 42 +++++++++++++++ .../ExtensionManagerIncludeCurrent.php | 48 ++++++++++++----- .../src/integration/Setup/SetupScript.php | 2 +- .../testing/src/integration/TestCase.php | 2 +- .../testing/tests/tests/integration/setup.php | 6 +-- .../tests/tests/phpunit.integration.xml | 1 + .../testing/tests/tests/phpunit.unit.xml | 1 + 70 files changed, 213 insertions(+), 309 deletions(-) create mode 100644 .github/workflows/backend.yml delete mode 100644 .github/workflows/flarum-akismet-backend.yml delete mode 100644 .github/workflows/flarum-approval-backend.yml delete mode 100644 .github/workflows/flarum-core-backend.yml delete mode 100644 .github/workflows/flarum-embed-backend.yml delete mode 100644 .github/workflows/flarum-emoji-backend.yml delete mode 100644 .github/workflows/flarum-flags-backend.yml delete mode 100644 .github/workflows/flarum-likes-backend.yml delete mode 100644 .github/workflows/flarum-lock-backend.yml delete mode 100644 .github/workflows/flarum-markdown-backend.yml delete mode 100644 .github/workflows/flarum-mentions-backend.yml delete mode 100644 .github/workflows/flarum-nicknames-backend.yml delete mode 100644 .github/workflows/flarum-package-manager-backend.yml delete mode 100644 .github/workflows/flarum-pusher-backend.yml delete mode 100644 .github/workflows/flarum-statistics-backend.yml delete mode 100644 .github/workflows/flarum-sticky-backend.yml delete mode 100644 .github/workflows/flarum-subscriptions-backend.yml delete mode 100644 .github/workflows/flarum-suspend-backend.yml delete mode 100644 .github/workflows/flarum-tags-backend.yml create mode 100644 php-packages/testing/bootstrap/monorepo.php diff --git a/.github/workflows/REUSABLE_backend.yml b/.github/workflows/REUSABLE_backend.yml index 57923a4124..67203d3e35 100644 --- a/.github/workflows/REUSABLE_backend.yml +++ b/.github/workflows/REUSABLE_backend.yml @@ -21,6 +21,12 @@ on: required: false 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: description: Versions of PHP to test with. Should be array of strings encoded as JSON array type: string @@ -47,6 +53,7 @@ on: env: COMPOSER_ROOT_VERSION: dev-main + # `inputs.composer_directory` defaults to `inputs.backend_directory` FLARUM_TEST_TMP_DIR_LOCAL: tests/integration/tmp jobs: @@ -143,18 +150,27 @@ jobs: run: composer install working-directory: ${{ inputs.backend_directory }} - - name: Setup Composer tests - run: composer test:setup + # If we have a `inputs.monorepo_tests`, we will run tests for each item of the provided array in a ::group::item + # 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 }} env: DB_PORT: 13306 DB_PASSWORD: root DB_PREFIX: ${{ matrix.prefix }} - - - name: Run Composer tests - run: composer test - working-directory: ${{ inputs.backend_directory }} - env: COMPOSER_PROCESS_TIMEOUT: 600 phpstan: diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml new file mode 100644 index 0000000000..fad36a3ad3 --- /dev/null +++ b/.github/workflows/backend.yml @@ -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" diff --git a/.github/workflows/flarum-akismet-backend.yml b/.github/workflows/flarum-akismet-backend.yml deleted file mode 100644 index a493e93da8..0000000000 --- a/.github/workflows/flarum-akismet-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-approval-backend.yml b/.github/workflows/flarum-approval-backend.yml deleted file mode 100644 index fec282a699..0000000000 --- a/.github/workflows/flarum-approval-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-core-backend.yml b/.github/workflows/flarum-core-backend.yml deleted file mode 100644 index 5017573820..0000000000 --- a/.github/workflows/flarum-core-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-embed-backend.yml b/.github/workflows/flarum-embed-backend.yml deleted file mode 100644 index 41325d9d72..0000000000 --- a/.github/workflows/flarum-embed-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-emoji-backend.yml b/.github/workflows/flarum-emoji-backend.yml deleted file mode 100644 index ff8a402e93..0000000000 --- a/.github/workflows/flarum-emoji-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-flags-backend.yml b/.github/workflows/flarum-flags-backend.yml deleted file mode 100644 index ec8f91d877..0000000000 --- a/.github/workflows/flarum-flags-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-likes-backend.yml b/.github/workflows/flarum-likes-backend.yml deleted file mode 100644 index a3347bd126..0000000000 --- a/.github/workflows/flarum-likes-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-lock-backend.yml b/.github/workflows/flarum-lock-backend.yml deleted file mode 100644 index a8ddba992e..0000000000 --- a/.github/workflows/flarum-lock-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-markdown-backend.yml b/.github/workflows/flarum-markdown-backend.yml deleted file mode 100644 index f1022fd5ca..0000000000 --- a/.github/workflows/flarum-markdown-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-mentions-backend.yml b/.github/workflows/flarum-mentions-backend.yml deleted file mode 100644 index 4955837bf2..0000000000 --- a/.github/workflows/flarum-mentions-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-nicknames-backend.yml b/.github/workflows/flarum-nicknames-backend.yml deleted file mode 100644 index 602bba515c..0000000000 --- a/.github/workflows/flarum-nicknames-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-package-manager-backend.yml b/.github/workflows/flarum-package-manager-backend.yml deleted file mode 100644 index 77a12e945c..0000000000 --- a/.github/workflows/flarum-package-manager-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-pusher-backend.yml b/.github/workflows/flarum-pusher-backend.yml deleted file mode 100644 index cc92162742..0000000000 --- a/.github/workflows/flarum-pusher-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-statistics-backend.yml b/.github/workflows/flarum-statistics-backend.yml deleted file mode 100644 index 514222f9f1..0000000000 --- a/.github/workflows/flarum-statistics-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-sticky-backend.yml b/.github/workflows/flarum-sticky-backend.yml deleted file mode 100644 index d86994abca..0000000000 --- a/.github/workflows/flarum-sticky-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-subscriptions-backend.yml b/.github/workflows/flarum-subscriptions-backend.yml deleted file mode 100644 index cfd21a0c4d..0000000000 --- a/.github/workflows/flarum-subscriptions-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-suspend-backend.yml b/.github/workflows/flarum-suspend-backend.yml deleted file mode 100644 index b65d7fb071..0000000000 --- a/.github/workflows/flarum-suspend-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/flarum-tags-backend.yml b/.github/workflows/flarum-tags-backend.yml deleted file mode 100644 index 6220908221..0000000000 --- a/.github/workflows/flarum-tags-backend.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 0c9ff95634..c70458f8c0 100755 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -1,4 +1,4 @@ -name: Framework JS +name: Frontend Workflow on: [workflow_dispatch, push, pull_request] diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index e0088cfd26..edb7d27e62 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -1,4 +1,4 @@ -name: Framework PHP +name: Static Code Analysis on: [workflow_dispatch, push, pull_request] @@ -8,5 +8,4 @@ jobs: with: enable_backend_testing: false enable_phpstan: true - backend_directory: . diff --git a/composer.json b/composer.json index 5e4b8d7871..d6163bfb59 100644 --- a/composer.json +++ b/composer.json @@ -60,6 +60,26 @@ "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": { "flarum/core": "self.version", "flarum/akismet": "self.version", diff --git a/extensions/akismet/tests/integration/setup.php b/extensions/akismet/tests/integration/setup.php index 67039c0832..96caab5fef 100644 --- a/extensions/akismet/tests/integration/setup.php +++ b/extensions/akismet/tests/integration/setup.php @@ -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(); diff --git a/extensions/akismet/tests/phpunit.integration.xml b/extensions/akismet/tests/phpunit.integration.xml index 90fbbff37c..7319d929ae 100644 --- a/extensions/akismet/tests/phpunit.integration.xml +++ b/extensions/akismet/tests/phpunit.integration.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/akismet/tests/phpunit.unit.xml b/extensions/akismet/tests/phpunit.unit.xml index d3a4a3e3d3..66262dd9ff 100644 --- a/extensions/akismet/tests/phpunit.unit.xml +++ b/extensions/akismet/tests/phpunit.unit.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/approval/tests/integration/setup.php b/extensions/approval/tests/integration/setup.php index 67039c0832..96caab5fef 100644 --- a/extensions/approval/tests/integration/setup.php +++ b/extensions/approval/tests/integration/setup.php @@ -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(); diff --git a/extensions/approval/tests/phpunit.integration.xml b/extensions/approval/tests/phpunit.integration.xml index 90fbbff37c..7319d929ae 100644 --- a/extensions/approval/tests/phpunit.integration.xml +++ b/extensions/approval/tests/phpunit.integration.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/approval/tests/phpunit.unit.xml b/extensions/approval/tests/phpunit.unit.xml index d3a4a3e3d3..66262dd9ff 100644 --- a/extensions/approval/tests/phpunit.unit.xml +++ b/extensions/approval/tests/phpunit.unit.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/flags/tests/integration/setup.php b/extensions/flags/tests/integration/setup.php index 67039c0832..96caab5fef 100644 --- a/extensions/flags/tests/integration/setup.php +++ b/extensions/flags/tests/integration/setup.php @@ -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(); diff --git a/extensions/flags/tests/phpunit.integration.xml b/extensions/flags/tests/phpunit.integration.xml index 90fbbff37c..7319d929ae 100644 --- a/extensions/flags/tests/phpunit.integration.xml +++ b/extensions/flags/tests/phpunit.integration.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/flags/tests/phpunit.unit.xml b/extensions/flags/tests/phpunit.unit.xml index d3a4a3e3d3..66262dd9ff 100644 --- a/extensions/flags/tests/phpunit.unit.xml +++ b/extensions/flags/tests/phpunit.unit.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/likes/tests/integration/setup.php b/extensions/likes/tests/integration/setup.php index 67039c0832..96caab5fef 100644 --- a/extensions/likes/tests/integration/setup.php +++ b/extensions/likes/tests/integration/setup.php @@ -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(); diff --git a/extensions/likes/tests/phpunit.integration.xml b/extensions/likes/tests/phpunit.integration.xml index 90fbbff37c..7319d929ae 100644 --- a/extensions/likes/tests/phpunit.integration.xml +++ b/extensions/likes/tests/phpunit.integration.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/likes/tests/phpunit.unit.xml b/extensions/likes/tests/phpunit.unit.xml index d3a4a3e3d3..66262dd9ff 100644 --- a/extensions/likes/tests/phpunit.unit.xml +++ b/extensions/likes/tests/phpunit.unit.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/mentions/tests/integration/setup.php b/extensions/mentions/tests/integration/setup.php index 67039c0832..96caab5fef 100644 --- a/extensions/mentions/tests/integration/setup.php +++ b/extensions/mentions/tests/integration/setup.php @@ -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(); diff --git a/extensions/mentions/tests/phpunit.integration.xml b/extensions/mentions/tests/phpunit.integration.xml index 90fbbff37c..7319d929ae 100644 --- a/extensions/mentions/tests/phpunit.integration.xml +++ b/extensions/mentions/tests/phpunit.integration.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/mentions/tests/phpunit.unit.xml b/extensions/mentions/tests/phpunit.unit.xml index d3a4a3e3d3..66262dd9ff 100644 --- a/extensions/mentions/tests/phpunit.unit.xml +++ b/extensions/mentions/tests/phpunit.unit.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/nicknames/tests/integration/setup.php b/extensions/nicknames/tests/integration/setup.php index 67039c0832..96caab5fef 100644 --- a/extensions/nicknames/tests/integration/setup.php +++ b/extensions/nicknames/tests/integration/setup.php @@ -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(); diff --git a/extensions/nicknames/tests/phpunit.integration.xml b/extensions/nicknames/tests/phpunit.integration.xml index 90fbbff37c..7319d929ae 100644 --- a/extensions/nicknames/tests/phpunit.integration.xml +++ b/extensions/nicknames/tests/phpunit.integration.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/nicknames/tests/phpunit.unit.xml b/extensions/nicknames/tests/phpunit.unit.xml index d3a4a3e3d3..66262dd9ff 100644 --- a/extensions/nicknames/tests/phpunit.unit.xml +++ b/extensions/nicknames/tests/phpunit.unit.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/package-manager/tests/integration/setup.php b/extensions/package-manager/tests/integration/setup.php index 49ccccb843..6b319855dd 100644 --- a/extensions/package-manager/tests/integration/setup.php +++ b/extensions/package-manager/tests/integration/setup.php @@ -8,11 +8,8 @@ */ use Flarum\PackageManager\Tests\integration\SetupComposer; -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(); diff --git a/extensions/package-manager/tests/phpunit.integration.xml b/extensions/package-manager/tests/phpunit.integration.xml index 89f91a4d15..e467c38a36 100644 --- a/extensions/package-manager/tests/phpunit.integration.xml +++ b/extensions/package-manager/tests/phpunit.integration.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/package-manager/tests/phpunit.unit.xml b/extensions/package-manager/tests/phpunit.unit.xml index d3a4a3e3d3..66262dd9ff 100644 --- a/extensions/package-manager/tests/phpunit.unit.xml +++ b/extensions/package-manager/tests/phpunit.unit.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/statistics/tests/integration/setup.php b/extensions/statistics/tests/integration/setup.php index 67039c0832..96caab5fef 100644 --- a/extensions/statistics/tests/integration/setup.php +++ b/extensions/statistics/tests/integration/setup.php @@ -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(); diff --git a/extensions/statistics/tests/phpunit.integration.xml b/extensions/statistics/tests/phpunit.integration.xml index 90fbbff37c..7319d929ae 100644 --- a/extensions/statistics/tests/phpunit.integration.xml +++ b/extensions/statistics/tests/phpunit.integration.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/statistics/tests/phpunit.unit.xml b/extensions/statistics/tests/phpunit.unit.xml index d3a4a3e3d3..66262dd9ff 100644 --- a/extensions/statistics/tests/phpunit.unit.xml +++ b/extensions/statistics/tests/phpunit.unit.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/sticky/tests/integration/setup.php b/extensions/sticky/tests/integration/setup.php index 67039c0832..96caab5fef 100644 --- a/extensions/sticky/tests/integration/setup.php +++ b/extensions/sticky/tests/integration/setup.php @@ -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(); diff --git a/extensions/sticky/tests/phpunit.integration.xml b/extensions/sticky/tests/phpunit.integration.xml index 90fbbff37c..7319d929ae 100644 --- a/extensions/sticky/tests/phpunit.integration.xml +++ b/extensions/sticky/tests/phpunit.integration.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/sticky/tests/phpunit.unit.xml b/extensions/sticky/tests/phpunit.unit.xml index d3a4a3e3d3..66262dd9ff 100644 --- a/extensions/sticky/tests/phpunit.unit.xml +++ b/extensions/sticky/tests/phpunit.unit.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/subscriptions/tests/integration/setup.php b/extensions/subscriptions/tests/integration/setup.php index 67039c0832..96caab5fef 100644 --- a/extensions/subscriptions/tests/integration/setup.php +++ b/extensions/subscriptions/tests/integration/setup.php @@ -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(); diff --git a/extensions/subscriptions/tests/phpunit.integration.xml b/extensions/subscriptions/tests/phpunit.integration.xml index 90fbbff37c..7319d929ae 100644 --- a/extensions/subscriptions/tests/phpunit.integration.xml +++ b/extensions/subscriptions/tests/phpunit.integration.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/subscriptions/tests/phpunit.unit.xml b/extensions/subscriptions/tests/phpunit.unit.xml index d3a4a3e3d3..66262dd9ff 100644 --- a/extensions/subscriptions/tests/phpunit.unit.xml +++ b/extensions/subscriptions/tests/phpunit.unit.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/suspend/tests/integration/setup.php b/extensions/suspend/tests/integration/setup.php index 67039c0832..96caab5fef 100644 --- a/extensions/suspend/tests/integration/setup.php +++ b/extensions/suspend/tests/integration/setup.php @@ -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(); diff --git a/extensions/suspend/tests/phpunit.integration.xml b/extensions/suspend/tests/phpunit.integration.xml index 90fbbff37c..7319d929ae 100644 --- a/extensions/suspend/tests/phpunit.integration.xml +++ b/extensions/suspend/tests/phpunit.integration.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/suspend/tests/phpunit.unit.xml b/extensions/suspend/tests/phpunit.unit.xml index d3a4a3e3d3..66262dd9ff 100644 --- a/extensions/suspend/tests/phpunit.unit.xml +++ b/extensions/suspend/tests/phpunit.unit.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/tags/tests/integration/setup.php b/extensions/tags/tests/integration/setup.php index 67039c0832..96caab5fef 100644 --- a/extensions/tags/tests/integration/setup.php +++ b/extensions/tags/tests/integration/setup.php @@ -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(); diff --git a/extensions/tags/tests/phpunit.integration.xml b/extensions/tags/tests/phpunit.integration.xml index 90fbbff37c..7319d929ae 100644 --- a/extensions/tags/tests/phpunit.integration.xml +++ b/extensions/tags/tests/phpunit.integration.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/extensions/tags/tests/phpunit.unit.xml b/extensions/tags/tests/phpunit.unit.xml index d3a4a3e3d3..66262dd9ff 100644 --- a/extensions/tags/tests/phpunit.unit.xml +++ b/extensions/tags/tests/phpunit.unit.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index a8d9fb4d2b..01613643dd 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -73,31 +73,18 @@ public function getExtensions(): Collection $composerJsonConfs[$packagePath] = $package; } - if ($subextPaths = Arr::get($package, 'extra.flarum-subextensions', [])) { - foreach ($subextPaths as $subExtPath) { - $subPackagePath = "$packagePath/$subExtPath"; - $conf = json_decode($this->filesystem->get("$subPackagePath/composer.json"), true); - - if (Arr::get($conf, 'type') === 'flarum-extension') { - $composerJsonConfs[$subPackagePath] = $conf; - } - } + if ($subExtConfs = $this->subExtensionConfsFromJson($package, $packagePath)) { + $composerJsonConfs = array_merge($composerJsonConfs, $subExtConfs); } } foreach ($composerJsonConfs as $path => $package) { $installedSet[Arr::get($package, 'name')] = true; - - // 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')); - + $extension = $this->extensionFromJson($package, $path); $extensions->put($extension->getId(), $extension); } + /** @var Extension $extension */ foreach ($extensions as $extension) { $extension->calculateDependencies($installedSet); } @@ -472,4 +459,36 @@ public static function resolveExtensionOrder(array $extensionList): array '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; + } } diff --git a/framework/core/tests/integration/setup.php b/framework/core/tests/integration/setup.php index 67039c0832..96caab5fef 100644 --- a/framework/core/tests/integration/setup.php +++ b/framework/core/tests/integration/setup.php @@ -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(); diff --git a/framework/core/tests/phpunit.integration.xml b/framework/core/tests/phpunit.integration.xml index 90fbbff37c..7319d929ae 100644 --- a/framework/core/tests/phpunit.integration.xml +++ b/framework/core/tests/phpunit.integration.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/framework/core/tests/phpunit.unit.xml b/framework/core/tests/phpunit.unit.xml index d3a4a3e3d3..66262dd9ff 100644 --- a/framework/core/tests/phpunit.unit.xml +++ b/framework/core/tests/phpunit.unit.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/php-packages/testing/bootstrap/monorepo.php b/php-packages/testing/bootstrap/monorepo.php new file mode 100644 index 0000000000..4d25d257b8 --- /dev/null +++ b/php-packages/testing/bootstrap/monorepo.php @@ -0,0 +1,42 @@ +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->put($current->getId(), $current); - - $this->extensions = $extensions->sortBy(function ($extension) { - return $extension->composerJsonAttribute('extra.flarum-extension.title'); - }); - } + $extensions = $this->includeCurrentExtension($extensions, $package, $packagePath); - return $this->extensions; + return $this->extensions = $this->includeMonorepoExtensions($extensions, $package, $packagePath); } /** @@ -111,4 +101,36 @@ protected function getAssetsFilesystem(): Cloud 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; + } } diff --git a/php-packages/testing/src/integration/Setup/SetupScript.php b/php-packages/testing/src/integration/Setup/SetupScript.php index f9c75afb2e..e6d70a9eaf 100644 --- a/php-packages/testing/src/integration/Setup/SetupScript.php +++ b/php-packages/testing/src/integration/Setup/SetupScript.php @@ -116,7 +116,7 @@ public function run() 'base' => $tmp, 'public' => "$tmp/public", 'storage' => "$tmp/storage", - 'vendor' => getcwd().'/vendor', + 'vendor' => getenv('FLARUM_TEST_VENDOR_PATH') ?: getcwd().'/vendor', ]) ); diff --git a/php-packages/testing/src/integration/TestCase.php b/php-packages/testing/src/integration/TestCase.php index fa26609710..a0913ab2fa 100644 --- a/php-packages/testing/src/integration/TestCase.php +++ b/php-packages/testing/src/integration/TestCase.php @@ -64,7 +64,7 @@ protected function app() 'base' => $tmp, 'public' => "$tmp/public", 'storage' => "$tmp/storage", - 'vendor' => getcwd().'/vendor', + 'vendor' => getenv('FLARUM_TEST_VENDOR_PATH') ?: getcwd().'/vendor', ]), new Config($config) ); diff --git a/php-packages/testing/tests/tests/integration/setup.php b/php-packages/testing/tests/tests/integration/setup.php index 67039c0832..96caab5fef 100644 --- a/php-packages/testing/tests/tests/integration/setup.php +++ b/php-packages/testing/tests/tests/integration/setup.php @@ -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(); diff --git a/php-packages/testing/tests/tests/phpunit.integration.xml b/php-packages/testing/tests/tests/phpunit.integration.xml index 23afc237d5..f9fbdf591a 100644 --- a/php-packages/testing/tests/tests/phpunit.integration.xml +++ b/php-packages/testing/tests/tests/phpunit.integration.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" > diff --git a/php-packages/testing/tests/tests/phpunit.unit.xml b/php-packages/testing/tests/tests/phpunit.unit.xml index d3a4a3e3d3..66262dd9ff 100644 --- a/php-packages/testing/tests/tests/phpunit.unit.xml +++ b/php-packages/testing/tests/tests/phpunit.unit.xml @@ -10,6 +10,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" + bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" >