From e219db37183f7b0480b1e4888bc885034845bd97 Mon Sep 17 00:00:00 2001 From: Nicolas Peugnet Date: Fri, 23 Jun 2023 15:47:41 +0200 Subject: [PATCH 1/7] chore(testing): run flarum/testing packages tests back again These tests were not run on each framework build, I enabled them again. Two of the tests were failing so I disabled them for now, it is more important to have some tests running than none at all. --- .github/workflows/backend.yml | 2 +- composer.json | 3 ++- php-packages/testing/tests/.gitignore | 3 ++- php-packages/testing/tests/composer.json | 2 +- php-packages/testing/tests/tests/.phpunit.result.cache | 1 - php-packages/testing/tests/tests/integration/TestCaseTest.php | 4 ++-- php-packages/testing/tests/tests/integration/setup.php | 2 +- php-packages/testing/tests/tests/phpunit.integration.xml | 2 +- php-packages/testing/tests/tests/phpunit.unit.xml | 2 +- 9 files changed, 11 insertions(+), 10 deletions(-) delete mode 100644 php-packages/testing/tests/tests/.phpunit.result.cache diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index fad36a3ad3..e10c6cf5bd 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -8,4 +8,4 @@ jobs: 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" + 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 php-packages/testing/tests" diff --git a/composer.json b/composer.json index e21ebfb8a2..45565be0ab 100644 --- a/composer.json +++ b/composer.json @@ -197,7 +197,8 @@ "extensions/sticky", "extensions/subscriptions", "extensions/suspend", - "extensions/tags" + "extensions/tags", + "php-packages/testing/tests" ], "branch-alias": { "dev-main": "2.x-dev" diff --git a/php-packages/testing/tests/.gitignore b/php-packages/testing/tests/.gitignore index 208a599131..3d3b669caa 100644 --- a/php-packages/testing/tests/.gitignore +++ b/php-packages/testing/tests/.gitignore @@ -1 +1,2 @@ -vendor/* \ No newline at end of file +vendor/* +tests/.*.cache diff --git a/php-packages/testing/tests/composer.json b/php-packages/testing/tests/composer.json index cc8ba7bb9f..521f1b38fb 100644 --- a/php-packages/testing/tests/composer.json +++ b/php-packages/testing/tests/composer.json @@ -3,7 +3,7 @@ "description": "Minimal extension to test the flarum/testing package", "type": "flarum-extension", "require": { - "flarum/core": "^0.1.0@dev" + "flarum/core": "^1.0@dev" }, "require-dev": { "flarum/testing": "*@dev" diff --git a/php-packages/testing/tests/tests/.phpunit.result.cache b/php-packages/testing/tests/tests/.phpunit.result.cache deleted file mode 100644 index 05fbec964e..0000000000 --- a/php-packages/testing/tests/tests/.phpunit.result.cache +++ /dev/null @@ -1 +0,0 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":219:{a:2:{s:7:"defects";a:1:{s:74:"Flarum\Testing\Tests\integration\TestCaseTest::can_add_settings_via_method";i:4;}s:5:"times";a:1:{s:74:"Flarum\Testing\Tests\integration\TestCaseTest::can_add_settings_via_method";d:0.09;}}} \ No newline at end of file diff --git a/php-packages/testing/tests/tests/integration/TestCaseTest.php b/php-packages/testing/tests/tests/integration/TestCaseTest.php index 3638e00a2e..54b7ad7f67 100644 --- a/php-packages/testing/tests/tests/integration/TestCaseTest.php +++ b/php-packages/testing/tests/tests/integration/TestCaseTest.php @@ -49,7 +49,7 @@ public function can_add_settings_via_method() } /** - * @test + * Disabled failing test for now. */ public function settings_cleaned_up_from_previous_method() { @@ -194,7 +194,7 @@ public function routes_added_by_current_extension_accessible() } /** - * @test + * Disabled failing test for now. */ public function extension_url_correct() { diff --git a/php-packages/testing/tests/tests/integration/setup.php b/php-packages/testing/tests/tests/integration/setup.php index 96caab5fef..f41d90749c 100644 --- a/php-packages/testing/tests/tests/integration/setup.php +++ b/php-packages/testing/tests/tests/integration/setup.php @@ -7,6 +7,6 @@ * LICENSE file that was distributed with this source code. */ -$setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php'; +$setup = require __DIR__.'/../../../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 f9fbdf591a..f84f9de44a 100644 --- a/php-packages/testing/tests/tests/phpunit.integration.xml +++ b/php-packages/testing/tests/tests/phpunit.integration.xml @@ -10,7 +10,7 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" - bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" + bootstrap="../../bootstrap/monorepo.php" > diff --git a/php-packages/testing/tests/tests/phpunit.unit.xml b/php-packages/testing/tests/tests/phpunit.unit.xml index 66262dd9ff..aab6943ac4 100644 --- a/php-packages/testing/tests/tests/phpunit.unit.xml +++ b/php-packages/testing/tests/tests/phpunit.unit.xml @@ -10,7 +10,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - bootstrap="../../../php-packages/testing/bootstrap/monorepo.php" + bootstrap="../../bootstrap/monorepo.php" > From 9f1d2bb00bee97368f26242dcdb7892c0ec0d504 Mon Sep 17 00:00:00 2001 From: Nicolas Peugnet Date: Fri, 23 Jun 2023 16:40:34 +0200 Subject: [PATCH 2/7] chore(testing): remove flarum/testing dedicated workflow It is useless now that the tests are run in the framework repo. Also this workflow was not working anymore. --- .../testing/.github/workflows/test.yml | 83 ------------------- 1 file changed, 83 deletions(-) delete mode 100644 php-packages/testing/.github/workflows/test.yml diff --git a/php-packages/testing/.github/workflows/test.yml b/php-packages/testing/.github/workflows/test.yml deleted file mode 100644 index b7ba28c304..0000000000 --- a/php-packages/testing/.github/workflows/test.yml +++ /dev/null @@ -1,83 +0,0 @@ -name: Tests - -on: [push, pull_request] - -jobs: - test: - runs-on: ubuntu-latest - - defaults: - run: - shell: bash - working-directory: tests - - strategy: - matrix: - php: [7.3, 7.4, '8.0'] - service: ['mysql:5.7', mariadb] - prefix: ['', flarum_] - - include: - - service: 'mysql:5.7' - db: MySQL - - service: mariadb - db: MariaDB - - prefix: flarum_ - prefixStr: (prefix) - - exclude: - - php: 7.3 - service: 'mysql:5.7' - prefix: flarum_ - - php: 7.3 - service: mariadb - prefix: flarum_ - - php: 8.0 - service: 'mysql:5.7' - prefix: flarum_ - - php: 8.0 - service: mariadb - prefix: flarum_ - - services: - mysql: - image: ${{ matrix.service }} - ports: - - 13306:3306 - - name: 'PHP ${{ matrix.php }} / ${{ matrix.db }} ${{ matrix.prefixStr }}' - - steps: - - uses: actions/checkout@master - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - coverage: xdebug - extensions: curl, dom, gd, json, mbstring, openssl, pdo_mysql, tokenizer, zip - tools: phpunit, composer:v2 - - # The authentication alter is necessary because newer mysql versions use the `caching_sha2_password` driver, - # which isn't supported prior to PHP7.4 - # When we drop support for PHP7.3, we should remove this from the setup. - - name: Create MySQL Database - run: | - sudo systemctl start mysql - mysql -uroot -proot -e 'CREATE DATABASE flarum_test;' --port 13306 - mysql -uroot -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';" --port 13306 - - - name: Install Composer dependencies - run: composer install - - - name: Setup Composer tests - run: composer test:setup - env: - DB_PORT: 13306 - DB_PASSWORD: root - DB_PREFIX: ${{ matrix.prefix }} - - - name: Run Composer tests - run: composer test - env: - COMPOSER_PROCESS_TIMEOUT: 600 From 60466aec11afba6e6275156a75e258debecee167 Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Fri, 29 Nov 2024 12:54:51 +0100 Subject: [PATCH 3/7] chore --- composer.json | 3 +-- php-packages/testing/tests/composer.json | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 236635165a..1358721ef0 100644 --- a/composer.json +++ b/composer.json @@ -200,8 +200,7 @@ "extensions/subscriptions", "extensions/suspend", "extensions/tags", - "extensions/messages", - "php-packages/testing/tests" + "extensions/messages" ], "branch-alias": { "dev-main": "2.x-dev" diff --git a/php-packages/testing/tests/composer.json b/php-packages/testing/tests/composer.json index 521f1b38fb..c2085682b4 100644 --- a/php-packages/testing/tests/composer.json +++ b/php-packages/testing/tests/composer.json @@ -3,7 +3,7 @@ "description": "Minimal extension to test the flarum/testing package", "type": "flarum-extension", "require": { - "flarum/core": "^1.0@dev" + "flarum/core": "^2.0@dev" }, "require-dev": { "flarum/testing": "*@dev" From a7fe0700b66316018a078b9693c845ec90b65bca Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Fri, 29 Nov 2024 13:04:13 +0100 Subject: [PATCH 4/7] chore --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 84fc3723ca..f59bf24d93 100644 --- a/composer.json +++ b/composer.json @@ -200,7 +200,8 @@ "extensions/subscriptions", "extensions/suspend", "extensions/tags", - "extensions/messages" + "extensions/messages", + "php-packages/testing/tests" ], "branch-alias": { "dev-main": "2.x-dev" From d53b39b27fafaf7d9fdfc246021a667dd75488e6 Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Fri, 29 Nov 2024 13:13:00 +0100 Subject: [PATCH 5/7] chore --- composer.json | 3 +- php-packages/testing/composer.json | 13 +++-- .../tests/tests/integration/TestCaseTest.php | 49 +++++-------------- 3 files changed, 24 insertions(+), 41 deletions(-) diff --git a/composer.json b/composer.json index f59bf24d93..84fc3723ca 100644 --- a/composer.json +++ b/composer.json @@ -200,8 +200,7 @@ "extensions/subscriptions", "extensions/suspend", "extensions/tags", - "extensions/messages", - "php-packages/testing/tests" + "extensions/messages" ], "branch-alias": { "dev-main": "2.x-dev" diff --git a/php-packages/testing/composer.json b/php-packages/testing/composer.json index c8e7a885aa..ec72e52e36 100644 --- a/php-packages/testing/composer.json +++ b/php-packages/testing/composer.json @@ -13,7 +13,8 @@ "phpunit/phpunit": "^11.0" }, "require-dev": { - "flarum/core": "*@dev" + "flarum/core": "*@dev", + "flarum/testing-tests": "*@dev" }, "autoload": { "psr-4": { @@ -30,10 +31,16 @@ "dev-main": "2.x-dev" } }, - "repositories": [{ + "repositories": [ + { "type": "path", "url": "../../*/*" - }], + }, + { + "type": "path", + "url": "tests" + } + ], "minimum-stability": "dev", "prefer-stable": true } diff --git a/php-packages/testing/tests/tests/integration/TestCaseTest.php b/php-packages/testing/tests/tests/integration/TestCaseTest.php index 54b7ad7f67..7d41173fbc 100644 --- a/php-packages/testing/tests/tests/integration/TestCaseTest.php +++ b/php-packages/testing/tests/tests/integration/TestCaseTest.php @@ -15,12 +15,11 @@ use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Database\Schema\Builder; +use PHPUnit\Framework\Attributes\Test; class TestCaseTest extends TestCase { - /** - * @test - */ + #[Test] public function admin_user_created_as_part_of_default_state() { $this->app(); @@ -34,9 +33,7 @@ public function admin_user_created_as_part_of_default_state() $this->assertTrue($user->isAdmin()); } - /** - * @test - */ + #[Test] public function can_add_settings_via_method() { $this->setting('hello', 'world'); @@ -59,9 +56,7 @@ public function settings_cleaned_up_from_previous_method() $this->assertEquals(null, $settings->get('display_name_driver')); } - /** - * @test - */ + #[Test] public function can_add_config_via_method() { $this->config('hello', 'world'); @@ -75,9 +70,7 @@ public function can_add_config_via_method() $this->assertEquals('value', $config['level1']['level2']); } - /** - * @test - */ + #[Test] public function config_cleaned_up_from_previous_method() { $config = $this->app()->getContainer()->make(Config::class); @@ -87,9 +80,7 @@ public function config_cleaned_up_from_previous_method() $this->assertFalse(isset($config['level1']['level2'])); } - /** - * @test - */ + #[Test] public function current_extension_not_applied_by_default() { $response = $this->send( @@ -99,9 +90,7 @@ public function current_extension_not_applied_by_default() $this->assertStringNotContainsString('notARealSetting', $response->getBody()->getContents()); } - /** - * @test - */ + #[Test] public function current_extension_applied_if_specified() { $this->extension('flarum-testing-tests'); @@ -113,9 +102,7 @@ public function current_extension_applied_if_specified() $this->assertStringContainsString('notARealSetting', $response->getBody()->getContents()); } - /** - * @test - */ + #[Test] public function current_extension_migrations_applied_if_specified() { $this->extension('flarum-testing-tests'); @@ -124,9 +111,7 @@ public function current_extension_migrations_applied_if_specified() $this->assertTrue($tableExists); } - /** - * @test - */ + #[Test] public function current_extension_considered_enabled_after_boot() { $this->extension('flarum-testing-tests'); @@ -135,9 +120,7 @@ public function current_extension_considered_enabled_after_boot() $this->assertTrue($enabled); } - /** - * @test - */ + #[Test] public function can_apply_extenders() { $this->extend( @@ -151,9 +134,7 @@ public function can_apply_extenders() $this->assertStringContainsString('notARealSetting', $response->getBody()->getContents()); } - /** - * @test - */ + #[Test] public function can_apply_route_extenders() { $this->extend( @@ -167,9 +148,7 @@ public function can_apply_route_extenders() $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function routes_added_by_current_extension_not_accessible_by_default() { $response = $this->send( @@ -179,9 +158,7 @@ public function routes_added_by_current_extension_not_accessible_by_default() $this->assertEquals(404, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function routes_added_by_current_extension_accessible() { $this->extension('flarum-testing-tests'); From 8c7fe79178a8d1e4b95c38513cfd28913f56fd4c Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Fri, 29 Nov 2024 13:22:01 +0100 Subject: [PATCH 6/7] chore --- composer.json | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 84fc3723ca..9e7216aa6d 100644 --- a/composer.json +++ b/composer.json @@ -172,7 +172,8 @@ "phpunit/phpunit": "^11.0", "phpstan/phpstan": "^1.10.0", "larastan/larastan": "2.9.12", - "symfony/var-dumper": "^7.0" + "symfony/var-dumper": "^7.0", + "flarum/testing-tests": "*@dev" }, "config": { "sort-packages": true @@ -217,5 +218,11 @@ }, "scripts-descriptions": { "analyse:phpstan": "Run static analysis" - } + }, + "repositories": [ + { + "type": "path", + "url": "php-packages/testing/tests" + } + ] } From 5196aaddc3b77a27c89740b6b36e2950d9a3a197 Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Fri, 29 Nov 2024 13:42:00 +0100 Subject: [PATCH 7/7] fix --- .../Extension/ExtensionManagerIncludeCurrent.php | 7 ++++++- php-packages/testing/tests/composer.json | 11 +++++++++++ .../tests/tests/integration/TestCaseTest.php | 14 +++++++------- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/php-packages/testing/src/integration/Extension/ExtensionManagerIncludeCurrent.php b/php-packages/testing/src/integration/Extension/ExtensionManagerIncludeCurrent.php index 546899b8e2..7362d0bf71 100644 --- a/php-packages/testing/src/integration/Extension/ExtensionManagerIncludeCurrent.php +++ b/php-packages/testing/src/integration/Extension/ExtensionManagerIncludeCurrent.php @@ -12,6 +12,7 @@ use Flarum\Database\Migrator; use Flarum\Extension\Extension; use Flarum\Extension\ExtensionManager; +use Flarum\Foundation\Config; use Flarum\Foundation\MaintenanceMode; use Flarum\Foundation\Paths; use Flarum\Settings\SettingsRepositoryInterface; @@ -99,9 +100,13 @@ protected function setEnabledExtensions(array $enabledExtensions): void */ protected function getAssetsFilesystem(): Cloud { + /** @var Config $config */ + $config = $this->container->make(Config::class); $adapter = new LocalFilesystemAdapter($this->paths->public.'/assets'); - return new FilesystemAdapter(new \League\Flysystem\Filesystem($adapter), $adapter); + return new FilesystemAdapter(new \League\Flysystem\Filesystem($adapter), $adapter, [ + 'url' => $config->url().'/assets', + ]); } protected function includeCurrentExtension(Collection $extensions, $package, string $packagePath): Collection diff --git a/php-packages/testing/tests/composer.json b/php-packages/testing/tests/composer.json index c2085682b4..b0153e8fd3 100644 --- a/php-packages/testing/tests/composer.json +++ b/php-packages/testing/tests/composer.json @@ -13,6 +13,17 @@ "Flarum\\Testing\\Tests\\": "tests/" } }, + "extra": { + "flarum-extension": { + "title": "Testing", + "category": "feature", + "icon": { + "name": "fas fa-vial", + "backgroundColor": "#ABDC88", + "color": "#3F8A32" + } + } + }, "scripts": { "test": [ "@test:unit", diff --git a/php-packages/testing/tests/tests/integration/TestCaseTest.php b/php-packages/testing/tests/tests/integration/TestCaseTest.php index 7d41173fbc..95953a9c16 100644 --- a/php-packages/testing/tests/tests/integration/TestCaseTest.php +++ b/php-packages/testing/tests/tests/integration/TestCaseTest.php @@ -10,7 +10,9 @@ namespace Flarum\Testing\Tests\integration; use Flarum\Extend; +use Flarum\Extension\ExtensionManager; use Flarum\Foundation\Config; +use Flarum\Settings\DefaultSettingsRepository; use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Testing\integration\TestCase; use Flarum\User\User; @@ -45,15 +47,14 @@ public function can_add_settings_via_method() $this->assertEquals('something_other_than_username', $settings->get('display_name_driver')); } - /** - * Disabled failing test for now. - */ + #[Test] public function settings_cleaned_up_from_previous_method() { $settings = $this->app()->getContainer()->make(SettingsRepositoryInterface::class); + $defaults = $this->app()->getContainer()->make(DefaultSettingsRepository::class); $this->assertEquals(null, $settings->get('hello')); - $this->assertEquals(null, $settings->get('display_name_driver')); + $this->assertEquals($defaults->get('display_name_driver'), $settings->get('display_name_driver')); } #[Test] @@ -170,14 +171,13 @@ public function routes_added_by_current_extension_accessible() $this->assertEquals(200, $response->getStatusCode()); } - /** - * Disabled failing test for now. - */ + #[Test] public function extension_url_correct() { $this->extension('flarum-testing-tests'); $expected = $this->app()->getContainer()->make('filesystem')->disk('flarum-assets')->url('/flarum-testing-tests/'); // We need to test this since we override it. + /** @var ExtensionManager $extensions */ $extensions = $this->app()->getContainer()->make('flarum.extensions'); $currExtension = $extensions->getExtension('flarum-testing-tests'); $baseAssetsUrl = $extensions->getAsset($currExtension, '');