Skip to content

Commit

Permalink
chore: improve test suite (#3814)
Browse files Browse the repository at this point in the history
Allows running tests without constantly running `composer install` on each extension.
  • Loading branch information
SychO9 authored Jun 15, 2023
1 parent 6bc19e2 commit 64b25b2
Show file tree
Hide file tree
Showing 70 changed files with 213 additions and 309 deletions.
30 changes: 23 additions & 7 deletions .github/workflows/REUSABLE_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 0 additions & 11 deletions .github/workflows/flarum-akismet-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-approval-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-core-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-embed-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-emoji-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-flags-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-likes-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-lock-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-markdown-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-mentions-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-nicknames-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-package-manager-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-pusher-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-statistics-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-sticky-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-subscriptions-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-suspend-backend.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/flarum-tags-backend.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Framework JS
name: Frontend Workflow

on: [workflow_dispatch, push, pull_request]

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Framework PHP
name: Static Code Analysis

on: [workflow_dispatch, push, pull_request]

Expand All @@ -8,5 +8,4 @@ jobs:
with:
enable_backend_testing: false
enable_phpstan: true

backend_directory: .
20 changes: 20 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 1 addition & 5 deletions extensions/akismet/tests/integration/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
1 change: 1 addition & 0 deletions extensions/akismet/tests/phpunit.integration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
convertWarningsToExceptions="true"
processIsolation="true"
stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
>
<coverage processUncoveredFiles="true">
<include>
Expand Down
1 change: 1 addition & 0 deletions extensions/akismet/tests/phpunit.unit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
>
<coverage processUncoveredFiles="true">
<include>
Expand Down
6 changes: 1 addition & 5 deletions extensions/approval/tests/integration/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
1 change: 1 addition & 0 deletions extensions/approval/tests/phpunit.integration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
convertWarningsToExceptions="true"
processIsolation="true"
stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
>
<coverage processUncoveredFiles="true">
<include>
Expand Down
1 change: 1 addition & 0 deletions extensions/approval/tests/phpunit.unit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
>
<coverage processUncoveredFiles="true">
<include>
Expand Down
6 changes: 1 addition & 5 deletions extensions/flags/tests/integration/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Loading

0 comments on commit 64b25b2

Please sign in to comment.