diff --git a/.github/workflows/REUSABLE_backend.yml b/.github/workflows/REUSABLE_backend.yml index 46e823c8e..0b4a837e3 100644 --- a/.github/workflows/REUSABLE_backend.yml +++ b/.github/workflows/REUSABLE_backend.yml @@ -32,7 +32,7 @@ on: type: string required: false # Keep PHP versions synced with build-install-packages.yml - default: '["8.1", "8.2", "8.3"]' + default: '["8.2", "8.3"]' php_extensions: description: PHP extensions to install. diff --git a/.github/workflows/build-install-packages.yml b/.github/workflows/build-install-packages.yml index fb4b88320..5ecdd320f 100644 --- a/.github/workflows/build-install-packages.yml +++ b/.github/workflows/build-install-packages.yml @@ -6,7 +6,7 @@ on: env: VERSION: ${{ github.event.release.tag_name }} - PHP_VERSIONS: '8.1 8.2 8.3' + PHP_VERSIONS: '8.2 8.3' INSTALL_PACKAGES_INPUTS: '{ "flarum_version": "{0}", "php_versions": "{1}" }' jobs: diff --git a/composer.json b/composer.json index 17431a63b..f117d7021 100644 --- a/composer.json +++ b/composer.json @@ -105,7 +105,7 @@ "flarum/testing": "self.version" }, "require": { - "php": "^8.1", + "php": "^8.2", "ext-json": "*", "components/font-awesome": "^5.15.0", "composer/composer": "^2.7", @@ -115,22 +115,22 @@ "fakerphp/faker": "^1.9.1", "franzl/whoops-middleware": "2.0", "guzzlehttp/guzzle": "*", - "illuminate/bus": "^10.0", - "illuminate/cache": "^10.0", - "illuminate/config": "^10.0", - "illuminate/console": "^10.0", - "illuminate/container": "^10.0", - "illuminate/contracts": "^10.0", - "illuminate/database": "^10.0", - "illuminate/events": "^10.0", - "illuminate/filesystem": "^10.0", - "illuminate/hashing": "^10.0", - "illuminate/mail": "^10.0", - "illuminate/queue": "^10.0", - "illuminate/session": "^10.0", - "illuminate/support": "^10.0", - "illuminate/validation": "^10.0", - "illuminate/view": "^10.0", + "illuminate/bus": "^11.0", + "illuminate/cache": "^11.0", + "illuminate/config": "^11.0", + "illuminate/console": "^11.0", + "illuminate/container": "^11.0", + "illuminate/contracts": "^11.0", + "illuminate/database": "^11.0", + "illuminate/events": "^11.0", + "illuminate/filesystem": "^11.0", + "illuminate/hashing": "^11.0", + "illuminate/mail": "^11.0", + "illuminate/queue": "^11.0", + "illuminate/session": "^11.0", + "illuminate/support": "^11.0", + "illuminate/validation": "^11.0", + "illuminate/view": "^11.0", "intervention/image": "^3.2", "jenssegers/agent": "^2.6", "laminas/laminas-diactoros": "^3.0", @@ -143,34 +143,33 @@ "middlewares/base-path-router": "^2.0.1", "middlewares/request-handler": "^2.0.2", "monolog/monolog": "^3.3", - "nesbot/carbon": "^2.66", + "nesbot/carbon": "^3.0", "nikic/fast-route": "^1.3", "psr/http-message": "^1.1", "psr/http-server-handler": "^1.0.2", "psr/http-server-middleware": "^1.0.2", "pusher/pusher-php-server": "^7.2", "s9e/text-formatter": "^2.13", - "staudenmeir/eloquent-eager-limit": "^1.8.2", "sycho/sourcemap": "^2.0.0", - "symfony/config": "^6.3", - "symfony/console": "^6.3", - "symfony/event-dispatcher": "^6.3", - "symfony/http-client": "^6.3", - "symfony/mailgun-mailer": "^6.3", - "symfony/mime": "^6.3", + "symfony/config": "^7.0", + "symfony/console": "^7.0", + "symfony/event-dispatcher": "^7.0", + "symfony/http-client": "^7.0", + "symfony/mailgun-mailer": "^7.0", + "symfony/mime": "^7.0", "symfony/polyfill-intl-messageformatter": "^1.27", - "symfony/postmark-mailer": "^6.3", - "symfony/translation": "^6.3", - "symfony/yaml": "^6.3", + "symfony/postmark-mailer": "^7.0", + "symfony/translation": "^7.0", + "symfony/yaml": "^7.0", "flarum/json-api-server": "^0.1.0", "wikimedia/less.php": "^4.1" }, "require-dev": { "mockery/mockery": "^1.5", - "phpunit/phpunit": "^9.0", + "phpunit/phpunit": "^11.0", "phpstan/phpstan": "^1.10.0", "larastan/larastan": "^2.7", - "symfony/var-dumper": "^6.3" + "symfony/var-dumper": "^7.0" }, "config": { "sort-packages": true diff --git a/extensions/akismet/.gitignore b/extensions/akismet/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/akismet/.gitignore +++ b/extensions/akismet/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/akismet/tests/phpunit.integration.xml b/extensions/akismet/tests/phpunit.integration.xml index 7319d929a..e3e14eab9 100644 --- a/extensions/akismet/tests/phpunit.integration.xml +++ b/extensions/akismet/tests/phpunit.integration.xml @@ -1,22 +1,20 @@ - + ../src/ - + ./integration diff --git a/extensions/akismet/tests/phpunit.unit.xml b/extensions/akismet/tests/phpunit.unit.xml index 66262dd9f..67367a782 100644 --- a/extensions/akismet/tests/phpunit.unit.xml +++ b/extensions/akismet/tests/phpunit.unit.xml @@ -1,28 +1,23 @@ - + ../src/ - + ./unit - - - diff --git a/extensions/approval/.gitignore b/extensions/approval/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/approval/.gitignore +++ b/extensions/approval/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/approval/tests/integration/InteractsWithUnapprovedContent.php b/extensions/approval/tests/integration/InteractsWithUnapprovedContent.php index bcf749887..6b6b70d31 100644 --- a/extensions/approval/tests/integration/InteractsWithUnapprovedContent.php +++ b/extensions/approval/tests/integration/InteractsWithUnapprovedContent.php @@ -64,7 +64,7 @@ trait InteractsWithUnapprovedContent /** * null: Guest, 2: Normal User. */ - public function unallowedUsers(): array + public static function unallowedUsers(): array { return [[null], [2]]; } @@ -72,7 +72,7 @@ trait InteractsWithUnapprovedContent /** * 1: Admin, 3: Permission Given, 4: Discussions Author. */ - public function allowedUsers(): array + public static function allowedUsers(): array { return [[1], [3], [4]]; } diff --git a/extensions/approval/tests/integration/api/ApprovePostsTest.php b/extensions/approval/tests/integration/api/ApprovePostsTest.php index 5d8a322d8..d5d3c5ead 100644 --- a/extensions/approval/tests/integration/api/ApprovePostsTest.php +++ b/extensions/approval/tests/integration/api/ApprovePostsTest.php @@ -17,6 +17,7 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class ApprovePostsTest extends TestCase { @@ -59,9 +60,7 @@ class ApprovePostsTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function can_approve_unapproved_post() { $response = $this->send( @@ -81,9 +80,7 @@ class ApprovePostsTest extends TestCase $this->assertEquals(1, $this->database()->table('posts')->where('id', 3)->where('is_approved', 1)->count()); } - /** - * @test - */ + #[Test] public function cannot_approve_post_without_permission() { $response = $this->send( @@ -103,9 +100,7 @@ class ApprovePostsTest extends TestCase $this->assertEquals(0, $this->database()->table('posts')->where('id', 3)->where('is_approved', 1)->count()); } - /** - * @test - */ + #[Test] public function hiding_post_silently_approves_it() { $response = $this->send( diff --git a/extensions/approval/tests/integration/api/CreatePostsTest.php b/extensions/approval/tests/integration/api/CreatePostsTest.php index 7099f3fa9..e8a87600b 100644 --- a/extensions/approval/tests/integration/api/CreatePostsTest.php +++ b/extensions/approval/tests/integration/api/CreatePostsTest.php @@ -17,6 +17,8 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class CreatePostsTest extends TestCase { @@ -68,10 +70,8 @@ class CreatePostsTest extends TestCase ]); } - /** - * @dataProvider startDiscussionDataProvider - * @test - */ + #[Test] + #[DataProvider('startDiscussionDataProvider')] public function can_start_discussion_without_approval_when_allowed(int $authenticatedAs, bool $allowed) { $this->database()->table('group_permission')->where('group_id', Group::MEMBER_ID)->where('permission', 'discussion.startWithoutApproval')->delete(); @@ -98,10 +98,8 @@ class CreatePostsTest extends TestCase $this->assertEquals($allowed ? 1 : 0, $this->database()->table('discussions')->where('id', $json['data']['id'])->value('is_approved')); } - /** - * @dataProvider replyToDiscussionDataProvider - * @test - */ + #[Test] + #[DataProvider('replyToDiscussionDataProvider')] public function can_reply_without_approval_when_allowed(?int $authenticatedAs, bool $allowed) { $this->database()->table('group_permission')->where('group_id', Group::MEMBER_ID)->where('permission', 'discussion.replyWithoutApproval')->delete(); diff --git a/extensions/approval/tests/integration/api/ListDiscussionsTest.php b/extensions/approval/tests/integration/api/ListDiscussionsTest.php index 2ebb63951..1f4976128 100644 --- a/extensions/approval/tests/integration/api/ListDiscussionsTest.php +++ b/extensions/approval/tests/integration/api/ListDiscussionsTest.php @@ -13,6 +13,8 @@ use Flarum\Approval\Tests\integration\InteractsWithUnapprovedContent; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class ListDiscussionsTest extends TestCase { @@ -28,10 +30,8 @@ class ListDiscussionsTest extends TestCase $this->prepareUnapprovedDatabaseContent(); } - /** - * @dataProvider unallowedUsers - * @test - */ + #[Test] + #[DataProvider('unallowedUsers')] public function can_only_see_approved_if_not_allowed_to_approve(?int $authenticatedAs) { $response = $this->send( @@ -44,10 +44,8 @@ class ListDiscussionsTest extends TestCase $this->assertEqualsCanonicalizing([1, 4, 5, 7], Arr::pluck($body['data'], 'id')); } - /** - * @dataProvider allowedUsers - * @test - */ + #[Test] + #[DataProvider('allowedUsers')] public function can_see_unapproved_if_allowed_to_approve(int $authenticatedAs) { $response = $this->send( diff --git a/extensions/approval/tests/integration/api/ListPostsTest.php b/extensions/approval/tests/integration/api/ListPostsTest.php index 844d0f796..ce06f2440 100644 --- a/extensions/approval/tests/integration/api/ListPostsTest.php +++ b/extensions/approval/tests/integration/api/ListPostsTest.php @@ -13,6 +13,8 @@ use Flarum\Approval\Tests\integration\InteractsWithUnapprovedContent; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class ListPostsTest extends TestCase { @@ -28,10 +30,8 @@ class ListPostsTest extends TestCase $this->prepareUnapprovedDatabaseContent(); } - /** - * @dataProvider unallowedUsers - * @test - */ + #[Test] + #[DataProvider('unallowedUsers')] public function can_only_see_approved_if_not_allowed_to_approve(?int $authenticatedAs) { $response = $this->send( @@ -50,10 +50,8 @@ class ListPostsTest extends TestCase $this->assertEqualsCanonicalizing([7, 8, 10], Arr::pluck($body['data'], 'id')); } - /** - * @dataProvider allowedUsers - * @test - */ + #[Test] + #[DataProvider('allowedUsers')] public function can_see_unapproved_if_allowed_to_approve(int $authenticatedAs) { $response = $this->send( diff --git a/extensions/approval/tests/phpunit.integration.xml b/extensions/approval/tests/phpunit.integration.xml index 7319d929a..e3e14eab9 100644 --- a/extensions/approval/tests/phpunit.integration.xml +++ b/extensions/approval/tests/phpunit.integration.xml @@ -1,22 +1,20 @@ - + ../src/ - + ./integration diff --git a/extensions/approval/tests/phpunit.unit.xml b/extensions/approval/tests/phpunit.unit.xml index 66262dd9f..67367a782 100644 --- a/extensions/approval/tests/phpunit.unit.xml +++ b/extensions/approval/tests/phpunit.unit.xml @@ -1,28 +1,23 @@ - + ../src/ - + ./unit - - - diff --git a/extensions/bbcode/.gitignore b/extensions/bbcode/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/bbcode/.gitignore +++ b/extensions/bbcode/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/embed/.gitignore b/extensions/embed/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/embed/.gitignore +++ b/extensions/embed/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/emoji/.gitignore b/extensions/emoji/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/emoji/.gitignore +++ b/extensions/emoji/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/flags/.gitignore b/extensions/flags/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/flags/.gitignore +++ b/extensions/flags/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/flags/migrations/2019_10_22_000000_change_reason_text_col_type.php b/extensions/flags/migrations/2019_10_22_000000_change_reason_text_col_type.php index 5b1af104a..167a51148 100644 --- a/extensions/flags/migrations/2019_10_22_000000_change_reason_text_col_type.php +++ b/extensions/flags/migrations/2019_10_22_000000_change_reason_text_col_type.php @@ -13,13 +13,13 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { $schema->table('flags', function (Blueprint $table) { - $table->text('reason_detail')->change(); + $table->text('reason_detail')->nullable()->change(); }); }, 'down' => function (Builder $schema) { $schema->table('flags', function (Blueprint $table) { - $table->string('reason_detail')->change(); + $table->string('reason_detail')->nullable()->change(); }); } ]; diff --git a/extensions/flags/tests/integration/api/flags/ListTest.php b/extensions/flags/tests/integration/api/flags/ListTest.php index 57f21344d..33ace7c7e 100644 --- a/extensions/flags/tests/integration/api/flags/ListTest.php +++ b/extensions/flags/tests/integration/api/flags/ListTest.php @@ -19,6 +19,7 @@ use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Database\PostgresConnection; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class ListTest extends TestCase { @@ -70,9 +71,7 @@ class ListTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function admin_can_see_one_flag_per_visible_post() { $response = $this->send( @@ -96,9 +95,7 @@ class ListTest extends TestCase } } - /** - * @test - */ + #[Test] public function regular_user_sees_own_flags_of_visible_posts() { $response = $this->send( @@ -115,9 +112,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(['2', '4'], $ids); } - /** - * @test - */ + #[Test] public function mod_can_see_one_flag_per_visible_post() { $response = $this->send( @@ -134,9 +129,7 @@ class ListTest extends TestCase $this->assertCount(3, $data); } - /** - * @test - */ + #[Test] public function guest_cant_see_flags() { $response = $this->send( diff --git a/extensions/flags/tests/integration/api/flags/ListWithTagsTest.php b/extensions/flags/tests/integration/api/flags/ListWithTagsTest.php index e1a6526cb..3dc8ae6b9 100644 --- a/extensions/flags/tests/integration/api/flags/ListWithTagsTest.php +++ b/extensions/flags/tests/integration/api/flags/ListWithTagsTest.php @@ -19,6 +19,7 @@ use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; use Illuminate\Support\Carbon; +use PHPUnit\Framework\Attributes\Test; class ListWithTagsTest extends TestCase { @@ -101,9 +102,7 @@ class ListWithTagsTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function admin_can_see_one_flag_per_post() { $response = $this->send( @@ -122,9 +121,7 @@ class ListWithTagsTest extends TestCase $this->assertCount(7, $data); } - /** - * @test - */ + #[Test] public function regular_user_sees_own_flags() { $response = $this->send( @@ -141,9 +138,7 @@ class ListWithTagsTest extends TestCase $this->assertEqualsCanonicalizing(['2', '4'], $ids); } - /** - * @test - */ + #[Test] public function mod_can_see_one_flag_per_post() { $response = $this->send( @@ -162,9 +157,7 @@ class ListWithTagsTest extends TestCase $this->assertCount(5, $data); } - /** - * @test - */ + #[Test] public function guest_cant_see_flags() { $response = $this->send( diff --git a/extensions/flags/tests/integration/api/posts/IncludeFlagsVisibilityTest.php b/extensions/flags/tests/integration/api/posts/IncludeFlagsVisibilityTest.php index 02100a7d8..412c154d2 100644 --- a/extensions/flags/tests/integration/api/posts/IncludeFlagsVisibilityTest.php +++ b/extensions/flags/tests/integration/api/posts/IncludeFlagsVisibilityTest.php @@ -18,6 +18,8 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class IncludeFlagsVisibilityTest extends TestCase { @@ -106,10 +108,8 @@ class IncludeFlagsVisibilityTest extends TestCase ]); } - /** - * @dataProvider listFlagsIncludesDataProvider - * @test - */ + #[Test] + #[DataProvider('listFlagsIncludesDataProvider')] public function user_sees_where_allowed_with_included_tags(int $actorId, array $expectedIncludes) { $response = $this->send( @@ -137,7 +137,7 @@ class IncludeFlagsVisibilityTest extends TestCase ); } - public function listFlagsIncludesDataProvider(): array + public static function listFlagsIncludesDataProvider(): array { return [ 'admin_sees_all' => [1, [1, 2, 3, 4, 5, 6, 7, 8]], diff --git a/extensions/flags/tests/phpunit.integration.xml b/extensions/flags/tests/phpunit.integration.xml index 7319d929a..e3e14eab9 100644 --- a/extensions/flags/tests/phpunit.integration.xml +++ b/extensions/flags/tests/phpunit.integration.xml @@ -1,22 +1,20 @@ - + ../src/ - + ./integration diff --git a/extensions/flags/tests/phpunit.unit.xml b/extensions/flags/tests/phpunit.unit.xml index 66262dd9f..67367a782 100644 --- a/extensions/flags/tests/phpunit.unit.xml +++ b/extensions/flags/tests/phpunit.unit.xml @@ -1,28 +1,23 @@ - + ../src/ - + ./unit - - - diff --git a/extensions/lang-english/.gitignore b/extensions/lang-english/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/lang-english/.gitignore +++ b/extensions/lang-english/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/likes/.gitignore b/extensions/likes/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/likes/.gitignore +++ b/extensions/likes/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/likes/tests/integration/api/LikePostTest.php b/extensions/likes/tests/integration/api/LikePostTest.php index 570081e1f..d79c4f76b 100644 --- a/extensions/likes/tests/integration/api/LikePostTest.php +++ b/extensions/likes/tests/integration/api/LikePostTest.php @@ -17,6 +17,8 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Psr\Http\Message\ResponseInterface; class LikePostTest extends TestCase @@ -60,10 +62,8 @@ class LikePostTest extends TestCase $this->database()->table('group_permission')->insert(['permission' => 'discussion.likePosts', 'group_id' => 5]); } - /** - * @dataProvider allowedUsersToLike - * @test - */ + #[Test] + #[DataProvider('allowedUsersToLike')] public function can_like_a_post_if_allowed(int $postId, ?int $authenticatedAs, string $message, bool $canLikeOwnPost = null) { if (! is_null($canLikeOwnPost)) { @@ -80,10 +80,8 @@ class LikePostTest extends TestCase $this->assertNotNull($post->likes->where('id', $authenticatedAs)->first(), $message); } - /** - * @dataProvider unallowedUsersToLike - * @test - */ + #[Test] + #[DataProvider('unallowedUsersToLike')] public function cannot_like_a_post_if_not_allowed(int $postId, ?int $authenticatedAs, string $message, bool $canLikeOwnPost = null) { if (! is_null($canLikeOwnPost)) { @@ -100,10 +98,8 @@ class LikePostTest extends TestCase $this->assertNull($post->likes->where('id', $authenticatedAs)->first()); } - /** - * @dataProvider allowedUsersToLike - * @test - */ + #[Test] + #[DataProvider('allowedUsersToLike')] public function can_dislike_a_post_if_liked_and_allowed(int $postId, ?int $authenticatedAs, string $message, bool $canLikeOwnPost = null) { if (! is_null($canLikeOwnPost)) { @@ -121,7 +117,7 @@ class LikePostTest extends TestCase $this->assertNull($post->likes->where('id', $authenticatedAs)->first(), $message); } - public function allowedUsersToLike(): array + public static function allowedUsersToLike(): array { return [ [1, 1, 'Admin can like any post'], @@ -130,7 +126,7 @@ class LikePostTest extends TestCase ]; } - public function unallowedUsersToLike(): array + public static function unallowedUsersToLike(): array { return [ [1, null, 'Guest cannot like any post'], diff --git a/extensions/likes/tests/integration/api/ListPostsTest.php b/extensions/likes/tests/integration/api/ListPostsTest.php index 37c5a8415..31639daed 100644 --- a/extensions/likes/tests/integration/api/ListPostsTest.php +++ b/extensions/likes/tests/integration/api/ListPostsTest.php @@ -18,6 +18,8 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class ListPostsTest extends TestCase { @@ -72,9 +74,7 @@ class ListPostsTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function liked_filter_works() { $response = $this->send( @@ -95,9 +95,7 @@ class ListPostsTest extends TestCase ], $ids, 'IDs do not match'); } - /** - * @test - */ + #[Test] public function liked_filter_works_negated() { $response = $this->send( @@ -116,7 +114,7 @@ class ListPostsTest extends TestCase $this->assertEqualsCanonicalizing([1, 103], $ids, 'IDs do not match'); } - /** @test */ + #[Test] public function likes_relation_returns_limited_results_and_shows_only_visible_posts_in_show_post_endpoint() { // List posts endpoint @@ -142,7 +140,7 @@ class ListPostsTest extends TestCase $this->assertEquals([2, 102, 104, 105], Arr::pluck($likes, 'id')); } - /** @test */ + #[Test] public function likes_relation_returns_limited_results_and_shows_only_visible_posts_in_list_posts_endpoint() { // List posts endpoint @@ -169,10 +167,8 @@ class ListPostsTest extends TestCase $this->assertEquals([2, 102, 104, 105], Arr::pluck($likes, 'id')); } - /** - * @dataProvider likesIncludeProvider - * @test - */ + #[Test] + #[DataProvider('likesIncludeProvider')] public function likes_relation_returns_limited_results_and_shows_only_visible_posts_in_show_discussion_endpoint(?string $include) { // Show discussion endpoint @@ -207,7 +203,7 @@ class ListPostsTest extends TestCase $this->assertEquals([2, 102, 104, 105], Arr::pluck($likes, 'id'), $body); } - public function likesIncludeProvider(): array + public static function likesIncludeProvider(): array { return [ ['posts,posts.likes'], diff --git a/extensions/likes/tests/phpunit.integration.xml b/extensions/likes/tests/phpunit.integration.xml index 7319d929a..e3e14eab9 100644 --- a/extensions/likes/tests/phpunit.integration.xml +++ b/extensions/likes/tests/phpunit.integration.xml @@ -1,22 +1,20 @@ - + ../src/ - + ./integration diff --git a/extensions/likes/tests/phpunit.unit.xml b/extensions/likes/tests/phpunit.unit.xml index 66262dd9f..67367a782 100644 --- a/extensions/likes/tests/phpunit.unit.xml +++ b/extensions/likes/tests/phpunit.unit.xml @@ -1,28 +1,23 @@ - + ../src/ - + ./unit - - - diff --git a/extensions/lock/.gitignore b/extensions/lock/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/lock/.gitignore +++ b/extensions/lock/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/markdown/.gitignore b/extensions/markdown/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/markdown/.gitignore +++ b/extensions/markdown/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/mentions/.gitignore b/extensions/mentions/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/mentions/.gitignore +++ b/extensions/mentions/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/mentions/tests/integration/api/GroupMentionsTest.php b/extensions/mentions/tests/integration/api/GroupMentionsTest.php index 6be5870a1..2efa17744 100644 --- a/extensions/mentions/tests/integration/api/GroupMentionsTest.php +++ b/extensions/mentions/tests/integration/api/GroupMentionsTest.php @@ -17,6 +17,7 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class GroupMentionsTest extends TestCase { @@ -63,9 +64,7 @@ class GroupMentionsTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function rendering_a_valid_group_mention_works() { $response = $this->send( @@ -83,9 +82,7 @@ class GroupMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsGroups->find(4)); } - /** - * @test - */ + #[Test] public function mentioning_an_invalid_group_doesnt_work() { $response = $this->send( @@ -114,9 +111,7 @@ class GroupMentionsTest extends TestCase $this->assertCount(0, CommentPost::find($response['data']['id'])->mentionsGroups); } - /** - * @test - */ + #[Test] public function deleted_group_mentions_render_with_deleted_label() { $deleted_text = $this->app()->getContainer()->make('translator')->trans('flarum-mentions.forum.group_mention.deleted_text'); @@ -138,9 +133,7 @@ class GroupMentionsTest extends TestCase $this->assertCount(0, CommentPost::find($response['data']['id'])->mentionsGroups); } - /** - * @test - */ + #[Test] public function group_mentions_render_with_fresh_data() { $response = $this->send( @@ -159,9 +152,7 @@ class GroupMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsGroups->find(11)); } - /** - * @test - */ + #[Test] public function mentioning_a_group_as_an_admin_user_works() { $response = $this->send( @@ -192,9 +183,7 @@ class GroupMentionsTest extends TestCase $this->assertCount(1, CommentPost::find($response['data']['id'])->mentionsGroups); } - /** - * @test - */ + #[Test] public function mentioning_multiple_groups_as_an_admin_user_works() { $response = $this->send( @@ -227,9 +216,7 @@ class GroupMentionsTest extends TestCase $this->assertCount(2, CommentPost::find($response['data']['id'])->mentionsGroups); } - /** - * @test - */ + #[Test] public function mentioning_a_virtual_group_as_an_admin_user_does_not_work() { $response = $this->send( @@ -262,18 +249,14 @@ class GroupMentionsTest extends TestCase $this->assertCount(0, CommentPost::find($response['data']['id'])->mentionsGroups); } - /** - * @test - */ + #[Test] public function regular_user_does_not_have_group_mention_permission_by_default() { $this->database(); $this->assertFalse(User::find(3)->can('mentionGroups')); } - /** - * @test - */ + #[Test] public function regular_user_does_have_group_mention_permission_when_added() { $this->prepareDatabase([ @@ -286,9 +269,7 @@ class GroupMentionsTest extends TestCase $this->assertTrue(User::find(3)->can('mentionGroups')); } - /** - * @test - */ + #[Test] public function user_without_permission_cannot_mention_groups() { $response = $this->send( @@ -318,9 +299,7 @@ class GroupMentionsTest extends TestCase $this->assertCount(0, CommentPost::find($response['data']['id'])->mentionsGroups); } - /** - * @test - */ + #[Test] public function user_with_permission_can_mention_groups() { $response = $this->send( @@ -350,9 +329,7 @@ class GroupMentionsTest extends TestCase $this->assertCount(1, CommentPost::find($response['data']['id'])->mentionsGroups); } - /** - * @test - */ + #[Test] public function user_with_permission_cannot_mention_hidden_groups() { $response = $this->send( @@ -382,9 +359,7 @@ class GroupMentionsTest extends TestCase $this->assertCount(0, CommentPost::find($response['data']['id'])->mentionsGroups); } - /** - * @test - */ + #[Test] public function editing_a_post_that_has_a_mention_works() { $response = $this->send( diff --git a/extensions/mentions/tests/integration/api/ListPostsTest.php b/extensions/mentions/tests/integration/api/ListPostsTest.php index d5214aebb..d45bfd892 100644 --- a/extensions/mentions/tests/integration/api/ListPostsTest.php +++ b/extensions/mentions/tests/integration/api/ListPostsTest.php @@ -17,6 +17,8 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class ListPostsTest extends TestCase { @@ -52,9 +54,7 @@ class ListPostsTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function mentioned_filter_works() { $response = $this->send( @@ -71,9 +71,7 @@ class ListPostsTest extends TestCase $this->assertEqualsCanonicalizing(['2', '3'], $ids, 'IDs do not match'); } - /** - * @test - */ + #[Test] public function mentioned_filter_works_negated() { $response = $this->send( @@ -90,9 +88,7 @@ class ListPostsTest extends TestCase $this->assertEqualsCanonicalizing(['4'], $ids, 'IDs do not match'); } - /** - * @test - */ + #[Test] public function mentioned_filter_works_with_sort() { $response = $this->send( @@ -149,7 +145,7 @@ class ListPostsTest extends TestCase ]); } - /** @test */ + #[Test] public function mentioned_by_relation_returns_limited_results_and_shows_only_visible_posts_in_show_post_endpoint() { $this->prepareMentionedByData(); @@ -175,7 +171,7 @@ class ListPostsTest extends TestCase $this->assertEquals([102, 104, 105, 106], Arr::pluck($mentionedBy, 'id')); } - /** @test */ + #[Test] public function mentioned_by_relation_returns_limited_results_and_shows_only_visible_posts_in_list_posts_endpoint() { $this->prepareMentionedByData(); @@ -203,10 +199,8 @@ class ListPostsTest extends TestCase $this->assertEquals([102, 104, 105, 106], Arr::pluck($mentionedBy, 'id')); } - /** - * @dataProvider mentionedByIncludeProvider - * @test - */ + #[Test] + #[DataProvider('mentionedByIncludeProvider')] public function mentioned_by_relation_returns_limited_results_and_shows_only_visible_posts_in_show_discussion_endpoint(?string $include) { $this->prepareMentionedByData(); @@ -236,7 +230,7 @@ class ListPostsTest extends TestCase $this->assertEquals([102, 104, 105, 106], Arr::pluck($mentionedBy, 'id')); } - public function mentionedByIncludeProvider(): array + public static function mentionedByIncludeProvider(): array { return [ ['posts,posts.mentionedBy'], @@ -245,7 +239,7 @@ class ListPostsTest extends TestCase ]; } - /** @test */ + #[Test] public function mentioned_by_count_only_includes_visible_posts_to_actor() { $this->prepareMentionedByData(); @@ -264,7 +258,7 @@ class ListPostsTest extends TestCase $this->assertEquals(0, $data['attributes']['mentionedByCount']); } - /** @test */ + #[Test] public function mentioned_by_count_works_on_show_endpoint() { $this->prepareMentionedByData(); @@ -283,7 +277,7 @@ class ListPostsTest extends TestCase $this->assertEquals(10, $data['attributes']['mentionedByCount']); } - /** @test */ + #[Test] public function mentioned_by_count_works_on_list_endpoint() { $this->prepareMentionedByData(); diff --git a/extensions/mentions/tests/integration/api/PostMentionsTest.php b/extensions/mentions/tests/integration/api/PostMentionsTest.php index a408b4a3b..0b9cd9c8e 100644 --- a/extensions/mentions/tests/integration/api/PostMentionsTest.php +++ b/extensions/mentions/tests/integration/api/PostMentionsTest.php @@ -19,6 +19,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\DisplayName\DriverInterface; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class PostMentionsTest extends TestCase { @@ -73,9 +74,7 @@ class PostMentionsTest extends TestCase ); } - /** - * @test - */ + #[Test] public function mentioning_a_valid_post_with_old_format_doesnt_work() { $response = $this->send( @@ -107,9 +106,7 @@ class PostMentionsTest extends TestCase $this->assertNull(CommentPost::find($response['data']['id'])->mentionsPosts->find(4)); } - /** - * @test - */ + #[Test] public function mentioning_a_valid_post_with_new_format_works() { $response = $this->send( @@ -139,9 +136,7 @@ class PostMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsPosts->find(4)); } - /** - * @test - */ + #[Test] public function cannot_mention_a_post_without_access() { $response = $this->send( @@ -171,9 +166,7 @@ class PostMentionsTest extends TestCase $this->assertNull(CommentPost::find($response['data']['id'])->mentionsPosts->find(50)); } - /** - * @test - */ + #[Test] public function mentioning_a_valid_post_with_new_format_with_smart_quotes_works_and_falls_back_to_normal_quotes() { $response = $this->send( @@ -205,9 +198,7 @@ class PostMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsPosts->find(4)); } - /** - * @test - */ + #[Test] public function mentioning_an_invalid_post_doesnt_work() { $response = $this->send( @@ -237,9 +228,7 @@ class PostMentionsTest extends TestCase $this->assertCount(0, CommentPost::find($response['data']['id'])->mentionsPosts); } - /** - * @test - */ + #[Test] public function mentioning_multiple_posts_works() { $response = $this->send( @@ -271,9 +260,7 @@ class PostMentionsTest extends TestCase $this->assertCount(2, CommentPost::find($response['data']['id'])->mentionsPosts); } - /** - * @test - */ + #[Test] public function post_mentions_render_with_fresh_data() { $response = $this->send( @@ -291,9 +278,7 @@ class PostMentionsTest extends TestCase $this->assertCount(1, CommentPost::find($response['data']['id'])->mentionsPosts); } - /** - * @test - */ + #[Test] public function post_mentions_unparse_with_fresh_data() { $response = $this->send( @@ -310,9 +295,7 @@ class PostMentionsTest extends TestCase $this->assertCount(1, CommentPost::find($response['data']['id'])->mentionsPosts); } - /** - * @test - */ + #[Test] public function deleted_post_mentions_s_user_unparse_and_render_without_user_data() { $deleted_text = $this->app()->getContainer()->make('translator')->trans('core.lib.username.deleted_text'); @@ -335,9 +318,7 @@ class PostMentionsTest extends TestCase $this->assertCount(1, CommentPost::find($response['data']['id'])->mentionsPosts); } - /** - * @test - */ + #[Test] public function deleted_post_mentions_unparse_and_render_without_user_data() { $deleted_text = $this->app()->getContainer()->make('translator')->trans('flarum-mentions.forum.post_mention.deleted_text'); @@ -360,9 +341,7 @@ class PostMentionsTest extends TestCase $this->assertCount(0, CommentPost::find($response['data']['id'])->mentionsPosts); } - /** - * @test - */ + #[Test] public function deleted_post_mentions_and_deleted_user_unparse_and_render_without_user_data() { $deleted_text = $this->app()->getContainer()->make('translator')->trans('flarum-mentions.forum.post_mention.deleted_text'); @@ -385,9 +364,7 @@ class PostMentionsTest extends TestCase $this->assertCount(0, CommentPost::find($response['data']['id'])->mentionsPosts); } - /** - * @test - */ + #[Test] public function post_mentions_with_unremoved_bad_string_from_display_names_doesnt_work() { $response = $this->send( @@ -417,9 +394,7 @@ class PostMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsPosts->find(6)); } - /** - * @test - */ + #[Test] public function post_mentions_unparsing_removes_bad_display_name_string() { $response = $this->send( @@ -438,9 +413,7 @@ class PostMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsPosts->find(9)); } - /** - * @test - */ + #[Test] public function post_mentions_with_removed_bad_string_from_display_names_works() { $response = $this->send( @@ -470,9 +443,7 @@ class PostMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsPosts->find(9)); } - /** - * @test - */ + #[Test] public function editing_a_post_that_has_a_mention_works() { $response = $this->send( @@ -499,9 +470,7 @@ class PostMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsPosts->find(9)); } - /** - * @test - */ + #[Test] public function editing_a_post_with_deleted_author_that_has_a_mention_works() { $response = $this->send( @@ -530,9 +499,7 @@ class PostMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsPosts->find(9)); } - /** - * @test - */ + #[Test] public function editing_a_post_with_a_mention_of_a_post_with_deleted_author_works() { $response = $this->send( @@ -559,9 +526,7 @@ class PostMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsPosts->find(11)); } - /** - * @test - */ + #[Test] public function rendering_post_mention_with_a_post_context_works() { /** @var Formatter $formatter */ @@ -576,9 +541,7 @@ class PostMentionsTest extends TestCase $this->assertStringContainsString('TOBY$', $renderedHtml); } - /** - * @test - */ + #[Test] public function rendering_post_mention_without_a_context_works() { /** @var Formatter $formatter */ diff --git a/extensions/mentions/tests/integration/api/TagMentionsTest.php b/extensions/mentions/tests/integration/api/TagMentionsTest.php index 54b4615c1..abf12fc29 100644 --- a/extensions/mentions/tests/integration/api/TagMentionsTest.php +++ b/extensions/mentions/tests/integration/api/TagMentionsTest.php @@ -18,6 +18,7 @@ use Flarum\Tags\Tag; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class TagMentionsTest extends TestCase { @@ -64,7 +65,7 @@ class TagMentionsTest extends TestCase ]); } - /** @test */ + #[Test] public function mentioning_a_valid_tag_with_valid_format_works() { $response = $this->send( @@ -93,7 +94,7 @@ class TagMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsTags->find(2)); } - /** @test */ + #[Test] public function mentioning_a_valid_tag_using_cjk_slug_with_valid_format_works() { $response = $this->send( @@ -123,7 +124,7 @@ class TagMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsTags->find(6)); } - /** @test */ + #[Test] public function mentioning_an_invalid_tag_doesnt_work() { $response = $this->send( @@ -152,7 +153,7 @@ class TagMentionsTest extends TestCase $this->assertCount(0, CommentPost::find($response['data']['id'])->mentionsTags); } - /** @test */ + #[Test] public function mentioning_a_tag_when_tags_disabled_does_not_cause_errors() { $this->extensions = ['flarum-mentions']; @@ -183,7 +184,7 @@ class TagMentionsTest extends TestCase $this->assertNull(CommentPost::find($response['data']['id'])->mentionsTags); } - /** @test */ + #[Test] public function mentioning_a_restricted_tag_doesnt_work_without_privileges() { $response = $this->send( @@ -212,7 +213,7 @@ class TagMentionsTest extends TestCase $this->assertCount(0, CommentPost::find($response['data']['id'])->mentionsTags); } - /** @test */ + #[Test] public function mentioning_a_restricted_tag_works_with_privileges() { $response = $this->send( @@ -241,7 +242,7 @@ class TagMentionsTest extends TestCase $this->assertCount(1, CommentPost::find($response['data']['id'])->mentionsTags); } - /** @test */ + #[Test] public function mentioning_multiple_tags_works() { $response = $this->send( @@ -273,7 +274,7 @@ class TagMentionsTest extends TestCase $this->assertCount(4, CommentPost::find($response['data']['id'])->mentionsTags); } - /** @test */ + #[Test] public function tag_mentions_render_with_fresh_data() { $response = $this->send( @@ -291,7 +292,7 @@ class TagMentionsTest extends TestCase $this->assertCount(1, CommentPost::find($response['data']['id'])->mentionsTags); } - /** @test */ + #[Test] public function tag_mentions_dont_cause_errors_when_tags_disabled() { $this->extensions = ['flarum-mentions']; @@ -305,7 +306,7 @@ class TagMentionsTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** @test */ + #[Test] public function tag_mentions_unparse_with_fresh_data() { $response = $this->send( @@ -322,7 +323,7 @@ class TagMentionsTest extends TestCase $this->assertCount(1, CommentPost::find($response['data']['id'])->mentionsTags); } - /** @test */ + #[Test] public function deleted_tag_mentions_unparse_and_render_as_expected() { // No reason to hide a deleted tag's name. @@ -345,7 +346,7 @@ class TagMentionsTest extends TestCase $this->assertCount(0, CommentPost::find($response['data']['id'])->mentionsTags); } - /** @test */ + #[Test] public function deleted_tag_mentions_relation_unparse_and_render_as_expected() { // No reason to hide a deleted tag's name. @@ -368,7 +369,7 @@ class TagMentionsTest extends TestCase $this->assertCount(0, CommentPost::find($response['data']['id'])->mentionsTags); } - /** @test */ + #[Test] public function editing_a_post_that_has_a_tag_mention_works() { $response = $this->send( diff --git a/extensions/mentions/tests/integration/api/UserMentionsTest.php b/extensions/mentions/tests/integration/api/UserMentionsTest.php index 726b0c21f..962eb59df 100644 --- a/extensions/mentions/tests/integration/api/UserMentionsTest.php +++ b/extensions/mentions/tests/integration/api/UserMentionsTest.php @@ -18,6 +18,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\DisplayName\DriverInterface; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class UserMentionsTest extends TestCase { @@ -63,9 +64,7 @@ class UserMentionsTest extends TestCase ); } - /** - * @test - */ + #[Test] public function mentioning_a_valid_user_with_old_format_doesnt_work_if_off() { $this->setting('flarum-mentions.allow_username_format', '0'); @@ -97,9 +96,7 @@ class UserMentionsTest extends TestCase $this->assertCount(0, CommentPost::find($response['data']['id'])->mentionsUsers); } - /** - * @test - */ + #[Test] public function mentioning_a_valid_user_with_old_format_works_if_on() { $this->setting('flarum-mentions.allow_username_format', '1'); @@ -131,9 +128,7 @@ class UserMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsUsers->find(3)); } - /** - * @test - */ + #[Test] public function mentioning_a_valid_user_with_new_format_works() { $response = $this->send( @@ -163,9 +158,7 @@ class UserMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsUsers->find(3)); } - /** - * @test - */ + #[Test] public function mentioning_a_valid_user_with_new_format_with_smart_quotes_works_and_falls_back_to_normal_quotes() { $response = $this->send( @@ -195,9 +188,7 @@ class UserMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsUsers->find(3)); } - /** - * @test - */ + #[Test] public function mentioning_an_invalid_user_doesnt_work() { $response = $this->send( @@ -227,9 +218,7 @@ class UserMentionsTest extends TestCase $this->assertCount(0, CommentPost::find($response['data']['id'])->mentionsUsers); } - /** - * @test - */ + #[Test] public function mentioning_multiple_users_works() { $response = $this->send( @@ -261,9 +250,7 @@ class UserMentionsTest extends TestCase $this->assertCount(2, CommentPost::find($response['data']['id'])->mentionsUsers); } - /** - * @test - */ + #[Test] public function old_user_mentions_still_render() { $response = $this->send( @@ -281,9 +268,7 @@ class UserMentionsTest extends TestCase $this->assertCount(1, CommentPost::find($response['data']['id'])->mentionsUsers); } - /** - * @test - */ + #[Test] public function user_mentions_render_with_fresh_data() { $response = $this->send( @@ -312,9 +297,7 @@ class UserMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsUsers->find(3)); } - /** - * @test - */ + #[Test] public function user_mentions_unparse_with_fresh_data() { $response = $this->send( @@ -342,9 +325,7 @@ class UserMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsUsers->find(3)); } - /** - * @test - */ + #[Test] public function deleted_user_mentions_unparse_and_render_without_user_data() { $deleted_text = $this->app()->getContainer()->make('translator')->trans('core.lib.username.deleted_text'); @@ -368,9 +349,7 @@ class UserMentionsTest extends TestCase $this->assertCount(0, CommentPost::find($response['data']['id'])->mentionsUsers); } - /** - * @test - */ + #[Test] public function user_mentions_with_unremoved_bad_string_from_display_names_doesnt_work() { $response = $this->send( @@ -400,9 +379,7 @@ class UserMentionsTest extends TestCase $this->assertNull(CommentPost::find($response['data']['id'])->mentionsUsers->find(5)); } - /** - * @test - */ + #[Test] public function user_mentions_unparsing_removes_bad_display_name_string() { $response = $this->send( @@ -421,9 +398,7 @@ class UserMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsUsers->find(5)); } - /** - * @test - */ + #[Test] public function user_mentions_with_removed_bad_string_from_display_names_works() { $response = $this->send( @@ -453,9 +428,7 @@ class UserMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsUsers->find(5)); } - /** - * @test - */ + #[Test] public function editing_a_post_that_has_a_mention_works() { $response = $this->send( @@ -482,9 +455,7 @@ class UserMentionsTest extends TestCase $this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsUsers->find(5)); } - /** - * @test - */ + #[Test] public function editing_a_post_with_deleted_author_that_has_a_mention_works() { $response = $this->send( diff --git a/extensions/mentions/tests/phpunit.integration.xml b/extensions/mentions/tests/phpunit.integration.xml index 7319d929a..e3e14eab9 100644 --- a/extensions/mentions/tests/phpunit.integration.xml +++ b/extensions/mentions/tests/phpunit.integration.xml @@ -1,22 +1,20 @@ - + ../src/ - + ./integration diff --git a/extensions/mentions/tests/phpunit.unit.xml b/extensions/mentions/tests/phpunit.unit.xml index 66262dd9f..67367a782 100644 --- a/extensions/mentions/tests/phpunit.unit.xml +++ b/extensions/mentions/tests/phpunit.unit.xml @@ -1,28 +1,23 @@ - + ../src/ - + ./unit - - - diff --git a/extensions/nicknames/.gitignore b/extensions/nicknames/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/nicknames/.gitignore +++ b/extensions/nicknames/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/nicknames/tests/integration/api/EditUserTest.php b/extensions/nicknames/tests/integration/api/EditUserTest.php index 8b92949eb..65156c0c6 100644 --- a/extensions/nicknames/tests/integration/api/EditUserTest.php +++ b/extensions/nicknames/tests/integration/api/EditUserTest.php @@ -14,8 +14,9 @@ use Flarum\Locale\TranslatorInterface; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; -class UpdateTest extends TestCase +class EditUserTest extends TestCase { use RetrievesAuthorizedUsers; @@ -34,9 +35,7 @@ class UpdateTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function user_cant_edit_own_nickname_if_not_allowed() { $this->database()->table('group_permission')->where('permission', 'user.editOwnNickname')->where('group_id', Group::MEMBER_ID)->delete(); @@ -58,9 +57,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode(), $response->getBody()->getContents()); } - /** - * @test - */ + #[Test] public function user_can_edit_own_nickname_if_allowed() { $this->prepareDatabase([ @@ -88,9 +85,7 @@ class UpdateTest extends TestCase $this->assertEquals('new nickname', User::find(2)->nickname); } - /** - * @test - */ + #[Test] public function cant_edit_nickname_if_invalid_regex() { $this->setting('flarum-nicknames.set_on_registration', true); diff --git a/extensions/nicknames/tests/integration/api/RegisterTest.php b/extensions/nicknames/tests/integration/api/RegisterTest.php index fbf411e46..025e56c3c 100644 --- a/extensions/nicknames/tests/integration/api/RegisterTest.php +++ b/extensions/nicknames/tests/integration/api/RegisterTest.php @@ -12,6 +12,7 @@ namespace Flarum\Nicknames\Tests\integration; use Flarum\Extend; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class RegisterTest extends TestCase { @@ -26,9 +27,7 @@ class RegisterTest extends TestCase ); } - /** - * @test - */ + #[Test] public function can_register_with_nickname() { $this->setting('flarum-nicknames.set_on_registration', true); @@ -54,9 +53,7 @@ class RegisterTest extends TestCase $this->assertEquals('test@machine.local', $user->email); } - /** - * @test - */ + #[Test] public function cant_register_with_nickname_if_not_allowed() { $this->setting('flarum-nicknames.set_on_registration', false); @@ -75,9 +72,7 @@ class RegisterTest extends TestCase $this->assertEquals(403, $response->getStatusCode(), $response->getBody()->getContents()); } - /** - * @test - */ + #[Test] public function cant_register_with_nickname_if_invalid_regex() { $this->setting('flarum-nicknames.set_on_registration', true); @@ -97,9 +92,7 @@ class RegisterTest extends TestCase $this->assertEquals(422, $response->getStatusCode(), $response->getBody()->getContents()); } - /** - * @test - */ + #[Test] public function can_register_with_nickname_if_valid_regex() { $this->setting('flarum-nicknames.set_on_registration', true); diff --git a/extensions/nicknames/tests/phpunit.integration.xml b/extensions/nicknames/tests/phpunit.integration.xml index 7319d929a..e3e14eab9 100644 --- a/extensions/nicknames/tests/phpunit.integration.xml +++ b/extensions/nicknames/tests/phpunit.integration.xml @@ -1,22 +1,20 @@ - + ../src/ - + ./integration diff --git a/extensions/nicknames/tests/phpunit.unit.xml b/extensions/nicknames/tests/phpunit.unit.xml index 66262dd9f..67367a782 100644 --- a/extensions/nicknames/tests/phpunit.unit.xml +++ b/extensions/nicknames/tests/phpunit.unit.xml @@ -1,28 +1,23 @@ - + ../src/ - + ./unit - - - diff --git a/extensions/package-manager/.gitignore b/extensions/package-manager/.gitignore index 4ebb168a0..e60e51206 100755 --- a/extensions/package-manager/.gitignore +++ b/extensions/package-manager/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/package-manager/tests/integration/api/CheckForUpdatesTest.php b/extensions/package-manager/tests/integration/api/CheckForUpdatesTest.php index 28778e87f..e27dfd47b 100644 --- a/extensions/package-manager/tests/integration/api/CheckForUpdatesTest.php +++ b/extensions/package-manager/tests/integration/api/CheckForUpdatesTest.php @@ -13,15 +13,14 @@ use Flarum\ExtensionManager\Tests\integration\ChangeComposerConfig; use Flarum\ExtensionManager\Tests\integration\RefreshComposerSetup; use Flarum\ExtensionManager\Tests\integration\TestCase; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class CheckForUpdatesTest extends TestCase { use RefreshComposerSetup; use ChangeComposerConfig; - /** - * @test - */ + #[Test] public function can_check_for_updates() { $this->setComposerConfig([ diff --git a/extensions/package-manager/tests/integration/api/GlobalUpdateTest.php b/extensions/package-manager/tests/integration/api/GlobalUpdateTest.php index 28e8a69da..1ab87112f 100644 --- a/extensions/package-manager/tests/integration/api/GlobalUpdateTest.php +++ b/extensions/package-manager/tests/integration/api/GlobalUpdateTest.php @@ -11,14 +11,13 @@ namespace Flarum\ExtensionManager\Tests\integration\api; use Flarum\ExtensionManager\Tests\integration\RefreshComposerSetup; use Flarum\ExtensionManager\Tests\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class GlobalUpdateTest extends TestCase { use RefreshComposerSetup; - /** - * @test - */ + #[Test] public function can_global_update() { $response = $this->send( diff --git a/extensions/package-manager/tests/integration/api/MajorUpdateTest.php b/extensions/package-manager/tests/integration/api/MajorUpdateTest.php index f9d19c6ac..7cce2c5d7 100644 --- a/extensions/package-manager/tests/integration/api/MajorUpdateTest.php +++ b/extensions/package-manager/tests/integration/api/MajorUpdateTest.php @@ -13,6 +13,7 @@ use Flarum\ExtensionManager\Tests\integration\ChangeComposerConfig; use Flarum\ExtensionManager\Tests\integration\DummyExtensions; use Flarum\ExtensionManager\Tests\integration\RefreshComposerSetup; use Flarum\ExtensionManager\Tests\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class MajorUpdateTest extends TestCase { @@ -20,9 +21,7 @@ class MajorUpdateTest extends TestCase use ChangeComposerConfig; use DummyExtensions; - /** - * @test - */ + #[Test] public function cannot_update_when_no_update_check_ran() { $this->makeDummyExtensionCompatibleWith('flarum/dummy-incompatible-extension', '>=0.1.0-beta.15 <=0.1.0-beta.16'); @@ -45,9 +44,7 @@ class MajorUpdateTest extends TestCase $this->assertEquals('no_new_major_version', $this->errorDetails($response)['code']); } - /** - * @test - */ + #[Test] public function can_update_when_major_update_available() { $this->makeDummyExtensionCompatibleWith('flarum/dummy-compatible-extension', '^0.1.0-beta.15 | ^1.0.0'); @@ -87,9 +84,7 @@ class MajorUpdateTest extends TestCase $this->assertPackageVersion('flarum/dummy-compatible-extension', '*'); } - /** - * @test - */ + #[Test] public function cannot_update_with_incompatible_extensions() { $this->makeDummyExtensionCompatibleWith('flarum/dummy-incompatible-extension-a', '>=0.1.0-beta.16 <0.1.0-beta.17'); diff --git a/extensions/package-manager/tests/integration/api/MinorUpdateTest.php b/extensions/package-manager/tests/integration/api/MinorUpdateTest.php index 6ebdacb61..3cf9ddd34 100644 --- a/extensions/package-manager/tests/integration/api/MinorUpdateTest.php +++ b/extensions/package-manager/tests/integration/api/MinorUpdateTest.php @@ -15,6 +15,7 @@ use Flarum\ExtensionManager\Tests\integration\ChangeComposerConfig; use Flarum\ExtensionManager\Tests\integration\DummyExtensions; use Flarum\ExtensionManager\Tests\integration\RefreshComposerSetup; use Flarum\ExtensionManager\Tests\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class MinorUpdateTest extends TestCase { @@ -22,9 +23,7 @@ class MinorUpdateTest extends TestCase use ChangeComposerConfig; use DummyExtensions; - /** - * @test - */ + #[Test] public function can_update_to_next_minor_version() { $this->makeDummyExtensionCompatibleWith('flarum/dummy-compatible-extension', '^1.0.0'); @@ -53,9 +52,7 @@ class MinorUpdateTest extends TestCase $this->assertPackageVersion('flarum/dummy-compatible-extension', '*'); } - /** - * @test - */ + #[Test] public function can_update_with_latest_ext_incompatible_with_latest_core() { $this->makeDummyExtensionCompatibleWith('flarum/dummy-extension', '1.0.0'); diff --git a/extensions/package-manager/tests/integration/api/extensions/RemoveExtensionTest.php b/extensions/package-manager/tests/integration/api/extensions/RemoveExtensionTest.php index 25ac2eddf..07a3b7709 100644 --- a/extensions/package-manager/tests/integration/api/extensions/RemoveExtensionTest.php +++ b/extensions/package-manager/tests/integration/api/extensions/RemoveExtensionTest.php @@ -11,22 +11,19 @@ namespace Flarum\ExtensionManager\Tests\integration\api\extensions; use Flarum\ExtensionManager\Tests\integration\RefreshComposerSetup; use Flarum\ExtensionManager\Tests\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class RemoveExtensionTest extends TestCase { use RefreshComposerSetup; - /** - * @test - */ + #[Test] public function extension_installed_by_default() { $this->assertExtensionExists('flarum-tags'); } - /** - * @test - */ + #[Test] public function removing_an_extension_works() { $response = $this->send( @@ -39,9 +36,7 @@ class RemoveExtensionTest extends TestCase $this->assertExtensionNotExists('flarum-tags'); } - /** - * @test - */ + #[Test] public function removing_a_non_existant_extension_fails() { $response = $this->send( diff --git a/extensions/package-manager/tests/integration/api/extensions/RequireExtensionTest.php b/extensions/package-manager/tests/integration/api/extensions/RequireExtensionTest.php index e9979b9d3..4ca128ae1 100644 --- a/extensions/package-manager/tests/integration/api/extensions/RequireExtensionTest.php +++ b/extensions/package-manager/tests/integration/api/extensions/RequireExtensionTest.php @@ -11,22 +11,19 @@ namespace Flarum\ExtensionManager\Tests\integration\api\extensions; use Flarum\ExtensionManager\Tests\integration\RefreshComposerSetup; use Flarum\ExtensionManager\Tests\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class RequireExtensionTest extends TestCase { use RefreshComposerSetup; - /** - * @test - */ + #[Test] public function extension_uninstalled_by_default() { $this->assertExtensionNotExists('v17development-blog'); } - /** - * @test - */ + #[Test] public function requiring_an_existing_extension_fails() { $response = $this->send( @@ -43,9 +40,7 @@ class RequireExtensionTest extends TestCase $this->assertEquals(409, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function requiring_a_compatible_extension_works() { $response = $this->send( @@ -63,9 +58,7 @@ class RequireExtensionTest extends TestCase $this->assertExtensionExists('v17development-blog'); } - /** - * @test - */ + #[Test] public function requiring_a_compatible_extension_with_specific_version_works() { $response = $this->send( @@ -83,9 +76,7 @@ class RequireExtensionTest extends TestCase $this->assertExtensionExists('v17development-blog'); } - /** - * @test - */ + #[Test] public function requiring_an_uncompatible_extension_fails() { $response = $this->send( @@ -103,9 +94,7 @@ class RequireExtensionTest extends TestCase $this->assertEquals('extension_incompatible_with_instance', $this->errorDetails($response)['guessed_cause']); } - /** - * @test - */ + #[Test] public function requiring_an_uncompatible_extension_with_specific_version_fails() { $response = $this->send( diff --git a/extensions/package-manager/tests/integration/api/extensions/UpdateExtensionTest.php b/extensions/package-manager/tests/integration/api/extensions/UpdateExtensionTest.php index 3ca3f3a58..dd14f5c95 100644 --- a/extensions/package-manager/tests/integration/api/extensions/UpdateExtensionTest.php +++ b/extensions/package-manager/tests/integration/api/extensions/UpdateExtensionTest.php @@ -11,22 +11,19 @@ namespace Flarum\ExtensionManager\Tests\integration\api\extensions; use Flarum\ExtensionManager\Tests\integration\RefreshComposerSetup; use Flarum\ExtensionManager\Tests\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class UpdateExtensionTest extends TestCase { use RefreshComposerSetup; - /** - * @test - */ + #[Test] public function extension_installed_by_default() { $this->assertExtensionExists('flarum-tags'); } - /** - * @test - */ + #[Test] public function updating_an_existing_extension_works() { $response = $this->send( @@ -39,9 +36,7 @@ class UpdateExtensionTest extends TestCase $this->assertExtensionExists('flarum-tags'); } - /** - * @test - */ + #[Test] public function updating_a_non_existing_extension_fails() { $response = $this->send( diff --git a/extensions/package-manager/tests/phpunit.integration.xml b/extensions/package-manager/tests/phpunit.integration.xml index 89f91a4d1..b637aadab 100644 --- a/extensions/package-manager/tests/phpunit.integration.xml +++ b/extensions/package-manager/tests/phpunit.integration.xml @@ -1,21 +1,19 @@ - + ../src/ - + ./integration diff --git a/extensions/package-manager/tests/phpunit.unit.xml b/extensions/package-manager/tests/phpunit.unit.xml index d3a4a3e3d..eb33f60fe 100644 --- a/extensions/package-manager/tests/phpunit.unit.xml +++ b/extensions/package-manager/tests/phpunit.unit.xml @@ -1,27 +1,22 @@ - + ../src/ - + ./unit - - - diff --git a/extensions/pusher/.gitignore b/extensions/pusher/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/pusher/.gitignore +++ b/extensions/pusher/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/statistics/.gitignore b/extensions/statistics/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/statistics/.gitignore +++ b/extensions/statistics/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/statistics/tests/integration/api/CanRequestCustomTimedStatisticsTest.php b/extensions/statistics/tests/integration/api/CanRequestCustomTimedStatisticsTest.php index adf5a89b0..c03f18e26 100644 --- a/extensions/statistics/tests/integration/api/CanRequestCustomTimedStatisticsTest.php +++ b/extensions/statistics/tests/integration/api/CanRequestCustomTimedStatisticsTest.php @@ -15,6 +15,7 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class CanRequestCustomTimedStatisticsTest extends TestCase { @@ -60,9 +61,7 @@ class CanRequestCustomTimedStatisticsTest extends TestCase ]; } - /** - * @test - */ + #[Test] public function can_request_timed_stats() { $time = $this->nowTime->copy(); diff --git a/extensions/statistics/tests/integration/api/CanRequestLifetimeStatisticsTest.php b/extensions/statistics/tests/integration/api/CanRequestLifetimeStatisticsTest.php index 3b6967595..645e38baf 100644 --- a/extensions/statistics/tests/integration/api/CanRequestLifetimeStatisticsTest.php +++ b/extensions/statistics/tests/integration/api/CanRequestLifetimeStatisticsTest.php @@ -15,6 +15,7 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class CanRequestLifetimeStatisticsTest extends TestCase { @@ -59,9 +60,7 @@ class CanRequestLifetimeStatisticsTest extends TestCase ]; } - /** - * @test - */ + #[Test] public function can_request_lifetime_stats() { $response = $this->send( diff --git a/extensions/statistics/tests/integration/api/CanRequestTimedStatisticsTest.php b/extensions/statistics/tests/integration/api/CanRequestTimedStatisticsTest.php index 4e82c84a6..6abd802eb 100644 --- a/extensions/statistics/tests/integration/api/CanRequestTimedStatisticsTest.php +++ b/extensions/statistics/tests/integration/api/CanRequestTimedStatisticsTest.php @@ -15,6 +15,7 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class CanRequestTimedStatisticsTest extends TestCase { @@ -59,9 +60,7 @@ class CanRequestTimedStatisticsTest extends TestCase ]; } - /** - * @test - */ + #[Test] public function can_request_timed_stats() { $time = $this->nowTime->copy(); diff --git a/extensions/statistics/tests/phpunit.integration.xml b/extensions/statistics/tests/phpunit.integration.xml index 7319d929a..e3e14eab9 100644 --- a/extensions/statistics/tests/phpunit.integration.xml +++ b/extensions/statistics/tests/phpunit.integration.xml @@ -1,22 +1,20 @@ - + ../src/ - + ./integration diff --git a/extensions/statistics/tests/phpunit.unit.xml b/extensions/statistics/tests/phpunit.unit.xml index 66262dd9f..67367a782 100644 --- a/extensions/statistics/tests/phpunit.unit.xml +++ b/extensions/statistics/tests/phpunit.unit.xml @@ -1,28 +1,23 @@ - + ../src/ - + ./unit - - - diff --git a/extensions/sticky/.gitignore b/extensions/sticky/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/sticky/.gitignore +++ b/extensions/sticky/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/sticky/tests/integration/api/ListDiscussionsTest.php b/extensions/sticky/tests/integration/api/ListDiscussionsTest.php index de1b15cc2..b8518f41e 100644 --- a/extensions/sticky/tests/integration/api/ListDiscussionsTest.php +++ b/extensions/sticky/tests/integration/api/ListDiscussionsTest.php @@ -16,6 +16,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class ListDiscussionsTest extends TestCase { @@ -55,7 +56,7 @@ class ListDiscussionsTest extends TestCase ]); } - /** @test */ + #[Test] public function list_discussions_shows_sticky_first_as_guest() { $response = $this->send( @@ -71,7 +72,7 @@ class ListDiscussionsTest extends TestCase $this->assertEquals([3, 1, 2, 4], Arr::pluck($data['data'], 'id')); } - /** @test */ + #[Test] public function list_discussions_shows_sticky_unread_first_as_user() { $response = $this->send( @@ -87,7 +88,7 @@ class ListDiscussionsTest extends TestCase $this->assertEqualsCanonicalizing([3, 1, 2, 4], Arr::pluck($data['data'], 'id')); } - /** @test */ + #[Test] public function list_discussions_shows_normal_order_when_all_read_as_user() { $response = $this->send( @@ -103,7 +104,7 @@ class ListDiscussionsTest extends TestCase $this->assertEqualsCanonicalizing([2, 4, 3, 1], Arr::pluck($data['data'], 'id')); } - /** @test */ + #[Test] public function list_discussions_shows_stick_first_on_a_tag() { $response = $this->send( diff --git a/extensions/sticky/tests/integration/api/StickyDiscussionsTest.php b/extensions/sticky/tests/integration/api/StickyDiscussionsTest.php index ec835c624..2c61768d5 100644 --- a/extensions/sticky/tests/integration/api/StickyDiscussionsTest.php +++ b/extensions/sticky/tests/integration/api/StickyDiscussionsTest.php @@ -16,6 +16,8 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class StickyDiscussionsTest extends TestCase { @@ -57,10 +59,8 @@ class StickyDiscussionsTest extends TestCase ]); } - /** - * @dataProvider stickyDataProvider - * @test - */ + #[Test] + #[DataProvider('stickyDataProvider')] public function can_sticky_if_allowed(int $actorId, bool $allowed, bool $sticky) { $response = $this->send( diff --git a/extensions/sticky/tests/phpunit.integration.xml b/extensions/sticky/tests/phpunit.integration.xml index 7319d929a..e3e14eab9 100644 --- a/extensions/sticky/tests/phpunit.integration.xml +++ b/extensions/sticky/tests/phpunit.integration.xml @@ -1,22 +1,20 @@ - + ../src/ - + ./integration diff --git a/extensions/sticky/tests/phpunit.unit.xml b/extensions/sticky/tests/phpunit.unit.xml index 66262dd9f..67367a782 100644 --- a/extensions/sticky/tests/phpunit.unit.xml +++ b/extensions/sticky/tests/phpunit.unit.xml @@ -1,28 +1,23 @@ - + ../src/ - + ./unit - - - diff --git a/extensions/subscriptions/.gitignore b/extensions/subscriptions/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/subscriptions/.gitignore +++ b/extensions/subscriptions/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/subscriptions/tests/integration/api/discussions/ReplyNotificationTest.php b/extensions/subscriptions/tests/integration/api/discussions/ReplyNotificationTest.php index 81423546a..1e639e283 100644 --- a/extensions/subscriptions/tests/integration/api/discussions/ReplyNotificationTest.php +++ b/extensions/subscriptions/tests/integration/api/discussions/ReplyNotificationTest.php @@ -17,6 +17,8 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class ReplyNotificationTest extends TestCase { @@ -62,10 +64,8 @@ class ReplyNotificationTest extends TestCase ]); } - /** - * @dataProvider replyingSendsNotificationsDataProvider - * @test - */ + #[Test] + #[DataProvider('replyingSendsNotificationsDataProvider')] public function replying_to_a_discussion_with_comment_post_as_last_post_sends_reply_notification(int $userId, int $discussionId, int $newNotificationCount) { $this->app(); @@ -96,7 +96,7 @@ class ReplyNotificationTest extends TestCase $this->assertEquals($newNotificationCount, $mainUser->getUnreadNotificationCount()); } - public function replyingSendsNotificationsDataProvider(): array + public static function replyingSendsNotificationsDataProvider(): array { return [ 'admin receives a notification when another replies to a discussion they are following and caught up to' => [1, 1, 1], @@ -106,7 +106,7 @@ class ReplyNotificationTest extends TestCase ]; } - /** @test */ + #[Test] public function replying_to_a_discussion_with_event_post_as_last_post_sends_reply_notification() { $this->app(); @@ -166,10 +166,8 @@ class ReplyNotificationTest extends TestCase $this->assertEquals(1, $mainUser->getUnreadNotificationCount()); } - /** - * @dataProvider deleteLastPostsProvider - * @test - */ + #[Test] + #[DataProvider('deleteLastPostsProvider')] public function deleting_last_posts_then_posting_new_one_sends_reply_notification(array $postIds) { $this->prepareDatabase([ @@ -222,7 +220,7 @@ class ReplyNotificationTest extends TestCase $this->assertEquals(1, $mainUser->getUnreadNotificationCount()); } - public function deleteLastPostsProvider(): array + public static function deleteLastPostsProvider(): array { return [ [[10, 9, 8]], @@ -230,7 +228,7 @@ class ReplyNotificationTest extends TestCase ]; } - /** @test */ + #[Test] public function approving_reply_sends_reply_notification() { // Flags was only specified because it is required for approval. @@ -288,7 +286,7 @@ class ReplyNotificationTest extends TestCase $this->assertEquals(1, $mainUser->getUnreadNotificationCount()); } - /** @test */ + #[Test] public function replying_to_a_discussion_with_a_restricted_post_only_sends_notifications_to_allowed_users() { // Add visibility scoper to only allow admin diff --git a/extensions/subscriptions/tests/integration/api/discussions/SubscribeTest.php b/extensions/subscriptions/tests/integration/api/discussions/SubscribeTest.php index b592ed7e9..233441507 100644 --- a/extensions/subscriptions/tests/integration/api/discussions/SubscribeTest.php +++ b/extensions/subscriptions/tests/integration/api/discussions/SubscribeTest.php @@ -15,6 +15,8 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class SubscribeTest extends TestCase { @@ -60,10 +62,8 @@ class SubscribeTest extends TestCase ]); } - /** - * @test - * @dataProvider provideStates - */ + #[Test] + #[DataProvider('provideStates')] public function can_subscribe_to_a_discussion(int $actorId, int $discussionId, ?string $newState) { $this->app(); diff --git a/extensions/subscriptions/tests/phpunit.integration.xml b/extensions/subscriptions/tests/phpunit.integration.xml index 7319d929a..e3e14eab9 100644 --- a/extensions/subscriptions/tests/phpunit.integration.xml +++ b/extensions/subscriptions/tests/phpunit.integration.xml @@ -1,22 +1,20 @@ - + ../src/ - + ./integration diff --git a/extensions/subscriptions/tests/phpunit.unit.xml b/extensions/subscriptions/tests/phpunit.unit.xml index 66262dd9f..67367a782 100644 --- a/extensions/subscriptions/tests/phpunit.unit.xml +++ b/extensions/subscriptions/tests/phpunit.unit.xml @@ -1,28 +1,23 @@ - + ../src/ - + ./unit - - - diff --git a/extensions/suspend/.gitignore b/extensions/suspend/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/suspend/.gitignore +++ b/extensions/suspend/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/suspend/tests/integration/api/UseForumTest.php b/extensions/suspend/tests/integration/api/UseForumTest.php index f640b4a39..9270baa70 100644 --- a/extensions/suspend/tests/integration/api/UseForumTest.php +++ b/extensions/suspend/tests/integration/api/UseForumTest.php @@ -15,6 +15,7 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class UseForumTest extends TestCase { @@ -40,7 +41,7 @@ class UseForumTest extends TestCase ]); } - /** @test */ + #[Test] public function suspended_user_cannot_create_discussions() { $response = $this->send( @@ -61,7 +62,7 @@ class UseForumTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** @test */ + #[Test] public function suspended_user_cannot_reply_to_discussions() { $response = $this->send( diff --git a/extensions/suspend/tests/integration/api/users/ListUsersTest.php b/extensions/suspend/tests/integration/api/users/ListUsersTest.php index 5b6a7340f..dd007ea54 100644 --- a/extensions/suspend/tests/integration/api/users/ListUsersTest.php +++ b/extensions/suspend/tests/integration/api/users/ListUsersTest.php @@ -14,6 +14,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class ListUsersTest extends TestCase { @@ -55,7 +56,7 @@ class ListUsersTest extends TestCase $this->assertEqualsCanonicalizing([1, 2, 3, 4, 5, 6], Arr::pluck($body['data'], 'id')); } - /** @test */ + #[Test] public function can_filter_users_by_suspension() { $response = $this->send( diff --git a/extensions/suspend/tests/integration/api/users/SuspendUserTest.php b/extensions/suspend/tests/integration/api/users/SuspendUserTest.php index 92eff1d5d..10b12d17e 100644 --- a/extensions/suspend/tests/integration/api/users/SuspendUserTest.php +++ b/extensions/suspend/tests/integration/api/users/SuspendUserTest.php @@ -14,6 +14,8 @@ use Flarum\Group\Group; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Psr\Http\Message\ResponseInterface; class SuspendUserTest extends TestCase @@ -44,10 +46,8 @@ class SuspendUserTest extends TestCase ]); } - /** - * @dataProvider allowedToSuspendUser - * @test - */ + #[Test] + #[DataProvider('allowedToSuspendUser')] public function can_suspend_user_if_allowed(?int $authenticatedAs, int $targetUserId, string $message) { $response = $this->sendSuspensionRequest($authenticatedAs, $targetUserId); @@ -55,10 +55,8 @@ class SuspendUserTest extends TestCase $this->assertEquals(200, $response->getStatusCode(), $response->getBody()->getContents()); } - /** - * @dataProvider unallowedToSuspendUser - * @test - */ + #[Test] + #[DataProvider('unallowedToSuspendUser')] public function cannot_suspend_user_if_not_allowed(?int $authenticatedAs, int $targetUserId, string $message) { $response = $this->sendSuspensionRequest($authenticatedAs, $targetUserId); @@ -66,7 +64,7 @@ class SuspendUserTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - public function allowedToSuspendUser(): array + public static function allowedToSuspendUser(): array { return [ [1, 2, 'Admin can suspend any user'], @@ -75,7 +73,7 @@ class SuspendUserTest extends TestCase ]; } - public function unallowedToSuspendUser(): array + public static function unallowedToSuspendUser(): array { return [ [1, 1, 'Admin cannot suspend self'], diff --git a/extensions/suspend/tests/phpunit.integration.xml b/extensions/suspend/tests/phpunit.integration.xml index 7319d929a..e3e14eab9 100644 --- a/extensions/suspend/tests/phpunit.integration.xml +++ b/extensions/suspend/tests/phpunit.integration.xml @@ -1,22 +1,20 @@ - + ../src/ - + ./integration diff --git a/extensions/suspend/tests/phpunit.unit.xml b/extensions/suspend/tests/phpunit.unit.xml index 66262dd9f..67367a782 100644 --- a/extensions/suspend/tests/phpunit.unit.xml +++ b/extensions/suspend/tests/phpunit.unit.xml @@ -1,28 +1,23 @@ - + ../src/ - + ./unit - - - diff --git a/extensions/tags/.gitignore b/extensions/tags/.gitignore index 4ebb168a0..e60e51206 100644 --- a/extensions/tags/.gitignore +++ b/extensions/tags/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/extensions/tags/src/Access/DiscussionPolicy.php b/extensions/tags/src/Access/DiscussionPolicy.php index 3790782e9..742632cae 100755 --- a/extensions/tags/src/Access/DiscussionPolicy.php +++ b/extensions/tags/src/Access/DiscussionPolicy.php @@ -62,7 +62,7 @@ class DiscussionPolicy extends AbstractPolicy if ( $allowEditTags === '-1' || ($allowEditTags === 'reply' && $discussion->participant_count <= 1) - || (is_numeric($allowEditTags) && $discussion->created_at->diffInMinutes(new Carbon) < $allowEditTags) + || (is_numeric($allowEditTags) && $discussion->created_at->diffInMinutes(new Carbon, true) < $allowEditTags) ) { return $this->allow(); } diff --git a/extensions/tags/tests/integration/api/discussions/CreateTest.php b/extensions/tags/tests/integration/api/discussions/CreateTest.php index 19d24b3f0..edeaf3a61 100644 --- a/extensions/tags/tests/integration/api/discussions/CreateTest.php +++ b/extensions/tags/tests/integration/api/discussions/CreateTest.php @@ -15,6 +15,7 @@ use Flarum\Tags\Tests\integration\RetrievesRepresentativeTags; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class CreateTest extends TestCase { @@ -45,9 +46,7 @@ class CreateTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function admin_can_create_discussion_without_tags() { $response = $this->send( @@ -68,9 +67,7 @@ class CreateTest extends TestCase $this->assertEquals(201, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_cant_create_discussion_without_tags() { $response = $this->send( @@ -113,9 +110,7 @@ class CreateTest extends TestCase $this->assertEquals(422, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_can_create_discussion_without_tags_if_bypass_permission_granted() { $this->prepareDatabase([ @@ -142,9 +137,7 @@ class CreateTest extends TestCase $this->assertEquals(201, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_can_create_discussion_in_primary_tag() { $response = $this->send( @@ -172,9 +165,7 @@ class CreateTest extends TestCase $this->assertEquals(201, $response->getStatusCode(), (string) $response->getBody()); } - /** - * @test - */ + #[Test] public function user_cant_create_discussion_in_primary_tag_where_can_view_but_cant_start() { $response = $this->send( @@ -202,9 +193,7 @@ class CreateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_cant_create_discussion_in_primary_tag_where_can_view_but_cant_start_with_bypass_permission_granted() { $this->prepareDatabase([ @@ -238,9 +227,7 @@ class CreateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_can_create_discussion_in_tag_where_can_view_and_can_start() { $response = $this->send( @@ -269,9 +256,7 @@ class CreateTest extends TestCase $this->assertEquals(201, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_cant_create_discussion_in_child_tag_without_parent_tag() { $response = $this->send( @@ -299,9 +284,7 @@ class CreateTest extends TestCase $this->assertEquals(422, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_can_create_discussion_in_child_tag_with_parent_tag() { $response = $this->send( @@ -330,9 +313,7 @@ class CreateTest extends TestCase $this->assertEquals(201, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function primary_tag_required_by_default() { $response = $this->send( diff --git a/extensions/tags/tests/integration/api/discussions/ListTest.php b/extensions/tags/tests/integration/api/discussions/ListTest.php index 42b544d79..41d349651 100644 --- a/extensions/tags/tests/integration/api/discussions/ListTest.php +++ b/extensions/tags/tests/integration/api/discussions/ListTest.php @@ -18,6 +18,8 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class ListTest extends TestCase { @@ -110,9 +112,7 @@ class ListTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function admin_sees_all() { $response = $this->send( @@ -129,9 +129,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(['1', '2', '3', '4', '5', '6'], $ids); } - /** - * @test - */ + #[Test] public function user_sees_where_allowed() { $response = $this->send( @@ -148,9 +146,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(['1', '2', '3', '4'], $ids); } - /** - * @test - */ + #[Test] public function guest_can_see_where_allowed() { $response = $this->send( @@ -165,10 +161,8 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(['1', '2'], $ids); } - /** - * @dataProvider seeWhereAllowedWhenMoreTagsAreRequiredThanAvailableDataProvider - * @test - */ + #[Test] + #[DataProvider('seeWhereAllowedWhenMoreTagsAreRequiredThanAvailableDataProvider')] public function actor_can_see_where_allowed_when_more_tags_are_required_than_available(string $type, int $actorId, array $expectedDiscussions) { if ($type === 'secondary') { @@ -201,7 +195,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing($expectedDiscussions, $ids); } - public function seeWhereAllowedWhenMoreTagsAreRequiredThanAvailableDataProvider(): array + public static function seeWhereAllowedWhenMoreTagsAreRequiredThanAvailableDataProvider(): array { return [ // admin_can_see_where_allowed_when_more_primary_tags_are_required_than_available @@ -219,10 +213,8 @@ class ListTest extends TestCase ]; } - /** - * @dataProvider filterByTagsDataProvider - * @test - */ + #[Test] + #[DataProvider('filterByTagsDataProvider')] public function can_filter_by_authorized_tags(int $authenticatedAs, string $tags, array $expectedDiscussionIds) { $response = $this->send( @@ -242,7 +234,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing($expectedDiscussionIds, array_map('intval', $ids)); } - public function filterByTagsDataProvider(): array + public static function filterByTagsDataProvider(): array { return [ // Admin can filter by any tag. diff --git a/extensions/tags/tests/integration/api/discussions/UpdateTest.php b/extensions/tags/tests/integration/api/discussions/UpdateTest.php index bcdcd3d39..a6fb13b6b 100644 --- a/extensions/tags/tests/integration/api/discussions/UpdateTest.php +++ b/extensions/tags/tests/integration/api/discussions/UpdateTest.php @@ -18,6 +18,7 @@ use Flarum\Tags\Tests\integration\RetrievesRepresentativeTags; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class UpdateTest extends TestCase { @@ -57,9 +58,7 @@ class UpdateTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function user_cant_change_tags_without_setting() { $response = $this->send( @@ -82,9 +81,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_can_change_tags_without_setting() { $this->setting('allow_tag_change', '-1'); @@ -109,9 +106,7 @@ class UpdateTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function admin_can_add_primary_tag_beyond_limit() { $response = $this->send( @@ -135,9 +130,7 @@ class UpdateTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_cant_add_primary_tag_beyond_limit() { $this->setting('allow_tag_change', '-1'); @@ -163,9 +156,7 @@ class UpdateTest extends TestCase $this->assertEquals(422, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_cant_add_tag_where_can_view_but_cant_start() { $this->setting('allow_tag_change', '-1'); @@ -190,9 +181,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_can_add_tag_where_can_view_and_can_start() { $this->setting('allow_tag_change', '-1'); @@ -218,9 +207,7 @@ class UpdateTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_cant_add_child_tag_without_parent_tag() { $this->setting('allow_tag_change', '-1'); @@ -250,9 +237,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode(), $response->getBody()); } - /** - * @test - */ + #[Test] public function user_can_add_child_tag_with_parent_tag() { $this->setting('allow_tag_change', '-1'); @@ -278,9 +263,7 @@ class UpdateTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function primary_tag_required_by_default() { $this->setting('allow_tag_change', '-1'); diff --git a/extensions/tags/tests/integration/api/posts/ListTest.php b/extensions/tags/tests/integration/api/posts/ListTest.php index c0a4c0605..06ef56d45 100644 --- a/extensions/tags/tests/integration/api/posts/ListTest.php +++ b/extensions/tags/tests/integration/api/posts/ListTest.php @@ -17,6 +17,8 @@ use Flarum\Tags\Tests\integration\RetrievesRepresentativeTags; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class ListTest extends TestCase { @@ -74,10 +76,8 @@ class ListTest extends TestCase ]); } - /** - * @dataProvider authorizedUsers - * @test - */ + #[Test] + #[DataProvider('authorizedUsers')] public function event_mentioned_tags_are_included_in_response_for_authorized_users(int $userId) { $response = $this->send( @@ -101,10 +101,8 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing([1, 5], $tagIds, $body); } - /** - * @dataProvider unauthorizedUsers - * @test - */ + #[Test] + #[DataProvider('unauthorizedUsers')] public function event_mentioned_tags_are_not_included_in_response_for_unauthorized_users(?int $userId) { $response = $this->send( @@ -126,7 +124,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing([1], $tagIds); } - public function authorizedUsers() + public static function authorizedUsers() { return [ 'admin' => [1], @@ -134,7 +132,7 @@ class ListTest extends TestCase ]; } - public function unauthorizedUsers() + public static function unauthorizedUsers() { return [ 'normal user without permission' => [3], diff --git a/extensions/tags/tests/integration/api/tags/CreateTest.php b/extensions/tags/tests/integration/api/tags/CreateTest.php index 881f7d579..a8c67a45e 100644 --- a/extensions/tags/tests/integration/api/tags/CreateTest.php +++ b/extensions/tags/tests/integration/api/tags/CreateTest.php @@ -14,6 +14,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class CreateTest extends TestCase { @@ -35,9 +36,7 @@ class CreateTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function normal_user_cant_create_tag() { $response = $this->send( @@ -51,9 +50,7 @@ class CreateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function admin_cannot_create_tag_without_data() { $response = $this->send( @@ -68,9 +65,7 @@ class CreateTest extends TestCase $this->assertEquals(422, $response->getStatusCode(), (string) $response->getBody()); } - /** - * @test - */ + #[Test] public function admin_can_create_tag() { $response = $this->send( diff --git a/extensions/tags/tests/integration/api/tags/ListTest.php b/extensions/tags/tests/integration/api/tags/ListTest.php index ee813ae3d..ac937e686 100644 --- a/extensions/tags/tests/integration/api/tags/ListTest.php +++ b/extensions/tags/tests/integration/api/tags/ListTest.php @@ -16,6 +16,8 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class ListTest extends TestCase { @@ -43,9 +45,7 @@ class ListTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function admin_sees_all() { $response = $this->send( @@ -62,9 +62,7 @@ class ListTest extends TestCase $this->assertEquals(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14'], $ids); } - /** - * @test - */ + #[Test] public function user_sees_where_allowed() { $response = $this->send( @@ -84,10 +82,8 @@ class ListTest extends TestCase $this->assertEquals(['1', '2', '3', '4', '9', '10', '11'], $ids); } - /** - * @dataProvider listTagsIncludesDataProvider - * @test - */ + #[Test] + #[DataProvider('listTagsIncludesDataProvider')] public function user_sees_where_allowed_with_included_tags(string $include, array $expectedIncludes) { $response = $this->send( @@ -121,9 +117,7 @@ class ListTest extends TestCase ); } - /** - * @test - */ + #[Test] public function guest_cant_see_restricted_or_children_of_restricted() { $response = $this->send( @@ -138,7 +132,7 @@ class ListTest extends TestCase $this->assertEquals(['1', '2', '3', '4', '9', '10'], $ids); } - public function listTagsIncludesDataProvider(): array + public static function listTagsIncludesDataProvider(): array { return [ ['children', ['3', '4']], diff --git a/extensions/tags/tests/integration/api/tags/ListWithFulltextSearchTest.php b/extensions/tags/tests/integration/api/tags/ListWithFulltextSearchTest.php index 5353b139e..dd3c9daf1 100644 --- a/extensions/tags/tests/integration/api/tags/ListWithFulltextSearchTest.php +++ b/extensions/tags/tests/integration/api/tags/ListWithFulltextSearchTest.php @@ -12,6 +12,8 @@ namespace Flarum\Tags\Tests\integration\api\tags; use Flarum\Tags\Tag; use Flarum\Testing\integration\TestCase; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class ListWithFulltextSearchTest extends TestCase { @@ -36,10 +38,8 @@ class ListWithFulltextSearchTest extends TestCase ]); } - /** - * @dataProvider searchDataProvider - * @test - */ + #[Test] + #[DataProvider('searchDataProvider')] public function can_search_for_tags(string $search, array $expected) { $response = $this->send( @@ -56,7 +56,7 @@ class ListWithFulltextSearchTest extends TestCase $this->assertEquals($expected, Arr::pluck($data, 'id')); } - public function searchDataProvider(): array + public static function searchDataProvider(): array { return [ ['fla', [8]], diff --git a/extensions/tags/tests/integration/api/tags/ShowTest.php b/extensions/tags/tests/integration/api/tags/ShowTest.php index 840bde027..ab605e868 100644 --- a/extensions/tags/tests/integration/api/tags/ShowTest.php +++ b/extensions/tags/tests/integration/api/tags/ShowTest.php @@ -16,6 +16,8 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class ShowTest extends TestCase { @@ -43,7 +45,7 @@ class ShowTest extends TestCase ]); } - /** @test */ + #[Test] public function can_show_tag_with_url_decoded_utf8_slug() { $this->prepareDatabase([ @@ -65,7 +67,7 @@ class ShowTest extends TestCase $this->assertEquals(200, $response2->getStatusCode()); } - /** @test */ + #[Test] public function can_show_tag_with_url_encoded_utf8_slug() { $this->prepareDatabase([ @@ -87,10 +89,8 @@ class ShowTest extends TestCase $this->assertEquals(200, $response2->getStatusCode()); } - /** - * @dataProvider showTagIncludes - * @test - */ + #[Test] + #[DataProvider('showTagIncludes')] public function user_sees_tag_relations_where_allowed(string $include, array $expectedIncludes) { $response = $this->send( @@ -109,7 +109,7 @@ class ShowTest extends TestCase $this->assertEqualsCanonicalizing($expectedIncludes, Arr::pluck($included, 'id')); } - public function showTagIncludes(): array + public static function showTagIncludes(): array { return [ ['children', []], diff --git a/extensions/tags/tests/integration/authorization/GlobalPolicyTest.php b/extensions/tags/tests/integration/authorization/GlobalPolicyTest.php index bc66b08f2..5c3b177c9 100644 --- a/extensions/tags/tests/integration/authorization/GlobalPolicyTest.php +++ b/extensions/tags/tests/integration/authorization/GlobalPolicyTest.php @@ -15,6 +15,7 @@ use Flarum\Tags\Tests\integration\RetrievesRepresentativeTags; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class GlobalPolicyTest extends TestCase { @@ -38,9 +39,7 @@ class GlobalPolicyTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function cant_start_discussion_globally_if_permission_not_granted() { $this->database()->table('group_permission')->where('permission', 'startDiscussion')->delete(); @@ -48,9 +47,7 @@ class GlobalPolicyTest extends TestCase $this->assertFalse(User::find(2)->can('startDiscussion')); } - /** - * @test - */ + #[Test] public function can_start_discussion_globally_if_allowed_in_primary_tag() { $this->prepareDatabase([ @@ -64,9 +61,7 @@ class GlobalPolicyTest extends TestCase $this->assertTrue(User::find(2)->can('startDiscussion')); } - /** - * @test - */ + #[Test] public function cant_start_discussion_globally_if_allowed_in_child_tag_only() { $this->prepareDatabase([ @@ -80,9 +75,7 @@ class GlobalPolicyTest extends TestCase $this->assertFalse(User::find(2)->can('startDiscussion')); } - /** - * @test - */ + #[Test] public function cant_start_discussion_globally_if_allowed_in_secondary_tag() { $this->prepareDatabase([ @@ -96,9 +89,7 @@ class GlobalPolicyTest extends TestCase $this->assertFalse(User::find(2)->can('startDiscussion')); } - /** - * @test - */ + #[Test] public function can_start_discussion_globally_if_allowed_in_secondary_tag_and_minimums_adjusted() { $this->prepareDatabase([ @@ -115,9 +106,7 @@ class GlobalPolicyTest extends TestCase $this->assertTrue(User::find(2)->can('startDiscussion')); } - /** - * @test - */ + #[Test] public function cant_start_discussion_globally_if_permission_in_insufficient_tags_requires_start_discussion_regardless_of_bypass() { $this->prepareDatabase([ @@ -131,9 +120,7 @@ class GlobalPolicyTest extends TestCase $this->assertFalse(User::find(2)->can('startDiscussion')); } - /** - * @test - */ + #[Test] public function can_start_discussion_globally_if_start_discussion_and_bypass_allows_regardless_of_tag_count() { $this->prepareDatabase([ @@ -147,9 +134,7 @@ class GlobalPolicyTest extends TestCase $this->assertTrue(User::find(2)->can('startDiscussion')); } - /** - * @test - */ + #[Test] public function can_start_discussion_globally_if_sufficient_tags_and_allows_regardless_of_start_discussion_and_bypass() { $this->database()->table('group_permission')->where('permission', 'bypassTagCounts')->delete(); diff --git a/extensions/tags/tests/integration/authorization/TagPolicyTest.php b/extensions/tags/tests/integration/authorization/TagPolicyTest.php index 82de689f5..faaf798a0 100644 --- a/extensions/tags/tests/integration/authorization/TagPolicyTest.php +++ b/extensions/tags/tests/integration/authorization/TagPolicyTest.php @@ -15,6 +15,7 @@ use Flarum\Tags\Tests\integration\RetrievesRepresentativeTags; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class TagPolicyTest extends TestCase { @@ -42,9 +43,7 @@ class TagPolicyTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function has_ability_when_allowed_in_restricted_tag() { $this->app(); @@ -54,9 +53,7 @@ class TagPolicyTest extends TestCase $this->assertTrue(User::find(2)->can('arbitraryAbility!', $tag)); } - /** - * @test - */ + #[Test] public function has_ability_in_child_when_allowed_in_top_tag_and_child() { $this->app(); @@ -66,9 +63,7 @@ class TagPolicyTest extends TestCase $this->assertTrue(User::find(2)->can('arbitraryAbility!', $tag)); } - /** - * @test - */ + #[Test] public function doesnt_have_ability_in_child_when_allowed_in_child_but_not_parent() { $this->app(); @@ -80,9 +75,7 @@ class TagPolicyTest extends TestCase $this->assertFalse(User::find(2)->can('arbitraryAbility!', $tag)); } - /** - * @test - */ + #[Test] public function nonrestricted_tag_falls_back_to_global_when_allowed() { $this->prepareDatabase([ @@ -98,9 +91,7 @@ class TagPolicyTest extends TestCase $this->assertTrue(User::find(2)->can('arbitraryAbility!', $tag)); } - /** - * @test - */ + #[Test] public function nonrestricted_tag_falls_back_to_global_when_not_allowed() { $this->app(); diff --git a/extensions/tags/tests/integration/visibility/DiscussionVisibilityTest.php b/extensions/tags/tests/integration/visibility/DiscussionVisibilityTest.php index 4176a65f8..17f6ca5be 100644 --- a/extensions/tags/tests/integration/visibility/DiscussionVisibilityTest.php +++ b/extensions/tags/tests/integration/visibility/DiscussionVisibilityTest.php @@ -19,6 +19,7 @@ use Flarum\Testing\integration\TestCase; use Flarum\User\Guest; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class DiscussionVisibilityTest extends TestCase { @@ -82,9 +83,7 @@ class DiscussionVisibilityTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function admin_sees_all() { $this->app(); @@ -96,9 +95,7 @@ class DiscussionVisibilityTest extends TestCase $this->assertEqualsCanonicalizing([1, 2, 3, 4, 5, 6, 7], $ids); } - /** - * @test - */ + #[Test] public function user_sees_where_allowed() { $this->app(); @@ -110,9 +107,7 @@ class DiscussionVisibilityTest extends TestCase $this->assertEqualsCanonicalizing([1, 2, 3, 4, 7], $ids); } - /** - * @test - */ + #[Test] public function user_sees_only_in_restricted_tags_without_global_perm() { $this->database()->table('group_permission')->where('permission', 'arbitraryAbility')->delete(); @@ -124,9 +119,7 @@ class DiscussionVisibilityTest extends TestCase $this->assertEqualsCanonicalizing([7], $ids); } - /** - * @test - */ + #[Test] public function guest_can_see_where_allowed() { $this->app(); @@ -138,9 +131,7 @@ class DiscussionVisibilityTest extends TestCase $this->assertEqualsCanonicalizing([1, 2], $ids); } - /** - * @test - */ + #[Test] public function guest_cant_see_without_global_perm() { $this->database()->table('group_permission')->where('permission', 'arbitraryAbility')->delete(); diff --git a/extensions/tags/tests/phpunit.integration.xml b/extensions/tags/tests/phpunit.integration.xml index 7319d929a..e3e14eab9 100644 --- a/extensions/tags/tests/phpunit.integration.xml +++ b/extensions/tags/tests/phpunit.integration.xml @@ -1,22 +1,20 @@ - + ../src/ - + ./integration diff --git a/extensions/tags/tests/phpunit.unit.xml b/extensions/tags/tests/phpunit.unit.xml index 66262dd9f..67367a782 100644 --- a/extensions/tags/tests/phpunit.unit.xml +++ b/extensions/tags/tests/phpunit.unit.xml @@ -1,28 +1,23 @@ - + ../src/ - + ./unit - - - diff --git a/framework/core/.gitignore b/framework/core/.gitignore index 4ebb168a0..e60e51206 100644 --- a/framework/core/.gitignore +++ b/framework/core/.gitignore @@ -4,6 +4,7 @@ composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/framework/core/composer.json b/framework/core/composer.json index 99847daf7..f7a4c8e55 100644 --- a/framework/core/composer.json +++ b/framework/core/composer.json @@ -36,7 +36,7 @@ "chat": "https://flarum.org/chat" }, "require": { - "php": "^8.1", + "php": "^8.2", "components/font-awesome": "^5.15.0", "dflydev/fig-cookies": "^3.0", "doctrine/dbal": "^3.6", @@ -44,22 +44,22 @@ "fakerphp/faker": "^1.9.1", "franzl/whoops-middleware": "2.0", "guzzlehttp/guzzle": "^7.7", - "illuminate/bus": "^10.0", - "illuminate/cache": "^10.0", - "illuminate/config": "^10.0", - "illuminate/console": "^10.0", - "illuminate/container": "^10.0", - "illuminate/contracts": "^10.0", - "illuminate/database": "^10.0", - "illuminate/events": "^10.0", - "illuminate/filesystem": "^10.0", - "illuminate/hashing": "^10.0", - "illuminate/mail": "^10.0", - "illuminate/queue": "^10.0", - "illuminate/session": "^10.0", - "illuminate/support": "^10.0", - "illuminate/validation": "^10.0", - "illuminate/view": "^10.0", + "illuminate/bus": "^11.0", + "illuminate/cache": "^11.0", + "illuminate/config": "^11.0", + "illuminate/console": "^11.0", + "illuminate/container": "^11.0", + "illuminate/contracts": "^11.0", + "illuminate/database": "^11.0", + "illuminate/events": "^11.0", + "illuminate/filesystem": "^11.0", + "illuminate/hashing": "^11.0", + "illuminate/mail": "^11.0", + "illuminate/queue": "^11.0", + "illuminate/session": "^11.0", + "illuminate/support": "^11.0", + "illuminate/validation": "^11.0", + "illuminate/view": "^11.0", "intervention/image": "^3.2", "jenssegers/agent": "^2.6.4", "laminas/laminas-diactoros": "^3.0", @@ -72,31 +72,30 @@ "middlewares/base-path-router": "^2.0.1", "middlewares/request-handler": "^2.0.2", "monolog/monolog": "^3.0", - "nesbot/carbon": "^2.0", + "nesbot/carbon": "^3.0", "nikic/fast-route": "^1.3", "psr/http-message": "^1.1", "psr/http-server-handler": "^1.0.2", "psr/http-server-middleware": "^1.0.2", "s9e/text-formatter": "^2.13", - "staudenmeir/eloquent-eager-limit": "^1.8.2", "sycho/sourcemap": "^2.0.0", - "symfony/config": "^6.3", - "symfony/console": "^6.3", - "symfony/event-dispatcher": "^6.3", - "symfony/http-client": "^6.3", - "symfony/mailgun-mailer": "^6.3", - "symfony/mime": "^6.3", + "symfony/config": "^7.0", + "symfony/console": "^7.0", + "symfony/event-dispatcher": "^7.0", + "symfony/http-client": "^7.0", + "symfony/mailgun-mailer": "^7.0", + "symfony/mime": "^7.0", "symfony/polyfill-intl-messageformatter": "^1.27", - "symfony/postmark-mailer": "^6.3", - "symfony/translation": "^6.3", + "symfony/postmark-mailer": "^7.0", + "symfony/translation": "^7.0", "symfony/translation-contracts": "^2.5", - "symfony/yaml": "^6.3", + "symfony/yaml": "^7.0", "flarum/json-api-server": "^0.1.0", "wikimedia/less.php": "^4.1" }, "require-dev": { "flarum/testing": "^2.0", - "symfony/var-dumper": "^6.3" + "symfony/var-dumper": "^7.0" }, "autoload": { "psr-4": { diff --git a/framework/core/migrations/2015_12_17_194247_change_settings_value_column_to_text.php b/framework/core/migrations/2015_12_17_194247_change_settings_value_column_to_text.php index bc30cf249..e3eae3865 100644 --- a/framework/core/migrations/2015_12_17_194247_change_settings_value_column_to_text.php +++ b/framework/core/migrations/2015_12_17_194247_change_settings_value_column_to_text.php @@ -13,13 +13,13 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { $schema->table('settings', function (Blueprint $table) { - $table->text('value')->change(); + $table->text('value')->nullable()->change(); }); }, 'down' => function (Builder $schema) { $schema->table('settings', function (Blueprint $table) { - $table->binary('value')->change(); + $table->binary('value')->nullable()->change(); }); } ]; diff --git a/framework/core/src/Console/ConsoleServiceProvider.php b/framework/core/src/Console/ConsoleServiceProvider.php index a9ab9aadb..5bd57fe1a 100644 --- a/framework/core/src/Console/ConsoleServiceProvider.php +++ b/framework/core/src/Console/ConsoleServiceProvider.php @@ -55,7 +55,7 @@ class ConsoleServiceProvider extends AbstractServiceProvider }); $this->container->singleton(LaravelSchedule::class, function (Container $container) { - return $container->make(Schedule::class); + return $container->make(Schedule::class, ['timezone' => $container['config']['app.timezone']]); }); $this->container->singleton('flarum.console.commands', function () { diff --git a/framework/core/src/Database/AbstractModel.php b/framework/core/src/Database/AbstractModel.php index ce1e04a39..f9ed97450 100644 --- a/framework/core/src/Database/AbstractModel.php +++ b/framework/core/src/Database/AbstractModel.php @@ -151,8 +151,12 @@ abstract class AbstractModel extends Eloquent return $callbacks; } + /** + * @inheritDoc + */ public function newModelQuery() { + /** @var \Illuminate\Database\Eloquent\Builder $query */ $query = parent::newModelQuery(); if ($this->tableAlias) { @@ -183,8 +187,10 @@ abstract class AbstractModel extends Eloquent return $result; } + // @phpstan-ignore-next-line public function newCollection(array $models = []): Collection { + // @phpstan-ignore-next-line return new Collection($models); } diff --git a/framework/core/src/Database/Migrator.php b/framework/core/src/Database/Migrator.php index 2be94ab29..c5830b7ed 100644 --- a/framework/core/src/Database/Migrator.php +++ b/framework/core/src/Database/Migrator.php @@ -9,12 +9,10 @@ namespace Flarum\Database; -use Doctrine\DBAL\Types\Type; use Flarum\Database\Exception\MigrationKeyMissing; use Flarum\Extension\Extension; use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Database\ConnectionInterface; -use Illuminate\Database\DBAL\TimestampType; use Illuminate\Filesystem\Filesystem; use RuntimeException; use Symfony\Component\Console\Output\OutputInterface; @@ -31,14 +29,6 @@ class Migrator protected ConnectionInterface $connection, protected Filesystem $files ) { - $doctrine = $connection->getDoctrineConnection()->getDatabasePlatform(); - - if (! Type::hasType('timestamp')) { - Type::addType('timestamp', TimestampType::class); - } - - // Workaround for https://github.com/laravel/framework/issues/1186 - $doctrine->registerDoctrineTypeMapping('enum', 'string'); } /** diff --git a/framework/core/src/Discussion/Access/DiscussionPolicy.php b/framework/core/src/Discussion/Access/DiscussionPolicy.php index 3e4099b07..321b31281 100644 --- a/framework/core/src/Discussion/Access/DiscussionPolicy.php +++ b/framework/core/src/Discussion/Access/DiscussionPolicy.php @@ -37,7 +37,7 @@ class DiscussionPolicy extends AbstractPolicy if ($allowRenaming === '-1' || ($allowRenaming === 'reply' && $discussion->participant_count <= 1) - || (is_numeric($allowRenaming) && $discussion->created_at->diffInMinutes() < $allowRenaming)) { + || (is_numeric($allowRenaming) && $discussion->created_at->diffInMinutes(null, true) < $allowRenaming)) { return $this->allow(); } } diff --git a/framework/core/src/Extend/Console.php b/framework/core/src/Extend/Console.php index 3164b86c4..f4ce68da5 100644 --- a/framework/core/src/Extend/Console.php +++ b/framework/core/src/Extend/Console.php @@ -44,7 +44,7 @@ class Console implements ExtenderInterface * The callback should apply relevant methods to $event, and does not need to return anything. * * @see https://laravel.com/api/8.x/Illuminate/Console/Scheduling/Event.html - * @see https://laravel.com/docs/10.x/scheduling#schedule-frequency-options + * @see https://laravel.com/docs/11.x/scheduling#schedule-frequency-options * for more information on available methods and what they do. * * @param array $args An array of args to call the command with. diff --git a/framework/core/src/Extend/Event.php b/framework/core/src/Extend/Event.php index a7092081e..d3a443887 100644 --- a/framework/core/src/Extend/Event.php +++ b/framework/core/src/Extend/Event.php @@ -44,7 +44,7 @@ class Event implements ExtenderInterface * Event subscribers are classes that may subscribe to multiple events from within the subscriber class itself, * allowing you to define several event handlers within a single class. * - * @see https://laravel.com/docs/10.x/events#writing-event-subscribers + * @see https://laravel.com/docs/11.x/events#writing-event-subscribers * * @param string $subscriber: The ::class attribute of the subscriber class. * @return self diff --git a/framework/core/src/Extend/Filesystem.php b/framework/core/src/Extend/Filesystem.php index f1bd90fc6..a6357b5f1 100644 --- a/framework/core/src/Extend/Filesystem.php +++ b/framework/core/src/Extend/Filesystem.php @@ -51,7 +51,7 @@ class Filesystem implements ExtenderInterface * }); * ``` * - * @see https://laravel.com/docs/10.x/filesystem#configuration + * @see https://laravel.com/docs/11.x/filesystem#configuration * * @return self */ diff --git a/framework/core/src/Extend/Model.php b/framework/core/src/Extend/Model.php index 4519b4d12..e0b30fbd3 100644 --- a/framework/core/src/Extend/Model.php +++ b/framework/core/src/Extend/Model.php @@ -16,6 +16,9 @@ use Illuminate\Contracts\Container\Container; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Arr; +/** + * @template M of AbstractModel + */ class Model implements ExtenderInterface { private array $customRelations = []; @@ -34,7 +37,7 @@ class Model implements ExtenderInterface * Add a custom attribute type cast. Should not be applied to non-extension attributes. * * @param string $attribute: The new attribute name. - * @param string $cast: The cast type. See https://laravel.com/docs/10.x/eloquent-mutators#attribute-casting + * @param string $cast: The cast type. See https://laravel.com/docs/11.x/eloquent-mutators#attribute-casting * @return self */ public function cast(string $attribute, string $cast): self @@ -156,9 +159,7 @@ class Model implements ExtenderInterface * @param string $name: The name of the relation. This doesn't have to be anything in particular, * but has to be unique from other relation names for this model, and should * work as the name of a method. - * @template T of AbstractModel - * @template R of Relation - * @param (callable(T $instance): R)|class-string $callback + * @param callable|class-string $callback * * The callable can be a closure or invokable class, and should accept: * - $instance: An instance of this model. diff --git a/framework/core/src/Extension/Extension.php b/framework/core/src/Extension/Extension.php index a7c87b8f8..6250c8a88 100644 --- a/framework/core/src/Extension/Extension.php +++ b/framework/core/src/Extension/Extension.php @@ -127,7 +127,7 @@ class Extension implements Arrayable /** * Dot notation getter for composer.json attributes. * - * @see https://laravel.com/docs/10.x/helpers#arrays + * @see https://laravel.com/docs/11.x/helpers#arrays */ public function composerJsonAttribute(string $name): mixed { diff --git a/framework/core/src/Foundation/Config.php b/framework/core/src/Foundation/Config.php index 4d5efd4a3..3e53ad7a6 100644 --- a/framework/core/src/Foundation/Config.php +++ b/framework/core/src/Foundation/Config.php @@ -81,12 +81,12 @@ class Config implements ArrayAccess public function offsetGet($offset): mixed { - return Arr::get($this->data, $offset); + return Arr::get($this->data, $offset, Arr::get($this->defaults(), $offset)); } public function offsetExists($offset): bool { - return Arr::has($this->data, $offset); + return Arr::has($this->data, $offset) || Arr::has($this->defaults(), $offset); } public function offsetSet($offset, $value): void @@ -103,4 +103,14 @@ class Config implements ArrayAccess { return $this->data['env'] ?? 'production'; } + + protected function defaults(): array + { + // Mostly needed for Laravel internals. + return [ + 'app' => [ + 'timezone' => 'UTC', + ], + ]; + } } diff --git a/framework/core/src/Http/AccessToken.php b/framework/core/src/Http/AccessToken.php index 69aa2e304..15f7a8c56 100644 --- a/framework/core/src/Http/AccessToken.php +++ b/framework/core/src/Http/AccessToken.php @@ -111,7 +111,7 @@ class AccessToken extends AbstractModel { $now = Carbon::now(); - if ($this->last_activity_at === null || $this->last_activity_at->diffInSeconds($now) > AccessToken::LAST_ACTIVITY_UPDATE_DIFF) { + if ($this->last_activity_at === null || $this->last_activity_at->diffInSeconds($now, true) > AccessToken::LAST_ACTIVITY_UPDATE_DIFF) { $this->last_activity_at = $now; } diff --git a/framework/core/src/Post/Access/PostPolicy.php b/framework/core/src/Post/Access/PostPolicy.php index 2171f1f55..333fc0ab8 100644 --- a/framework/core/src/Post/Access/PostPolicy.php +++ b/framework/core/src/Post/Access/PostPolicy.php @@ -41,7 +41,7 @@ class PostPolicy extends AbstractPolicy if ($allowEditing === '-1' || ($allowEditing === 'reply' && $post->number >= $post->discussion->last_post_number) - || (is_numeric($allowEditing) && $post->created_at->diffInMinutes(new Carbon) < $allowEditing)) { + || (is_numeric($allowEditing) && $post->created_at->diffInMinutes(new Carbon, true) < $allowEditing)) { return $this->allow(); } } @@ -56,7 +56,7 @@ class PostPolicy extends AbstractPolicy if ($allowHiding === '-1' || ($allowHiding === 'reply' && $post->number >= $post->discussion->last_post_number) - || (is_numeric($allowHiding) && $post->created_at->diffInMinutes(new Carbon) < $allowHiding)) { + || (is_numeric($allowHiding) && $post->created_at->diffInMinutes(new Carbon, true) < $allowHiding)) { return $this->allow(); } } diff --git a/framework/core/src/Post/Post.php b/framework/core/src/Post/Post.php index cf301568e..959f5f0f3 100644 --- a/framework/core/src/Post/Post.php +++ b/framework/core/src/Post/Post.php @@ -20,7 +20,6 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Query\Expression; -use Staudenmeir\EloquentEagerLimit\HasEagerLimit; /** * @property int $id @@ -45,7 +44,6 @@ class Post extends AbstractModel { use EventGeneratorTrait; use ScopeVisibilityTrait; - use HasEagerLimit; use HasFactory; protected $table = 'posts'; diff --git a/framework/core/src/User/EmailToken.php b/framework/core/src/User/EmailToken.php index ed91dbdbe..58ebcffa3 100644 --- a/framework/core/src/User/EmailToken.php +++ b/framework/core/src/User/EmailToken.php @@ -65,7 +65,7 @@ class EmailToken extends AbstractModel /** @var static|null $token */ $token = $query->find($id); - if (! $token || $token->created_at->diffInDays() >= 1) { + if (! $token || $token->created_at->diffInDays(null, true) >= 1) { throw new InvalidConfirmationTokenException; } diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 1038c056c..e8e0c1f93 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -39,7 +39,6 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Arr; -use Staudenmeir\EloquentEagerLimit\HasEagerLimit; /** * @property int $id @@ -72,7 +71,6 @@ class User extends AbstractModel { use EventGeneratorTrait; use ScopeVisibilityTrait; - use HasEagerLimit; use HasFactory; protected $casts = [ @@ -440,7 +438,7 @@ class User extends AbstractModel { $now = Carbon::now(); - if ($this->last_seen_at === null || $this->last_seen_at->diffInSeconds($now) > User::LAST_SEEN_UPDATE_DIFF) { + if ($this->last_seen_at === null || $this->last_seen_at->diffInSeconds($now, true) > User::LAST_SEEN_UPDATE_DIFF) { $this->last_seen_at = $now; } diff --git a/framework/core/tests/integration/admin/IndexTest.php b/framework/core/tests/integration/admin/IndexTest.php index 08234c7b3..0ad428091 100644 --- a/framework/core/tests/integration/admin/IndexTest.php +++ b/framework/core/tests/integration/admin/IndexTest.php @@ -29,7 +29,7 @@ class IndexTest extends TestCase ]); } - public function admin_can_access_admin_route(): void + public function test_admin_can_access_admin_route(): void { $response = $this->send( $this->request('GET', '/admin', [ @@ -40,7 +40,7 @@ class IndexTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - public function user_cannot_access_admin_route(): void + public function test_user_cannot_access_admin_route(): void { $response = $this->send( $this->request('GET', '/admin', [ diff --git a/framework/core/tests/integration/api/access_tokens/AccessTokenLifecycleTest.php b/framework/core/tests/integration/api/access_tokens/AccessTokenLifecycleTest.php index ce4096d3b..666227801 100644 --- a/framework/core/tests/integration/api/access_tokens/AccessTokenLifecycleTest.php +++ b/framework/core/tests/integration/api/access_tokens/AccessTokenLifecycleTest.php @@ -14,6 +14,7 @@ use Flarum\Http\AccessToken; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Laminas\Diactoros\ServerRequest; +use PHPUnit\Framework\Attributes\Test; class AccessTokenLifecycleTest extends TestCase { @@ -35,9 +36,7 @@ class AccessTokenLifecycleTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function tokens_expire() { $this->populateDatabase(); @@ -52,9 +51,7 @@ class AccessTokenLifecycleTest extends TestCase $this->assertEquals(['a', 'b'], AccessToken::whereExpired(Carbon::parse('2027-01-01 01:00:00'))->pluck('token')->sort()->values()->all()); } - /** - * @test - */ + #[Test] public function tokens_valid() { $this->populateDatabase(); @@ -69,9 +66,7 @@ class AccessTokenLifecycleTest extends TestCase $this->assertEquals(['c'], AccessToken::whereValid(Carbon::parse('2027-01-01 01:00:00'))->pluck('token')->all()); } - /** - * @test - */ + #[Test] public function touch_updates_lifetime() { $this->populateDatabase(); @@ -87,9 +82,7 @@ class AccessTokenLifecycleTest extends TestCase $this->assertTrue(AccessToken::whereValid(Carbon::parse('2021-01-01 03:30:00'))->whereToken('a')->exists()); } - /** - * @test - */ + #[Test] public function touch_without_request() { $this->populateDatabase(); @@ -104,9 +97,7 @@ class AccessTokenLifecycleTest extends TestCase $this->assertNull($token->last_user_agent); } - /** - * @test - */ + #[Test] public function touch_with_request() { $this->populateDatabase(); @@ -123,9 +114,7 @@ class AccessTokenLifecycleTest extends TestCase $this->assertEquals('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36', $token->last_user_agent); } - /** - * @test - */ + #[Test] public function long_user_agent_id_truncated() { $this->populateDatabase(); diff --git a/framework/core/tests/integration/api/access_tokens/CreateTest.php b/framework/core/tests/integration/api/access_tokens/CreateTest.php index e7e69a186..66b84fcde 100644 --- a/framework/core/tests/integration/api/access_tokens/CreateTest.php +++ b/framework/core/tests/integration/api/access_tokens/CreateTest.php @@ -13,6 +13,8 @@ use Flarum\Group\Group; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class CreateTest extends TestCase { @@ -42,10 +44,8 @@ class CreateTest extends TestCase ]); } - /** - * @dataProvider canCreateTokens - * @test - */ + #[Test] + #[DataProvider('canCreateTokens')] public function user_can_create_developer_tokens(int $authenticatedAs) { $response = $this->send( @@ -65,10 +65,8 @@ class CreateTest extends TestCase $this->assertEquals(201, $response->getStatusCode(), (string) $response->getBody()); } - /** - * @dataProvider cannotCreateTokens - * @test - */ + #[Test] + #[DataProvider('cannotCreateTokens')] public function user_cannot_delete_other_users_tokens(int $authenticatedAs) { $response = $this->send( @@ -88,9 +86,7 @@ class CreateTest extends TestCase $this->assertEquals(403, $response->getStatusCode(), (string) $response->getBody()); } - /** - * @test - */ + #[Test] public function user_cannot_create_token_without_title() { $response = $this->send( @@ -108,7 +104,7 @@ class CreateTest extends TestCase $this->assertEquals(422, $response->getStatusCode(), (string) $response->getBody()); } - public function canCreateTokens(): array + public static function canCreateTokens(): array { return [ [1], // Admin @@ -116,7 +112,7 @@ class CreateTest extends TestCase ]; } - public function cannotCreateTokens(): array + public static function cannotCreateTokens(): array { return [ [2] diff --git a/framework/core/tests/integration/api/access_tokens/DeleteTest.php b/framework/core/tests/integration/api/access_tokens/DeleteTest.php index bfc009eb2..5c70a8e67 100644 --- a/framework/core/tests/integration/api/access_tokens/DeleteTest.php +++ b/framework/core/tests/integration/api/access_tokens/DeleteTest.php @@ -18,6 +18,8 @@ use Flarum\Http\SessionAccessToken; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class DeleteTest extends TestCase { @@ -56,10 +58,8 @@ class DeleteTest extends TestCase ]); } - /** - * @dataProvider canDeleteTokensDataProvider - * @test - */ + #[Test] + #[DataProvider('canDeleteTokensDataProvider')] public function user_can_delete_tokens(int $authenticatedAs, array $canDeleteIds) { foreach ($canDeleteIds as $id) { @@ -71,10 +71,8 @@ class DeleteTest extends TestCase } } - /** - * @dataProvider cannotDeleteTokensDataProvider - * @test - */ + #[Test] + #[DataProvider('cannotDeleteTokensDataProvider')] public function user_cannot_delete_tokens(int $authenticatedAs, array $canDeleteIds) { foreach ($canDeleteIds as $id) { @@ -86,9 +84,7 @@ class DeleteTest extends TestCase } } - /** - * @test - */ + #[Test] public function user_cannot_delete_current_session_token() { $responseWithSession = $this->send( @@ -120,9 +116,7 @@ class DeleteTest extends TestCase $this->assertEquals(403, $response->getStatusCode(), $response->getBody()->getContents()); } - /** - * @test - */ + #[Test] public function user_can_terminate_all_other_sessions() { $responseWithSession = $this->send( @@ -165,9 +159,7 @@ class DeleteTest extends TestCase ); } - /** - * @test - */ + #[Test] public function terminting_all_other_sessions_does_not_delete_dev_tokens() { $response = $this->send( @@ -186,7 +178,7 @@ class DeleteTest extends TestCase ); } - public function canDeleteTokensDataProvider(): array + public static function canDeleteTokensDataProvider(): array { return [ // Admin can delete any user tokens. @@ -201,7 +193,7 @@ class DeleteTest extends TestCase ]; } - public function cannotDeleteTokensDataProvider(): array + public static function cannotDeleteTokensDataProvider(): array { return [ // Normal users cannot delete other users' tokens. diff --git a/framework/core/tests/integration/api/access_tokens/ListTest.php b/framework/core/tests/integration/api/access_tokens/ListTest.php index cef14fc2b..20f4d3c4a 100644 --- a/framework/core/tests/integration/api/access_tokens/ListTest.php +++ b/framework/core/tests/integration/api/access_tokens/ListTest.php @@ -16,6 +16,8 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class ListTest extends TestCase { @@ -54,10 +56,8 @@ class ListTest extends TestCase ]); } - /** - * @dataProvider canViewTokensDataProvider - * @test - */ + #[Test] + #[DataProvider('canViewTokensDataProvider')] public function user_can_view_access_tokens(int $authenticatedAs, array $canViewIds) { $response = $this->send( @@ -72,10 +72,8 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(array_merge($canViewIds, [$testsTokenId]), Arr::pluck($data, 'id')); } - /** - * @dataProvider cannotSeeTokenValuesDataProvider - * @test - */ + #[Test] + #[DataProvider('cannotSeeTokenValuesDataProvider')] public function user_cannot_see_token_values(int $authenticatedAs, ?int $userId, array $tokenValues) { if ($userId) { @@ -101,10 +99,8 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing($tokenValues, Arr::pluck($data, 'attributes.token')); } - /** - * @dataProvider needsPermissionToUseUserfilterDataProvider - * @test - */ + #[Test] + #[DataProvider('needsPermissionToUseUserfilterDataProvider')] public function user_needs_permissions_to_use_user_filter(int $authenticatedAs, int $userId, array $canViewIds) { $response = $this->send( @@ -125,7 +121,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing($canViewIds, Arr::pluck($data, 'id')); } - public function canViewTokensDataProvider(): array + public static function canViewTokensDataProvider(): array { return [ // Admin can view his and others access tokens. @@ -140,7 +136,7 @@ class ListTest extends TestCase ]; } - public function cannotSeeTokenValuesDataProvider(): array + public static function cannotSeeTokenValuesDataProvider(): array { return [ // Admin can only see his own developer token value. @@ -161,7 +157,7 @@ class ListTest extends TestCase ]; } - public function needsPermissionToUseUserfilterDataProvider(): array + public static function needsPermissionToUseUserfilterDataProvider(): array { return [ // Admin can use user filter. diff --git a/framework/core/tests/integration/api/access_tokens/RemembererTest.php b/framework/core/tests/integration/api/access_tokens/RemembererTest.php index 1ff10e1f4..d7efd80a0 100644 --- a/framework/core/tests/integration/api/access_tokens/RemembererTest.php +++ b/framework/core/tests/integration/api/access_tokens/RemembererTest.php @@ -13,6 +13,7 @@ use Carbon\Carbon; use Flarum\Http\AccessToken; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class RemembererTest extends TestCase { @@ -33,9 +34,7 @@ class RemembererTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function non_remember_tokens_cannot_be_used() { $this->populateDatabase(); @@ -54,9 +53,7 @@ class RemembererTest extends TestCase $this->assertFalse($data['data']['attributes']['canSearchUsers']); } - /** - * @test - */ + #[Test] public function expired_tokens_cannot_be_used() { $this->populateDatabase(); @@ -75,9 +72,7 @@ class RemembererTest extends TestCase $this->assertFalse($data['data']['attributes']['canSearchUsers']); } - /** - * @test - */ + #[Test] public function valid_tokens_can_be_used() { $this->populateDatabase(); diff --git a/framework/core/tests/integration/api/authentication/WithApiKeyTest.php b/framework/core/tests/integration/api/authentication/WithApiKeyTest.php index 544332bd1..eae59cc76 100644 --- a/framework/core/tests/integration/api/authentication/WithApiKeyTest.php +++ b/framework/core/tests/integration/api/authentication/WithApiKeyTest.php @@ -14,6 +14,7 @@ use Flarum\Api\ApiKey; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class WithApiKeyTest extends TestCase { @@ -37,9 +38,7 @@ class WithApiKeyTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function cannot_authorize_without_key() { $response = $this->send( @@ -50,9 +49,7 @@ class WithApiKeyTest extends TestCase $this->assertFalse($data['data']['attributes']['canSearchUsers']); } - /** - * @test - */ + #[Test] public function master_token_can_authenticate_as_anyone() { $response = $this->send( @@ -69,9 +66,7 @@ class WithApiKeyTest extends TestCase $this->assertNotNull($key->last_activity_at); } - /** - * @test - */ + #[Test] public function personal_api_token_cannot_authenticate_as_anyone() { $response = $this->send( @@ -88,9 +83,7 @@ class WithApiKeyTest extends TestCase $this->assertNotNull($key->last_activity_at); } - /** - * @test - */ + #[Test] public function personal_api_token_authenticates_user() { $response = $this->send( diff --git a/framework/core/tests/integration/api/authentication/WithTokenTest.php b/framework/core/tests/integration/api/authentication/WithTokenTest.php index 8ac9334cb..c02f66eee 100644 --- a/framework/core/tests/integration/api/authentication/WithTokenTest.php +++ b/framework/core/tests/integration/api/authentication/WithTokenTest.php @@ -13,6 +13,7 @@ use Flarum\Http\AccessToken; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class WithTokenTest extends TestCase { @@ -32,9 +33,7 @@ class WithTokenTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function user_generates_token() { $response = $this->send( @@ -64,9 +63,7 @@ class WithTokenTest extends TestCase $this->assertEquals(2, AccessToken::whereToken($token)->firstOrFail()->user_id); } - /** - * @test - */ + #[Test] public function failure_with_invalid_credentials() { $response = $this->send( diff --git a/framework/core/tests/integration/api/csrf_protection/RequireCsrfTokenTest.php b/framework/core/tests/integration/api/csrf_protection/RequireCsrfTokenTest.php index 461b6b6db..0c3fe3a50 100644 --- a/framework/core/tests/integration/api/csrf_protection/RequireCsrfTokenTest.php +++ b/framework/core/tests/integration/api/csrf_protection/RequireCsrfTokenTest.php @@ -13,6 +13,7 @@ use Flarum\Api\ApiKey; use Flarum\Http\AccessToken; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class RequireCsrfTokenTest extends TestCase { @@ -34,9 +35,7 @@ class RequireCsrfTokenTest extends TestCase $this->setting('csrf_test', 1); } - /** - * @test - */ + #[Test] public function error_when_doing_cookie_auth_without_csrf_token() { $auth = $this->send( @@ -73,9 +72,7 @@ class RequireCsrfTokenTest extends TestCase $this->assertEquals('csrf_token_mismatch', $json['errors'][0]['code']); } - /** - * @test - */ + #[Test] public function cookie_auth_succeeds_with_csrf_token_in_header() { $initial = $this->send( @@ -118,9 +115,7 @@ class RequireCsrfTokenTest extends TestCase ); } - /** - * @test - */ + #[Test] public function cookie_auth_succeeds_with_csrf_token_in_body() { $initial = $this->send( @@ -163,9 +158,7 @@ class RequireCsrfTokenTest extends TestCase ); } - /** - * @test - */ + #[Test] public function master_api_token_does_not_need_csrf_token() { $response = $this->send( @@ -188,9 +181,7 @@ class RequireCsrfTokenTest extends TestCase ); } - /** - * @test - */ + #[Test] public function access_token_does_not_need_csrf_token() { $this->database()->table('access_tokens')->insert( diff --git a/framework/core/tests/integration/api/discussions/CreateTest.php b/framework/core/tests/integration/api/discussions/CreateTest.php index 06cbc4e64..63ea47149 100644 --- a/framework/core/tests/integration/api/discussions/CreateTest.php +++ b/framework/core/tests/integration/api/discussions/CreateTest.php @@ -14,6 +14,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class CreateTest extends TestCase { @@ -33,9 +34,7 @@ class CreateTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function cannot_create_discussion_without_content() { $response = $this->send( @@ -71,9 +70,7 @@ class CreateTest extends TestCase ], json_decode($body, true)); } - /** - * @test - */ + #[Test] public function cannot_create_discussion_without_title() { $response = $this->send( @@ -108,9 +105,7 @@ class CreateTest extends TestCase ], json_decode($body, true)); } - /** - * @test - */ + #[Test] public function can_create_discussion() { $response = $this->send( @@ -140,9 +135,7 @@ class CreateTest extends TestCase $this->assertEquals('test - too-obscure', Arr::get($data, 'data.attributes.title')); } - /** - * @test - */ + #[Test] public function can_create_discussion_with_current_lang_slug_transliteration() { // Forum default is traditional Chinese. @@ -171,9 +164,7 @@ class CreateTest extends TestCase $this->assertEquals('wo-shi-yi-ge-tu-dou', $discussion->slug); } - /** - * @test - */ + #[Test] public function can_create_discussion_with_forum_locale_transliteration() { // Forum default is traditional Chinese. @@ -204,9 +195,7 @@ class CreateTest extends TestCase $this->assertEquals('wo-shi-yi-ge-tu-dou', $discussion->slug); } - /** - * @test - */ + #[Test] public function discussion_creation_limited_by_throttler() { $response = $this->send( @@ -244,9 +233,7 @@ class CreateTest extends TestCase $this->assertEquals(429, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function throttler_doesnt_apply_to_admin() { $this->send( diff --git a/framework/core/tests/integration/api/discussions/DeletionTest.php b/framework/core/tests/integration/api/discussions/DeletionTest.php index 6f029a624..4f125399f 100644 --- a/framework/core/tests/integration/api/discussions/DeletionTest.php +++ b/framework/core/tests/integration/api/discussions/DeletionTest.php @@ -15,6 +15,7 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class DeletionTest extends TestCase { @@ -40,9 +41,7 @@ class DeletionTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function admin_can_delete() { $response = $this->send( diff --git a/framework/core/tests/integration/api/discussions/ListTest.php b/framework/core/tests/integration/api/discussions/ListTest.php index 6a8aaf54e..3dfe05781 100644 --- a/framework/core/tests/integration/api/discussions/ListTest.php +++ b/framework/core/tests/integration/api/discussions/ListTest.php @@ -16,6 +16,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class ListTest extends TestCase { @@ -57,9 +58,7 @@ class ListTest extends TestCase $user->save(); } - /** - * @test - */ + #[Test] public function shows_index_for_guest() { $response = $this->send( @@ -72,9 +71,7 @@ class ListTest extends TestCase $this->assertEquals(3, count($data['data'])); } - /** - * @test - */ + #[Test] public function author_filter_works() { $response = $this->send( @@ -95,9 +92,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(['2', '3'], Arr::pluck($data, 'id'), 'IDs do not match'); } - /** - * @test - */ + #[Test] public function author_filter_works_negated() { $response = $this->send( @@ -114,9 +109,7 @@ class ListTest extends TestCase $this->assertEquals(['1'], Arr::pluck($data, 'id'), 'IDs do not match'); } - /** - * @test - */ + #[Test] public function created_filter_works_with_date() { $response = $this->send( @@ -135,9 +128,7 @@ class ListTest extends TestCase $this->assertEquals(['3'], Arr::pluck($data, 'id'), 'IDs do not match'); } - /** - * @test - */ + #[Test] public function created_filter_works_negated_with_date() { $response = $this->send( @@ -154,9 +145,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(['1', '2'], Arr::pluck($data, 'id'), 'IDs do not match'); } - /** - * @test - */ + #[Test] public function created_filter_works_with_range() { $response = $this->send( @@ -173,9 +162,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(['2', '3'], Arr::pluck($data, 'id'), 'IDs do not match'); } - /** - * @test - */ + #[Test] public function created_filter_works_negated_with_range() { $response = $this->send( @@ -192,9 +179,7 @@ class ListTest extends TestCase $this->assertEquals(['1'], Arr::pluck($data, 'id'), 'IDs do not match'); } - /** - * @test - */ + #[Test] public function hidden_filter_works() { $response = $this->send( @@ -211,9 +196,7 @@ class ListTest extends TestCase $this->assertEquals(['4'], Arr::pluck($data, 'id'), 'IDs do not match'); } - /** - * @test - */ + #[Test] public function hidden_filter_works_negated() { $response = $this->send( @@ -230,9 +213,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(['1', '2', '3'], Arr::pluck($data, 'id'), 'IDs do not match'); } - /** - * @test - */ + #[Test] public function unread_filter_works() { $this->app(); @@ -252,9 +233,7 @@ class ListTest extends TestCase $this->assertEquals(['3'], Arr::pluck($data, 'id'), 'IDs do not match'); } - /** - * @test - */ + #[Test] public function unread_filter_works_when_negated() { $this->app(); diff --git a/framework/core/tests/integration/api/discussions/ListWithFulltextSearchTest.php b/framework/core/tests/integration/api/discussions/ListWithFulltextSearchTest.php index 40bd49463..ac21921f1 100644 --- a/framework/core/tests/integration/api/discussions/ListWithFulltextSearchTest.php +++ b/framework/core/tests/integration/api/discussions/ListWithFulltextSearchTest.php @@ -15,6 +15,7 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class ListWithFulltextSearchTest extends TestCase { @@ -68,9 +69,7 @@ class ListWithFulltextSearchTest extends TestCase $this->database()->table('posts')->delete(); } - /** - * @test - */ + #[Test] public function can_search_for_word_or_title_in_post() { if ($this->database()->getDriverName() === 'sqlite') { @@ -96,9 +95,7 @@ class ListWithFulltextSearchTest extends TestCase $this->assertEqualsCanonicalizing(['2', '1', '3'], $ids, 'IDs do not match'); } - /** - * @test - */ + #[Test] public function ignores_non_word_characters_when_searching() { if ($this->database()->getDriverName() === 'sqlite') { @@ -121,9 +118,7 @@ class ListWithFulltextSearchTest extends TestCase $this->assertEqualsCanonicalizing(['2', '1', '3'], $ids, 'IDs do not match'); } - /** - * @test - */ + #[Test] public function can_search_telugu_like_languages() { if ($this->database()->getDriverName() === 'sqlite') { @@ -147,9 +142,7 @@ class ListWithFulltextSearchTest extends TestCase $this->assertEqualsCanonicalizing(['6'], Arr::pluck($data['included'], 'id')); } - /** - * @test - */ + #[Test] public function can_search_cjk_languages() { if ($this->database()->getDriverName() === 'sqlite') { @@ -173,9 +166,7 @@ class ListWithFulltextSearchTest extends TestCase $this->assertEqualsCanonicalizing(['7'], Arr::pluck($data['included'], 'id')); } - /** - * @test - */ + #[Test] public function search_for_special_characters_gives_empty_result() { if ($this->database()->getDriverName() === 'sqlite') { diff --git a/framework/core/tests/integration/api/discussions/ShowTest.php b/framework/core/tests/integration/api/discussions/ShowTest.php index b32714fb1..fbda8a44b 100644 --- a/framework/core/tests/integration/api/discussions/ShowTest.php +++ b/framework/core/tests/integration/api/discussions/ShowTest.php @@ -16,6 +16,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class ShowTest extends TestCase { @@ -45,9 +46,7 @@ class ShowTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function author_can_see_discussion() { $response = $this->send( @@ -59,9 +58,7 @@ class ShowTest extends TestCase $this->assertEquals(200, $response->getStatusCode(), $response->getBody()->getContents()); } - /** - * @test - */ + #[Test] public function author_can_see_discussion_via_slug() { // Note that here, the slug doesn't actually have to match the real slug @@ -77,9 +74,7 @@ class ShowTest extends TestCase $this->assertEquals(200, $response->getStatusCode(), $response->getBody()->getContents()); } - /** - * @test - */ + #[Test] public function guest_cannot_see_empty_discussion() { $response = $this->send( @@ -89,9 +84,7 @@ class ShowTest extends TestCase $this->assertEquals(404, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function guest_cannot_see_hidden_posts() { $response = $this->send( @@ -103,9 +96,7 @@ class ShowTest extends TestCase $this->assertEmpty(Arr::get($json, 'data.relationships.posts.data')); } - /** - * @test - */ + #[Test] public function author_can_see_hidden_posts() { $response = $this->send( @@ -119,9 +110,7 @@ class ShowTest extends TestCase $this->assertEquals(2, Arr::get($json, 'data.relationships.posts.data.0.id'), $response->getBody()->getContents()); } - /** - * @test - */ + #[Test] public function guest_can_see_discussion() { $response = $this->send( @@ -131,9 +120,7 @@ class ShowTest extends TestCase $this->assertEquals(200, $response->getStatusCode(), $response->getBody()->getContents()); } - /** - * @test - */ + #[Test] public function guests_cannot_see_private_discussion() { $response = $this->send( diff --git a/framework/core/tests/integration/api/forum/ShowTest.php b/framework/core/tests/integration/api/forum/ShowTest.php index 3b221546b..bc6958148 100644 --- a/framework/core/tests/integration/api/forum/ShowTest.php +++ b/framework/core/tests/integration/api/forum/ShowTest.php @@ -13,6 +13,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class ShowTest extends TestCase { @@ -32,9 +33,7 @@ class ShowTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function guest_user_does_not_see_actor_relationship() { $response = $this->send( @@ -49,9 +48,7 @@ class ShowTest extends TestCase $this->assertNull(Arr::get($json, 'data.relationships.actor.data')); } - /** - * @test - */ + #[Test] public function normal_user_sees_most_information() { $response = $this->send( @@ -73,9 +70,7 @@ class ShowTest extends TestCase $this->assertEquals(2, Arr::get($json, 'data.relationships.actor.data.id')); } - /** - * @test - */ + #[Test] public function admin_user_sees_even_more() { $response = $this->send( diff --git a/framework/core/tests/integration/api/groups/CreateTest.php b/framework/core/tests/integration/api/groups/CreateTest.php index 04d70dacf..593a4ad59 100644 --- a/framework/core/tests/integration/api/groups/CreateTest.php +++ b/framework/core/tests/integration/api/groups/CreateTest.php @@ -14,6 +14,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class CreateTest extends TestCase { @@ -33,9 +34,7 @@ class CreateTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function admin_cannot_create_group_without_data() { $response = $this->send( @@ -48,9 +47,7 @@ class CreateTest extends TestCase $this->assertEquals(400, $response->getStatusCode(), (string) $response->getBody()); } - /** - * @test - */ + #[Test] public function admin_can_create_group() { $response = $this->send( @@ -89,9 +86,7 @@ class CreateTest extends TestCase $this->assertNull($group->color); } - /** - * @test - */ + #[Test] public function normal_user_cannot_create_group() { $response = $this->send( diff --git a/framework/core/tests/integration/api/groups/ListTest.php b/framework/core/tests/integration/api/groups/ListTest.php index fcd55d6c7..c6524ee13 100644 --- a/framework/core/tests/integration/api/groups/ListTest.php +++ b/framework/core/tests/integration/api/groups/ListTest.php @@ -13,6 +13,7 @@ use Flarum\Group\Group; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class ListTest extends TestCase { @@ -32,9 +33,7 @@ class ListTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function shows_limited_index_for_guest() { $response = $this->send( @@ -48,9 +47,7 @@ class ListTest extends TestCase $this->assertEquals(['1', '2', '3', '4'], Arr::pluck($data['data'], 'id')); } - /** - * @test - */ + #[Test] public function shows_index_for_admin() { $response = $this->send( @@ -66,9 +63,7 @@ class ListTest extends TestCase $this->assertEquals(['1', '2', '3', '4', '10'], Arr::pluck($data['data'], 'id')); } - /** - * @test - */ + #[Test] public function filters_only_public_groups_for_admin() { $response = $this->send( @@ -87,9 +82,7 @@ class ListTest extends TestCase $this->assertEquals(['1', '2', '3', '4'], Arr::pluck($data['data'], 'id')); } - /** - * @test - */ + #[Test] public function filters_only_hidden_groups_for_admin() { $response = $this->send( @@ -108,9 +101,7 @@ class ListTest extends TestCase $this->assertEquals(['10'], Arr::pluck($data['data'], 'id')); } - /** - * @test - */ + #[Test] public function filters_only_public_groups_for_guest() { $response = $this->send( @@ -127,9 +118,7 @@ class ListTest extends TestCase $this->assertEquals(['1', '2', '3', '4'], Arr::pluck($data['data'], 'id')); } - /** - * @test - */ + #[Test] public function hides_hidden_groups_when_filtering_for_guest() { $response = $this->send( @@ -147,9 +136,7 @@ class ListTest extends TestCase $this->assertEquals([], Arr::pluck($data['data'], 'id')); } - /** - * @test - */ + #[Test] public function paginates_groups_without_filter() { $response = $this->send( @@ -166,9 +153,7 @@ class ListTest extends TestCase $this->assertEquals(['3', '4'], Arr::pluck($data['data'], 'id')); } - /** - * @test - */ + #[Test] public function paginates_groups_with_filter() { $response = $this->send( @@ -187,9 +172,7 @@ class ListTest extends TestCase $this->assertEmpty($data['data']); } - /** - * @test - */ + #[Test] public function sorts_groups_by_name() { $response = $this->send( diff --git a/framework/core/tests/integration/api/groups/ShowTest.php b/framework/core/tests/integration/api/groups/ShowTest.php index 09455e038..0dd4ea324 100644 --- a/framework/core/tests/integration/api/groups/ShowTest.php +++ b/framework/core/tests/integration/api/groups/ShowTest.php @@ -13,6 +13,7 @@ use Flarum\Group\Group; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class ShowTest extends TestCase { @@ -32,9 +33,7 @@ class ShowTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function shows_public_group_for_guest() { $response = $this->send( @@ -48,9 +47,7 @@ class ShowTest extends TestCase $this->assertEquals('1', Arr::get($data, 'data.id')); } - /** - * @test - */ + #[Test] public function shows_public_group_for_admin() { $response = $this->send( @@ -66,9 +63,7 @@ class ShowTest extends TestCase $this->assertEquals('1', Arr::get($data, 'data.id')); } - /** - * @test - */ + #[Test] public function hides_hidden_group_for_guest() { $response = $this->send( @@ -79,9 +74,7 @@ class ShowTest extends TestCase $this->assertEquals(404, $response->getStatusCode(), (string) $response->getBody()); } - /** - * @test - */ + #[Test] public function shows_hidden_group_for_admin() { $response = $this->send( @@ -97,9 +90,7 @@ class ShowTest extends TestCase $this->assertEquals('10', Arr::get($data, 'data.id')); } - /** - * @test - */ + #[Test] public function rejects_request_for_non_existing_group() { $response = $this->send( diff --git a/framework/core/tests/integration/api/notifications/DeleteTest.php b/framework/core/tests/integration/api/notifications/DeleteTest.php index 27f257794..e72dc5f1e 100644 --- a/framework/core/tests/integration/api/notifications/DeleteTest.php +++ b/framework/core/tests/integration/api/notifications/DeleteTest.php @@ -14,6 +14,8 @@ use Flarum\Discussion\Discussion; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class DeleteTest extends TestCase { @@ -45,10 +47,8 @@ class DeleteTest extends TestCase ]); } - /** - * @dataProvider canDeleteAllNotifications - * @test - */ + #[Test] + #[DataProvider('canDeleteAllNotifications')] public function user_can_delete_all_notifications(int $authenticatedAs) { $this->app(); @@ -63,7 +63,7 @@ class DeleteTest extends TestCase $this->assertEquals(0, User::query()->find($authenticatedAs)->notifications()->count()); } - public function canDeleteAllNotifications(): array + public static function canDeleteAllNotifications(): array { return [ [1], diff --git a/framework/core/tests/integration/api/notifications/ListTest.php b/framework/core/tests/integration/api/notifications/ListTest.php index 4ed6868ec..0fd8f45da 100644 --- a/framework/core/tests/integration/api/notifications/ListTest.php +++ b/framework/core/tests/integration/api/notifications/ListTest.php @@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\api\notifications; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class ListTest extends TestCase { @@ -31,9 +32,7 @@ class ListTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function disallows_index_for_guest() { $response = $this->send( @@ -43,9 +42,7 @@ class ListTest extends TestCase $this->assertEquals(401, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function shows_index_for_user() { $response = $this->send( diff --git a/framework/core/tests/integration/api/notifications/UpdateTest.php b/framework/core/tests/integration/api/notifications/UpdateTest.php index 331c7d84d..76403cf88 100644 --- a/framework/core/tests/integration/api/notifications/UpdateTest.php +++ b/framework/core/tests/integration/api/notifications/UpdateTest.php @@ -16,6 +16,7 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class UpdateTest extends TestCase { @@ -44,9 +45,7 @@ class UpdateTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function can_mark_all_as_read() { $response = $this->send( diff --git a/framework/core/tests/integration/api/posts/CreateTest.php b/framework/core/tests/integration/api/posts/CreateTest.php index 75079074a..a144daba1 100644 --- a/framework/core/tests/integration/api/posts/CreateTest.php +++ b/framework/core/tests/integration/api/posts/CreateTest.php @@ -16,6 +16,8 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class CreateTest extends TestCase { @@ -53,10 +55,8 @@ class CreateTest extends TestCase ]); } - /** - * @dataProvider discussionRepliesPrvider - * @test - */ + #[Test] + #[DataProvider('discussionRepliesPrvider')] public function can_create_reply_if_allowed(int $actorId, int $discussionId, int $responseStatus) { // Reset permissions for normal users group. @@ -88,7 +88,7 @@ class CreateTest extends TestCase $this->assertEquals($responseStatus, $response->getStatusCode(), (string) $response->getBody()); } - public function discussionRepliesPrvider(): array + public static function discussionRepliesPrvider(): array { return [ // [$actorId, $discussionId, $responseStatus] @@ -99,9 +99,7 @@ class CreateTest extends TestCase ]; } - /** - * @test - */ + #[Test] public function limited_by_throttler() { $response = $this->send( diff --git a/framework/core/tests/integration/api/posts/DeleteTest.php b/framework/core/tests/integration/api/posts/DeleteTest.php index 1bcb021bf..962231d88 100644 --- a/framework/core/tests/integration/api/posts/DeleteTest.php +++ b/framework/core/tests/integration/api/posts/DeleteTest.php @@ -16,6 +16,8 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class DeleteTest extends TestCase { @@ -52,10 +54,8 @@ class DeleteTest extends TestCase ]); } - /** - * @dataProvider deleteLastPostsProvider - * @test - */ + #[Test] + #[DataProvider('deleteLastPostsProvider')] public function deleting_last_posts_syncs_discussion_state_for_other_users(array $postIds, int $newLastReadNumber, int $userId) { // Delete the last post. @@ -76,7 +76,7 @@ class DeleteTest extends TestCase ); } - public function deleteLastPostsProvider(): array + public static function deleteLastPostsProvider(): array { return [ // User 2 diff --git a/framework/core/tests/integration/api/posts/ListTest.php b/framework/core/tests/integration/api/posts/ListTest.php index e6f8caf4e..6ef426171 100644 --- a/framework/core/tests/integration/api/posts/ListTest.php +++ b/framework/core/tests/integration/api/posts/ListTest.php @@ -16,6 +16,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class ListTest extends TestCase { @@ -48,9 +49,7 @@ class ListTest extends TestCase $this->database()->table('group_permission')->where('permission', 'viewForum')->where('group_id', 2)->delete(); } - /** - * @test - */ + #[Test] public function guests_cant_see_anything_if_not_allowed() { $this->forbidGuestsFromSeeingForum(); @@ -65,9 +64,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing([], $data['data']); } - /** - * @test - */ + #[Test] public function authorized_users_can_see_posts() { $response = $this->send( @@ -82,9 +79,7 @@ class ListTest extends TestCase $this->assertEquals(5, count($data['data'])); } - /** - * @test - */ + #[Test] public function author_filter_works() { $response = $this->send( @@ -100,9 +95,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(['1', '2'], Arr::pluck($data['data'], 'id')); } - /** - * @test - */ + #[Test] public function author_filter_works_with_multiple_values() { $response = $this->send( @@ -118,9 +111,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(['1', '2', '3', '4', '5'], Arr::pluck($data['data'], 'id')); } - /** - * @test - */ + #[Test] public function discussion_filter_works() { $response = $this->send( @@ -136,9 +127,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(['1', '3'], Arr::pluck($data['data'], 'id')); } - /** - * @test - */ + #[Test] public function type_filter_works() { $response = $this->send( @@ -154,9 +143,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(['5'], Arr::pluck($data['data'], 'id')); } - /** - * @test - */ + #[Test] public function number_filter_works() { $response = $this->send( @@ -172,9 +159,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(['3', '4'], Arr::pluck($data['data'], 'id')); } - /** - * @test - */ + #[Test] public function id_filter_works() { $response = $this->send( @@ -190,9 +175,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(['4'], Arr::pluck($data['data'], 'id')); } - /** - * @test - */ + #[Test] public function id_filter_works_with_multiple_ids() { $response = $this->send( diff --git a/framework/core/tests/integration/api/posts/ShowTest.php b/framework/core/tests/integration/api/posts/ShowTest.php index cf6d3b80d..21b7ef086 100644 --- a/framework/core/tests/integration/api/posts/ShowTest.php +++ b/framework/core/tests/integration/api/posts/ShowTest.php @@ -15,6 +15,7 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class ShowTest extends TestCase { @@ -41,9 +42,7 @@ class ShowTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function properly_formatted_post_rendered_correctly() { $response = $this->send( @@ -62,9 +61,7 @@ class ShowTest extends TestCase $this->assertEquals($data['data']['attributes']['contentHtml'], '

valid

'); } - /** - * @test - */ + #[Test] public function malformed_post_caught_by_renderer() { $response = $this->send( diff --git a/framework/core/tests/integration/api/settings/SetTest.php b/framework/core/tests/integration/api/settings/SetTest.php index d8cbef337..a51c52020 100644 --- a/framework/core/tests/integration/api/settings/SetTest.php +++ b/framework/core/tests/integration/api/settings/SetTest.php @@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\api\settings; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class SetTest extends TestCase { @@ -31,9 +32,7 @@ class SetTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function settings_cant_be_updated_by_user() { $response = $this->send( @@ -49,9 +48,7 @@ class SetTest extends TestCase $this->assertNotEquals('world', $this->app->getContainer()->make('flarum.settings')->get('hello')); } - /** - * @test - */ + #[Test] public function settings_can_be_updated_by_admin() { $response = $this->send( @@ -67,9 +64,7 @@ class SetTest extends TestCase $this->assertEquals('world', $this->app->getContainer()->make('flarum.settings')->get('hello')); } - /** - * @test - */ + #[Test] public function max_setting_length_validated() { $response = $this->send( diff --git a/framework/core/tests/integration/api/users/CreateTest.php b/framework/core/tests/integration/api/users/CreateTest.php index 7c400cff8..5fce8fba8 100644 --- a/framework/core/tests/integration/api/users/CreateTest.php +++ b/framework/core/tests/integration/api/users/CreateTest.php @@ -14,6 +14,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\RegistrationToken; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class CreateTest extends TestCase { @@ -29,9 +30,7 @@ class CreateTest extends TestCase $this->setting('mail_driver', 'log'); } - /** - * @test - */ + #[Test] public function cannot_create_user_without_data() { $response = $this->send( @@ -77,9 +76,7 @@ class CreateTest extends TestCase ], json_decode($body, true)); } - /** - * @test - */ + #[Test] public function can_create_user() { $response = $this->send( @@ -110,9 +107,7 @@ class CreateTest extends TestCase $this->assertEquals('test@machine.local', $user->email); } - /** - * @test - */ + #[Test] public function admins_can_create_activated_users() { $response = $this->send( @@ -143,9 +138,7 @@ class CreateTest extends TestCase $this->assertEquals(1, $user->is_email_confirmed); } - /** - * @test - */ + #[Test] public function disabling_sign_up_prevents_user_creation() { /** @var SettingsRepositoryInterface $settings */ @@ -174,9 +167,7 @@ class CreateTest extends TestCase $settings->set('allow_sign_up', true); } - /** - * @test - */ + #[Test] public function cannot_create_user_with_invalid_avatar_uri_scheme() { // Boot app @@ -240,9 +231,7 @@ class CreateTest extends TestCase } } - /** - * @test - */ + #[Test] public function cannot_create_user_with_invalid_avatar_uri() { // Boot app @@ -314,9 +303,7 @@ class CreateTest extends TestCase } } - /** - * @test - */ + #[Test] public function can_create_user_with_valid_avatar_uri() { // Boot app diff --git a/framework/core/tests/integration/api/users/DeleteTest.php b/framework/core/tests/integration/api/users/DeleteTest.php index 099b5dd8c..1edab12bc 100644 --- a/framework/core/tests/integration/api/users/DeleteTest.php +++ b/framework/core/tests/integration/api/users/DeleteTest.php @@ -12,6 +12,8 @@ namespace integration\api\users; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class DeleteTest extends TestCase { @@ -33,10 +35,8 @@ class DeleteTest extends TestCase ]); } - /** - * @dataProvider authorizedUsersProvider - * @test - */ + #[Test] + #[DataProvider('authorizedUsersProvider')] public function can_delete_user(int $actorId, int $userId) { $this->database()->table('group_permission')->insert([ @@ -54,7 +54,7 @@ class DeleteTest extends TestCase $this->assertNull(User::find($userId)); } - public function authorizedUsersProvider() + public static function authorizedUsersProvider() { return [ 'admin can delete user' => [1, 2], @@ -63,10 +63,8 @@ class DeleteTest extends TestCase ]; } - /** - * @dataProvider unauthorizedUsersProvider - * @test - */ + #[Test] + #[DataProvider('unauthorizedUsersProvider')] public function cannot_delete_user(int $actorId, int $userId) { $response = $this->send( @@ -79,7 +77,7 @@ class DeleteTest extends TestCase $this->assertNotNull(User::find($userId)); } - public function unauthorizedUsersProvider() + public static function unauthorizedUsersProvider() { return [ 'user without permission cannot delete self' => [2, 2], diff --git a/framework/core/tests/integration/api/users/GroupSearchTest.php b/framework/core/tests/integration/api/users/GroupSearchTest.php index 63f1a84eb..75d453fb1 100644 --- a/framework/core/tests/integration/api/users/GroupSearchTest.php +++ b/framework/core/tests/integration/api/users/GroupSearchTest.php @@ -13,6 +13,7 @@ use Flarum\Group\Group; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class GroupSearchTest extends TestCase { @@ -29,9 +30,7 @@ class GroupSearchTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function disallows_group_filter_for_user_without_permission() { $response = $this->createRequest(['admin']); @@ -39,9 +38,7 @@ class GroupSearchTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function allows_group_filter_for_admin() { $response = $this->createRequest(['admin'], 1); @@ -49,9 +46,7 @@ class GroupSearchTest extends TestCase $this->assertEquals(200, $response->getStatusCode(), $response->getBody()->getContents()); } - /** - * @test - */ + #[Test] public function allows_group_filter_for_user_with_permission() { $this->prepareDatabase([ @@ -64,9 +59,7 @@ class GroupSearchTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function non_admin_gets_correct_results() { $this->prepareDatabase([ @@ -115,9 +108,7 @@ class GroupSearchTest extends TestCase $this->assertCount(0, $responseBodyContents['included'], json_encode($responseBodyContents)); } - /** - * @test - */ + #[Test] public function non_admin_cannot_see_hidden_groups() { $this->prepareDatabase([ @@ -134,9 +125,7 @@ class GroupSearchTest extends TestCase $this->assertCount(0, $responseBodyContents['included'], json_encode($responseBodyContents)); } - /** - * @test - */ + #[Test] public function non_admin_can_select_multiple_groups_but_not_hidden() { $this->prepareDatabase([ @@ -153,9 +142,7 @@ class GroupSearchTest extends TestCase $this->assertEqualsCanonicalizing([1, 4, 5, 6], array_column($responseBodyContents['included'], 'id')); } - /** - * @test - */ + #[Test] public function admin_gets_correct_results_group() { $response = $this->createRequest(['admin'], 1); @@ -198,9 +185,7 @@ class GroupSearchTest extends TestCase $this->assertCount(0, $responseBodyContents['included'], json_encode($responseBodyContents)); } - /** - * @test - */ + #[Test] public function admin_can_see_hidden_groups() { $this->createHiddenUser(); @@ -212,9 +197,7 @@ class GroupSearchTest extends TestCase $this->assertEquals(99, $responseBodyContents['included'][0]['id']); } - /** - * @test - */ + #[Test] public function admin_can_select_multiple_groups_and_hidden() { $this->createMultipleUsersAndGroups(); diff --git a/framework/core/tests/integration/api/users/ListTest.php b/framework/core/tests/integration/api/users/ListTest.php index ef21abc4c..815d38d3f 100644 --- a/framework/core/tests/integration/api/users/ListTest.php +++ b/framework/core/tests/integration/api/users/ListTest.php @@ -13,6 +13,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class ListTest extends TestCase { @@ -32,9 +33,7 @@ class ListTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function disallows_index_for_guest() { $response = $this->send( @@ -44,9 +43,7 @@ class ListTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function shows_index_for_guest_when_they_have_permission() { $this->prepareDatabase([ @@ -62,9 +59,7 @@ class ListTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function shows_index_for_admin() { $response = $this->send( @@ -76,9 +71,7 @@ class ListTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function shows_full_results_without_search_or_filter() { $response = $this->send( @@ -92,9 +85,7 @@ class ListTest extends TestCase $this->assertEqualsCanonicalizing(['1', '2'], Arr::pluck($data, 'id')); } - /** - * @test - */ + #[Test] public function allows_last_seen_sorting_with_permission() { $this->prepareDatabase([ @@ -114,9 +105,7 @@ class ListTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function disallows_last_seen_sorting_without_permission() { $this->prepareDatabase([ @@ -135,9 +124,7 @@ class ListTest extends TestCase $this->assertEquals(400, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function group_filter_works() { $response = $this->send( @@ -153,9 +140,7 @@ class ListTest extends TestCase $this->assertEquals(['1'], Arr::pluck($data, 'id')); } - /** - * @test - */ + #[Test] public function group_filter_works_negated() { $response = $this->send( @@ -171,9 +156,7 @@ class ListTest extends TestCase $this->assertEquals(['2'], Arr::pluck($data, 'id')); } - /** - * @test - */ + #[Test] public function email_filter_works() { $response = $this->send( @@ -189,9 +172,7 @@ class ListTest extends TestCase $this->assertEquals(['1'], Arr::pluck($data, 'id')); } - /** - * @test - */ + #[Test] public function email_filter_works_negated() { $response = $this->send( @@ -207,9 +188,7 @@ class ListTest extends TestCase $this->assertEquals(['2'], Arr::pluck($data, 'id')); } - /** - * @test - */ + #[Test] public function email_filter_only_works_for_admin() { $response = $this->send( diff --git a/framework/core/tests/integration/api/users/PasswordEmailTokensTest.php b/framework/core/tests/integration/api/users/PasswordEmailTokensTest.php index 5d373f85f..59e129afb 100644 --- a/framework/core/tests/integration/api/users/PasswordEmailTokensTest.php +++ b/framework/core/tests/integration/api/users/PasswordEmailTokensTest.php @@ -14,6 +14,7 @@ use Flarum\Testing\integration\TestCase; use Flarum\User\EmailToken; use Flarum\User\PasswordToken; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class PasswordEmailTokensTest extends TestCase { @@ -30,7 +31,7 @@ class PasswordEmailTokensTest extends TestCase ]); } - /** @test */ + #[Test] public function actor_has_no_tokens_by_default() { $this->app(); @@ -39,7 +40,7 @@ class PasswordEmailTokensTest extends TestCase $this->assertEquals(0, EmailToken::query()->where('user_id', 2)->count()); } - /** @test */ + #[Test] public function password_tokens_are_generated_when_requesting_password_reset() { $response = $this->send( @@ -55,7 +56,7 @@ class PasswordEmailTokensTest extends TestCase $this->assertEquals(1, PasswordToken::query()->where('user_id', 2)->count()); } - /** @test */ + #[Test] public function password_tokens_are_deleted_after_password_reset() { $this->app(); @@ -94,7 +95,7 @@ class PasswordEmailTokensTest extends TestCase $this->assertEquals(0, PasswordToken::query()->where('user_id', 2)->count()); } - /** @test */ + #[Test] public function email_tokens_are_generated_when_requesting_email_change() { $response = $this->send( @@ -118,7 +119,7 @@ class PasswordEmailTokensTest extends TestCase $this->assertEquals(1, EmailToken::query()->where('user_id', 2)->count()); } - /** @test */ + #[Test] public function email_tokens_are_deleted_when_confirming_email() { $this->app(); @@ -140,7 +141,7 @@ class PasswordEmailTokensTest extends TestCase $this->assertEquals(0, EmailToken::query()->where('user_id', 2)->count()); } - /** @test */ + #[Test] public function email_tokens_are_deleted_after_password_reset() { $this->app(); @@ -179,7 +180,7 @@ class PasswordEmailTokensTest extends TestCase $this->assertEquals(0, EmailToken::query()->where('user_id', 2)->count()); } - /** @test */ + #[Test] public function password_tokens_are_deleted_when_confirming_email() { $this->app(); diff --git a/framework/core/tests/integration/api/users/SendActivationEmailTest.php b/framework/core/tests/integration/api/users/SendActivationEmailTest.php index 3d0149eba..3bd48c4cf 100644 --- a/framework/core/tests/integration/api/users/SendActivationEmailTest.php +++ b/framework/core/tests/integration/api/users/SendActivationEmailTest.php @@ -13,6 +13,7 @@ use Carbon\Carbon; use Flarum\Testing\integration\TestCase; use Flarum\User\Throttler\EmailActivationThrottler; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class SendActivationEmailTest extends TestCase { @@ -34,7 +35,7 @@ class SendActivationEmailTest extends TestCase ]); } - /** @test */ + #[Test] public function users_can_send_confirmation_emails_in_moderate_intervals() { for ($i = 0; $i < 2; $i++) { @@ -52,7 +53,7 @@ class SendActivationEmailTest extends TestCase $this->assertEquals(204, $response->getStatusCode()); } - /** @test */ + #[Test] public function users_cant_send_confirmation_emails_too_fast() { for ($i = 0; $i < 2; $i++) { diff --git a/framework/core/tests/integration/api/users/SendPasswordResetEmailTest.php b/framework/core/tests/integration/api/users/SendPasswordResetEmailTest.php index 4c46536a1..a7472c850 100644 --- a/framework/core/tests/integration/api/users/SendPasswordResetEmailTest.php +++ b/framework/core/tests/integration/api/users/SendPasswordResetEmailTest.php @@ -13,6 +13,7 @@ use Carbon\Carbon; use Flarum\Testing\integration\TestCase; use Flarum\User\Throttler\PasswordResetThrottler; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class SendPasswordResetEmailTest extends TestCase { @@ -34,7 +35,7 @@ class SendPasswordResetEmailTest extends TestCase ]); } - /** @test */ + #[Test] public function users_can_send_password_reset_emails_in_moderate_intervals() { for ($i = 0; $i < 2; $i++) { @@ -55,7 +56,7 @@ class SendPasswordResetEmailTest extends TestCase $this->assertEquals(204, $response->getStatusCode()); } - /** @test */ + #[Test] public function users_cant_send_confirmation_emails_too_fast() { for ($i = 0; $i < 2; $i++) { @@ -72,7 +73,7 @@ class SendPasswordResetEmailTest extends TestCase $this->assertEquals(429, $response->getStatusCode()); } - /** @test */ + #[Test] public function request_password_reset_does_not_leak_user_existence() { $response = $this->send( diff --git a/framework/core/tests/integration/api/users/ShowTest.php b/framework/core/tests/integration/api/users/ShowTest.php index 6050efc68..9af936581 100644 --- a/framework/core/tests/integration/api/users/ShowTest.php +++ b/framework/core/tests/integration/api/users/ShowTest.php @@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\api\users; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class ShowTest extends TestCase { @@ -41,9 +42,7 @@ class ShowTest extends TestCase $this->database()->table('group_permission')->where('permission', 'searchUsers')->where('group_id', 3)->delete(); } - /** - * @test - */ + #[Test] public function admin_can_see_user() { $response = $this->send( @@ -55,9 +54,7 @@ class ShowTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function admin_can_see_user_via_slug() { $response = $this->send( @@ -71,9 +68,7 @@ class ShowTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function guest_can_see_user_by_default() { $response = $this->send( @@ -83,9 +78,7 @@ class ShowTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function guest_can_see_user_by_slug_by_default() { $response = $this->send( @@ -97,9 +90,7 @@ class ShowTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function guest_cant_see_user_if_blocked() { $this->forbidGuestsFromSeeingForum(); @@ -111,9 +102,7 @@ class ShowTest extends TestCase $this->assertEquals(404, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function guest_cant_see_user_by_slug_if_blocked() { $this->forbidGuestsFromSeeingForum(); @@ -127,9 +116,7 @@ class ShowTest extends TestCase $this->assertEquals(404, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_can_see_themselves() { $response = $this->send( @@ -141,9 +128,7 @@ class ShowTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_can_see_themselves_via_slug() { $response = $this->send( @@ -157,9 +142,7 @@ class ShowTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_can_see_others_by_default() { $response = $this->send( @@ -171,9 +154,7 @@ class ShowTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_can_see_others_by_default_via_slug() { $response = $this->send( @@ -187,9 +168,7 @@ class ShowTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function user_can_still_see_others_via_slug_even_if_cant_search() { $this->forbidMembersFromSearchingUsers(); diff --git a/framework/core/tests/integration/api/users/UpdateTest.php b/framework/core/tests/integration/api/users/UpdateTest.php index 353c96046..970af5634 100644 --- a/framework/core/tests/integration/api/users/UpdateTest.php +++ b/framework/core/tests/integration/api/users/UpdateTest.php @@ -14,6 +14,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\Throttler\EmailChangeThrottler; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class UpdateTest extends TestCase { @@ -60,9 +61,7 @@ class UpdateTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function users_can_see_their_private_information() { $response = $this->send( @@ -79,9 +78,7 @@ class UpdateTest extends TestCase $this->assertStringContainsString('normal@machine.local', $body); } - /** - * @test - */ + #[Test] public function users_can_not_see_other_users_private_information() { $response = $this->send( @@ -99,10 +96,9 @@ class UpdateTest extends TestCase } /** - * @test - * - * This tests the generic user.edit permission used for non-credential/group attributes + * This tests the generic user.edit permission used for non-credential/group attributes. */ + #[Test] public function users_can_update_own_avatar() { $response = $this->send( @@ -114,9 +110,7 @@ class UpdateTest extends TestCase $this->assertEquals(200, $response->getStatusCode(), (string) $response->getBody()); } - /** - * @test - */ + #[Test] public function users_cant_update_own_email_if_password_wrong() { $response = $this->send( @@ -139,9 +133,7 @@ class UpdateTest extends TestCase $this->assertEquals(401, $response->getStatusCode(), (string) $response->getBody()); } - /** - * @test - */ + #[Test] public function users_can_update_own_email() { $response = $this->send( @@ -163,9 +155,7 @@ class UpdateTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_can_request_email_change_in_moderate_intervals() { for ($i = 0; $i < 2; $i++) { @@ -193,9 +183,7 @@ class UpdateTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_cant_request_email_change_too_fast() { for ($i = 0; $i < 2; $i++) { @@ -219,9 +207,7 @@ class UpdateTest extends TestCase $this->assertEquals(429, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_cant_update_own_username() { $response = $this->send( @@ -240,9 +226,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_can_update_own_preferences() { $response = $this->send( @@ -263,9 +247,7 @@ class UpdateTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_cant_update_own_groups() { $response = $this->send( @@ -287,9 +269,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_can_update_marked_all_as_read() { $response = $this->send( @@ -308,9 +288,7 @@ class UpdateTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_cant_activate_themselves() { $response = $this->send( @@ -330,10 +308,9 @@ class UpdateTest extends TestCase } /** - * @test - * - * This tests the generic user.edit permission used for non-credential/group attributes + * This tests the generic user.edit permission used for non-credential/group attributes. */ + #[Test] public function users_cant_update_others_avatars_without_permission() { $response = $this->send( @@ -345,9 +322,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_cant_update_others_emails_without_permission() { $response = $this->send( @@ -369,9 +344,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_cant_update_others_usernames_without_permission() { $response = $this->send( @@ -390,9 +363,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_cant_update_others_groups_without_permission() { $response = $this->send( @@ -414,9 +385,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_cant_activate_others_without_permission() { $response = $this->send( @@ -436,10 +405,9 @@ class UpdateTest extends TestCase } /** - * @test - * - * This tests the generic user.edit permission used for non-credential/group attributes + * This tests the generic user.edit permission used for non-credential/group attributes. */ + #[Test] public function users_can_update_others_avatars_with_permissions() { $this->giveNormalUsersEditPerms(); @@ -452,9 +420,7 @@ class UpdateTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_can_update_others_emails_with_permission() { $this->giveNormalUsersEditPerms(); @@ -474,9 +440,7 @@ class UpdateTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_can_update_others_usernames_with_permission() { $this->giveNormalUsersEditPerms(); @@ -496,9 +460,7 @@ class UpdateTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_cant_update_admin_emails_with_permission() { $this->giveNormalUsersEditPerms(); @@ -518,9 +480,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_cant_update_admin_usernames_with_permission() { $this->giveNormalUsersEditPerms(); @@ -540,9 +500,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_can_update_others_groups_with_permission() { $this->giveNormalUsersEditPerms(); @@ -565,9 +523,7 @@ class UpdateTest extends TestCase $this->assertEquals(200, $response->getStatusCode(), (string) $response->getBody()); } - /** - * @test - */ + #[Test] public function regular_users_cant_demote_admins_even_with_permission() { $this->giveNormalUsersEditPerms(); @@ -588,9 +544,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function regular_users_cant_promote_others_to_admin_even_with_permission() { $this->giveNormalUsersEditPerms(); @@ -613,9 +567,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function regular_users_cant_promote_self_to_admin_even_with_permission() { $this->giveNormalUsersEditPerms(); @@ -638,9 +590,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function users_cant_activate_others_even_with_permissions() { $this->giveNormalUsersEditPerms(); @@ -660,9 +610,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function admins_cant_update_others_preferences() { $response = $this->send( @@ -683,9 +631,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function admins_cant_update_marked_all_as_read() { $response = $this->send( @@ -704,9 +650,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function admins_can_activate_others() { $response = $this->send( @@ -725,9 +669,7 @@ class UpdateTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function admins_cant_demote_self() { $this->giveNormalUsersEditPerms(); @@ -748,9 +690,7 @@ class UpdateTest extends TestCase $this->assertEquals(403, $response->getStatusCode(), (string) $response->getBody()); } - /** - * @test - */ + #[Test] public function last_seen_not_updated_quickly() { $this->app(); @@ -769,9 +709,7 @@ class UpdateTest extends TestCase $this->assertTrue(Carbon::parse($last_seen)->equalTo($user->last_seen_at)); } - /** - * @test - */ + #[Test] public function last_seen_updated_after_long_time() { $this->app(); diff --git a/framework/core/tests/integration/extenders/ApiControllerTest.php b/framework/core/tests/integration/extenders/ApiControllerTest.php index 5fe3fa832..340ecde5f 100644 --- a/framework/core/tests/integration/extenders/ApiControllerTest.php +++ b/framework/core/tests/integration/extenders/ApiControllerTest.php @@ -26,6 +26,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; use Tobyz\JsonApiServer\Schema\Field\Field; class ApiControllerTest extends TestCase @@ -57,9 +58,7 @@ class ApiControllerTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function after_endpoint_callback_works_if_added() { $this->extend( @@ -84,9 +83,7 @@ class ApiControllerTest extends TestCase $this->assertEquals('dataSerializationPrepCustomTitle', $payload['data']['attributes']['title'], $body); } - /** - * @test - */ + #[Test] public function after_endpoint_callback_works_with_invokable_classes() { $this->extend( @@ -107,9 +104,7 @@ class ApiControllerTest extends TestCase $this->assertEquals(CustomAfterEndpointInvokableClass::class, $payload['data']['attributes']['title'], $body); } - /** - * @test - */ + #[Test] public function after_endpoint_callback_works_if_added_to_parent_class() { $this->extend( @@ -136,9 +131,7 @@ class ApiControllerTest extends TestCase $this->assertEquals('dataSerializationPrepCustomTitle2', $payload['data']['attributes']['title']); } - /** - * @test - */ + #[Test] public function after_endpoint_callback_prioritizes_child_classes() { $this->extend( @@ -173,9 +166,7 @@ class ApiControllerTest extends TestCase $this->assertEquals('dataSerializationPrepCustomTitle4', $payload['data']['attributes']['title'], $body); } - /** - * @test - */ + #[Test] public function before_endpoint_callback_works_if_added_to_parent_class() { $this->extend( @@ -199,9 +190,7 @@ class ApiControllerTest extends TestCase $this->assertStringContainsString('error on purpose', $body, $body); } - /** - * @test - */ + #[Test] public function before_endpoint_callback_prioritizes_child_classes() { $this->extend( @@ -231,9 +220,7 @@ class ApiControllerTest extends TestCase $this->assertStringContainsString('error on purpose from abstract resource', $body, $body); } - /** - * @test - */ + #[Test] public function custom_relationship_not_included_by_default() { $response = $this->send( @@ -248,9 +235,7 @@ class ApiControllerTest extends TestCase $this->assertArrayNotHasKey('customApiControllerRelation2', $payload['data']['relationships']); } - /** - * @test - */ + #[Test] public function custom_relationship_included_if_added() { $this->extend( @@ -278,9 +263,7 @@ class ApiControllerTest extends TestCase $this->assertArrayHasKey('customApiControllerRelation', $payload['data']['relationships'] ?? [], $body); } - /** - * @test - */ + #[Test] public function custom_relationship_optionally_included_if_added() { $this->extend( @@ -307,9 +290,7 @@ class ApiControllerTest extends TestCase $this->assertArrayHasKey('customApiControllerRelation2', $payload['data']['relationships'] ?? []); } - /** - * @test - */ + #[Test] public function custom_relationship_included_by_default() { $response = $this->send( @@ -323,9 +304,7 @@ class ApiControllerTest extends TestCase $this->assertArrayHasKey('groups', $payload['data']['relationships']); } - /** - * @test - */ + #[Test] public function custom_relationship_not_included_if_removed() { $this->extend( @@ -346,9 +325,7 @@ class ApiControllerTest extends TestCase $this->assertArrayNotHasKey('groups', Arr::get($payload, 'data.relationships', [])); } - /** - * @test - */ + #[Test] public function custom_relationship_not_optionally_included_if_removed() { $this->extend( @@ -374,9 +351,7 @@ class ApiControllerTest extends TestCase $this->assertEquals(400, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function custom_limit_doesnt_work_by_default() { $response = $this->send( @@ -390,9 +365,7 @@ class ApiControllerTest extends TestCase $this->assertCount(3, $payload['data']); } - /** - * @test - */ + #[Test] public function custom_limit_works_if_set() { $this->extend( @@ -413,9 +386,7 @@ class ApiControllerTest extends TestCase $this->assertCount(1, $payload['data']); } - /** - * @test - */ + #[Test] public function custom_max_limit_works_if_set() { $this->extend( @@ -438,9 +409,7 @@ class ApiControllerTest extends TestCase $this->assertCount(1, $payload['data']); } - /** - * @test - */ + #[Test] public function custom_sort_field_doesnt_exist_by_default() { $response = $this->send( @@ -454,9 +423,7 @@ class ApiControllerTest extends TestCase $this->assertEquals(400, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function custom_sort_field_exists_if_added() { $this->extend( @@ -480,9 +447,7 @@ class ApiControllerTest extends TestCase $this->assertEquals([3, 1, 2], Arr::pluck($payload['data'], 'id')); } - /** - * @test - */ + #[Test] public function custom_sort_field_exists_by_default() { $response = $this->send( @@ -496,9 +461,7 @@ class ApiControllerTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function custom_sort_field_doesnt_exist_if_removed() { $this->extend( @@ -517,9 +480,7 @@ class ApiControllerTest extends TestCase $this->assertEquals(400, $response->getStatusCode(), $response->getBody()->getContents()); } - /** - * @test - */ + #[Test] public function custom_sort_field_works_if_set() { $this->extend( @@ -544,9 +505,7 @@ class ApiControllerTest extends TestCase $this->assertEquals([2, 1, 3], Arr::pluck($payload['data'], 'id')); } - /** - * @test - */ + #[Test] public function custom_first_level_relation_is_not_loaded_by_default() { $users = null; @@ -573,9 +532,7 @@ class ApiControllerTest extends TestCase $this->assertTrue($users->filter->relationLoaded('firstLevelRelation')->isEmpty()); } - /** - * @test - */ + #[Test] public function custom_first_level_relation_is_loaded_if_added() { $users = null; @@ -604,9 +561,7 @@ class ApiControllerTest extends TestCase $this->assertFalse($users->filter->relationLoaded('firstLevelRelation')->isEmpty(), $response->getBody()->getContents()); } - /** - * @test - */ + #[Test] public function custom_second_level_relation_is_not_loaded_by_default() { $users = null; @@ -634,9 +589,7 @@ class ApiControllerTest extends TestCase $this->assertTrue($users->pluck('firstLevelRelation')->filter->relationLoaded('secondLevelRelation')->isEmpty()); } - /** - * @test - */ + #[Test] public function custom_second_level_relation_is_loaded_if_added() { $users = null; @@ -667,9 +620,7 @@ class ApiControllerTest extends TestCase $this->assertFalse($users->pluck('firstLevelRelation')->filter->relationLoaded('secondLevelRelation')->isEmpty()); } - /** - * @test - */ + #[Test] public function custom_second_level_relation_is_not_loaded_when_first_level_is_not() { $users = null; @@ -698,9 +649,7 @@ class ApiControllerTest extends TestCase $this->assertTrue($users->pluck('firstLevelRelation')->filter->relationLoaded('secondLevelRelation')->isEmpty()); } - /** - * @test - */ + #[Test] public function custom_callable_first_level_relation_is_loaded_if_added() { $users = null; @@ -729,9 +678,7 @@ class ApiControllerTest extends TestCase $this->assertFalse($users->filter->relationLoaded('firstLevelRelation')->isEmpty()); } - /** - * @test - */ + #[Test] public function custom_callable_second_level_relation_is_loaded_if_added() { $users = null; diff --git a/framework/core/tests/integration/extenders/ApiSerializerTest.php b/framework/core/tests/integration/extenders/ApiSerializerTest.php index c0281ea3b..e588833bb 100644 --- a/framework/core/tests/integration/extenders/ApiSerializerTest.php +++ b/framework/core/tests/integration/extenders/ApiSerializerTest.php @@ -21,6 +21,7 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class ApiSerializerTest extends TestCase { @@ -48,9 +49,7 @@ class ApiSerializerTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function custom_attributes_dont_exist_by_default() { $this->app(); @@ -66,9 +65,7 @@ class ApiSerializerTest extends TestCase $this->assertArrayNotHasKey('customAttribute', $payload['data']['attributes']); } - /** - * @test - */ + #[Test] public function custom_attributes_exist_if_added() { $this->extend( @@ -92,9 +89,7 @@ class ApiSerializerTest extends TestCase $this->assertArrayHasKey('customAttribute', $payload['data']['attributes']); } - /** - * @test - */ + #[Test] public function custom_attributes_with_invokable_exist_if_added() { $this->extend( @@ -115,9 +110,7 @@ class ApiSerializerTest extends TestCase $this->assertArrayHasKey('customAttributeFromInvokable', $payload['data']['attributes']); } - /** - * @test - */ + #[Test] public function custom_attributes_exist_if_added_to_parent_class() { $this->extend( @@ -141,9 +134,7 @@ class ApiSerializerTest extends TestCase $this->assertArrayHasKey('customAttribute', $payload['data']['attributes']); } - /** - * @test - */ + #[Test] public function custom_attributes_prioritize_child_classes() { $this->extend( @@ -173,9 +164,7 @@ class ApiSerializerTest extends TestCase $this->assertEquals('newValue', $payload['data']['attributes']['customAttribute']); } - /** - * @test - */ + #[Test] public function custom_attributes_can_be_overriden() { $this->extend( @@ -212,9 +201,7 @@ class ApiSerializerTest extends TestCase $this->assertEquals('newValue', $payload['data']['attributes']['someOtherCustomAttribute']); } - /** - * @test - */ + #[Test] public function custom_relations_dont_exist_by_default() { $this->extend( @@ -233,9 +220,7 @@ class ApiSerializerTest extends TestCase $this->assertEquals(400, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function custom_hasMany_relationship_exists_if_added() { $this->extend( @@ -264,9 +249,7 @@ class ApiSerializerTest extends TestCase $this->assertCount(3, $responseJson['data']['relationships']['customSerializerRelation']['data']); } - /** - * @test - */ + #[Test] public function custom_hasOne_relationship_exists_if_added() { $this->extend( @@ -295,9 +278,7 @@ class ApiSerializerTest extends TestCase $this->assertEquals('discussions', $responseJson['data']['relationships']['customSerializerRelation']['data']['type']); } - /** - * @test - */ + #[Test] public function custom_relationship_is_inherited_to_child_classes() { $this->extend( diff --git a/framework/core/tests/integration/extenders/AuthTest.php b/framework/core/tests/integration/extenders/AuthTest.php index 41e024e88..cede18dfe 100644 --- a/framework/core/tests/integration/extenders/AuthTest.php +++ b/framework/core/tests/integration/extenders/AuthTest.php @@ -13,14 +13,13 @@ use Flarum\Extend; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class AuthTest extends TestCase { use RetrievesAuthorizedUsers; - /** - * @test - */ + #[Test] public function standard_password_works_by_default() { $this->app(); @@ -30,9 +29,7 @@ class AuthTest extends TestCase $this->assertTrue($user->checkPassword('password')); } - /** - * @test - */ + #[Test] public function standard_password_can_be_disabled() { $this->extend( @@ -47,9 +44,7 @@ class AuthTest extends TestCase $this->assertFalse($user->checkPassword('password')); } - /** - * @test - */ + #[Test] public function custom_checker_can_be_added() { $this->extend( @@ -65,9 +60,7 @@ class AuthTest extends TestCase $this->assertTrue($user->checkPassword('DefinitelyNotThePassword')); } - /** - * @test - */ + #[Test] public function false_checker_overrides_true() { $this->extend( diff --git a/framework/core/tests/integration/extenders/ConditionalTest.php b/framework/core/tests/integration/extenders/ConditionalTest.php index 666e3452f..91f30af68 100644 --- a/framework/core/tests/integration/extenders/ConditionalTest.php +++ b/framework/core/tests/integration/extenders/ConditionalTest.php @@ -16,12 +16,13 @@ use Flarum\Extend; use Flarum\Extension\ExtensionManager; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class ConditionalTest extends TestCase { use RetrievesAuthorizedUsers; - /** @test */ + #[Test] public function conditional_works_if_condition_is_primitive_true() { $this->extend( @@ -48,7 +49,7 @@ class ConditionalTest extends TestCase $this->assertArrayHasKey('customConditionalAttribute', $payload['data']['attributes']); } - /** @test */ + #[Test] public function conditional_does_not_work_if_condition_is_primitive_false() { $this->extend( @@ -75,7 +76,7 @@ class ConditionalTest extends TestCase $this->assertArrayNotHasKey('customConditionalAttribute', $payload['data']['attributes']); } - /** @test */ + #[Test] public function conditional_works_if_condition_is_callable_true() { $this->extend( @@ -102,7 +103,7 @@ class ConditionalTest extends TestCase $this->assertArrayHasKey('customConditionalAttribute', $payload['data']['attributes']); } - /** @test */ + #[Test] public function conditional_does_not_work_if_condition_is_callable_false() { $this->extend( @@ -129,7 +130,7 @@ class ConditionalTest extends TestCase $this->assertArrayNotHasKey('customConditionalAttribute', $payload['data']['attributes']); } - /** @test */ + #[Test] public function conditional_injects_dependencies_to_condition_callable() { $this->expectNotToPerformAssertions(); @@ -152,7 +153,7 @@ class ConditionalTest extends TestCase $this->app(); } - /** @test */ + #[Test] public function conditional_disabled_extension_not_enabled_applies_invokable_class() { $this->extend( @@ -173,7 +174,7 @@ class ConditionalTest extends TestCase $this->assertArrayHasKey('customConditionalAttribute', $payload['data']['attributes']); } - /** @test */ + #[Test] public function conditional_disabled_extension_enabled_does_not_apply_invokable_class() { $this->extension('flarum-tags'); @@ -197,7 +198,7 @@ class ConditionalTest extends TestCase $this->assertArrayNotHasKey('customConditionalAttribute', $payload['data']['attributes']); } - /** @test */ + #[Test] public function conditional_enabled_extension_disabled_does_not_apply_invokable_class() { $this->extend( @@ -218,7 +219,7 @@ class ConditionalTest extends TestCase $this->assertArrayNotHasKey('customConditionalAttribute', $payload['data']['attributes']); } - /** @test */ + #[Test] public function conditional_enabled_extension_enabled_applies_invokable_class() { $this->extension('flarum-tags'); @@ -241,7 +242,7 @@ class ConditionalTest extends TestCase $this->assertArrayHasKey('customConditionalAttribute', $payload['data']['attributes']); } - /** @test */ + #[Test] public function conditional_does_not_instantiate_extender_if_condition_is_false_using_callable() { $this->extend( @@ -262,7 +263,7 @@ class ConditionalTest extends TestCase $this->assertArrayNotHasKey('customConditionalAttribute', $payload['data']['attributes']); } - /** @test */ + #[Test] public function conditional_does_instantiate_extender_if_condition_is_true_using_callable() { $this->extend( @@ -283,7 +284,7 @@ class ConditionalTest extends TestCase $this->assertArrayHasKey('customConditionalAttribute', $payload['data']['attributes']); } - /** @test */ + #[Test] public function conditional_does_not_instantiate_extender_if_condition_is_false_using_callback() { $this->extend( @@ -310,7 +311,7 @@ class ConditionalTest extends TestCase $this->assertArrayNotHasKey('customConditionalAttribute', $payload['data']['attributes']); } - /** @test */ + #[Test] public function conditional_does_instantiate_extender_if_condition_is_true_using_callback() { $this->extend( @@ -337,7 +338,7 @@ class ConditionalTest extends TestCase $this->assertArrayHasKey('customConditionalAttribute', $payload['data']['attributes']); } - /** @test */ + #[Test] public function conditional_does_not_work_if_extension_is_disabled() { $this->extend( diff --git a/framework/core/tests/integration/extenders/ConsoleTest.php b/framework/core/tests/integration/extenders/ConsoleTest.php index f536ae77a..a1433f26c 100644 --- a/framework/core/tests/integration/extenders/ConsoleTest.php +++ b/framework/core/tests/integration/extenders/ConsoleTest.php @@ -13,14 +13,13 @@ use Flarum\Console\AbstractCommand; use Flarum\Extend; use Flarum\Testing\integration\ConsoleTestCase; use Illuminate\Console\Scheduling\Event; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\CommandNotFoundException; class ConsoleTest extends ConsoleTestCase { - /** - * @test - */ + #[Test] public function custom_command_doesnt_exist_by_default() { $input = [ @@ -31,9 +30,7 @@ class ConsoleTest extends ConsoleTestCase $this->runCommand($input); } - /** - * @test - */ + #[Test] public function custom_command_exists_when_added() { $this->extend( @@ -48,9 +45,7 @@ class ConsoleTest extends ConsoleTestCase $this->assertEquals('Custom Command.', $this->runCommand($input)); } - /** - * @test - */ + #[Test] public function scheduled_command_doesnt_exist_by_default() { $input = [ @@ -60,9 +55,7 @@ class ConsoleTest extends ConsoleTestCase $this->assertStringNotContainsString('cache:clear', $this->runCommand($input)); } - /** - * @test - */ + #[Test] public function scheduled_command_exists_when_added() { $this->extend( @@ -79,9 +72,7 @@ class ConsoleTest extends ConsoleTestCase $this->assertStringContainsString('cache:clear', $this->runCommand($input)); } - /** - * @test - */ + #[Test] public function scheduled_command_exists_when_added_with_class_syntax() { $this->extend( diff --git a/framework/core/tests/integration/extenders/CsrfTest.php b/framework/core/tests/integration/extenders/CsrfTest.php index 1c9f7c38f..af91ce7b5 100644 --- a/framework/core/tests/integration/extenders/CsrfTest.php +++ b/framework/core/tests/integration/extenders/CsrfTest.php @@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\extenders; use Flarum\Extend; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class CsrfTest extends TestCase { @@ -21,9 +22,7 @@ class CsrfTest extends TestCase 'email' => 'test@machine.local', ]; - /** - * @test - */ + #[Test] public function create_user_post_needs_csrf_token_by_default() { $response = $this->send( @@ -39,9 +38,7 @@ class CsrfTest extends TestCase $this->assertEquals(400, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function create_user_post_doesnt_need_csrf_token_if_whitelisted() { $this->extend( diff --git a/framework/core/tests/integration/extenders/EventTest.php b/framework/core/tests/integration/extenders/EventTest.php index 83534f9d7..de8119044 100644 --- a/framework/core/tests/integration/extenders/EventTest.php +++ b/framework/core/tests/integration/extenders/EventTest.php @@ -20,6 +20,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Contracts\Events\Dispatcher; +use PHPUnit\Framework\Attributes\Test; class EventTest extends TestCase { @@ -47,9 +48,7 @@ class EventTest extends TestCase ); } - /** - * @test - */ + #[Test] public function custom_listener_doesnt_work_by_default() { $group = $this->buildGroup(); @@ -57,9 +56,7 @@ class EventTest extends TestCase $this->assertEquals('test group', $group->name_singular); } - /** - * @test - */ + #[Test] public function custom_listener_works_with_closure() { $this->extend((new Extend\Event)->listen(Created::class, function (Created $event) { @@ -71,9 +68,7 @@ class EventTest extends TestCase $this->assertEquals('modified group', $group->name_singular); } - /** - * @test - */ + #[Test] public function custom_listener_works_with_class_with_handle_method_and_can_inject_stuff() { // Because it injects a translator, this also tests that stuff can be injected into this callback. @@ -84,9 +79,7 @@ class EventTest extends TestCase $this->assertEquals('Admin', $group->name_singular); } - /** - * @test - */ + #[Test] public function custom_subscriber_works() { // Because it injects a translator, this also tests that stuff can be injected into this callback. @@ -97,9 +90,7 @@ class EventTest extends TestCase $this->assertEquals('Admin', $group->name_singular); } - /** - * @test - */ + #[Test] public function custom_subscriber_applied_after_app_booted() { // Because it injects a translator, this also tests that stuff can be injected into this callback. diff --git a/framework/core/tests/integration/extenders/FilesystemTest.php b/framework/core/tests/integration/extenders/FilesystemTest.php index d0f7b51f6..14cd83640 100644 --- a/framework/core/tests/integration/extenders/FilesystemTest.php +++ b/framework/core/tests/integration/extenders/FilesystemTest.php @@ -22,23 +22,20 @@ use Illuminate\Filesystem\FilesystemAdapter; use InvalidArgumentException; use League\Flysystem\InMemory\InMemoryFilesystemAdapter; use League\Flysystem\Local\LocalFilesystemAdapter; +use PHPUnit\Framework\Attributes\Test; class FilesystemTest extends TestCase { use RetrievesAuthorizedUsers; - /** - * @test - */ + #[Test] public function custom_disk_doesnt_exist_by_default() { $this->expectException(InvalidArgumentException::class); $this->app()->getContainer()->make('filesystem')->disk('flarum-uploads'); } - /** - * @test - */ + #[Test] public function custom_disk_exists_if_added_and_uses_local_adapter_by_default() { $this->extend((new Extend\Filesystem)->disk('flarum-uploads', function (Paths $paths, UrlGenerator $url) { @@ -54,9 +51,7 @@ class FilesystemTest extends TestCase $this->assertEquals($uploadsDisk->getAdapter()::class, LocalFilesystemAdapter::class); } - /** - * @test - */ + #[Test] public function custom_disk_exists_if_added_via_invokable_class_and_uses_local_adapter_by_default() { $this->extend((new Extend\Filesystem)->disk('flarum-uploads', UploadsDisk::class)); @@ -67,9 +62,7 @@ class FilesystemTest extends TestCase $this->assertEquals($uploadsDisk->getAdapter()::class, LocalFilesystemAdapter::class); } - /** - * @test - */ + #[Test] public function disk_uses_local_adapter_if_configured_adapter_unavailable() { $this->app()->getContainer()->make(SettingsRepositoryInterface::class)->set('disk_driver.flarum-assets', 'nonexistent_driver'); @@ -80,9 +73,7 @@ class FilesystemTest extends TestCase $this->assertEquals($assetsDisk->getAdapter()::class, LocalFilesystemAdapter::class); } - /** - * @test - */ + #[Test] public function disk_uses_local_adapter_if_configured_adapter_from_config_file_unavailable() { $this->config('disk_driver.flarum-assets', 'null'); @@ -93,9 +84,7 @@ class FilesystemTest extends TestCase $this->assertEquals($assetsDisk->getAdapter()::class, LocalFilesystemAdapter::class); } - /** - * @test - */ + #[Test] public function disk_uses_custom_adapter_if_configured_and_available() { $this->extend( @@ -110,9 +99,7 @@ class FilesystemTest extends TestCase $this->assertEquals($assetsDisk->getAdapter()::class, InMemoryFilesystemAdapter::class); } - /** - * @test - */ + #[Test] public function disk_uses_custom_adapter_from_config_file_if_configured_and_available() { $this->extend( diff --git a/framework/core/tests/integration/extenders/FormatterTest.php b/framework/core/tests/integration/extenders/FormatterTest.php index 72af5c8c1..31fa32240 100644 --- a/framework/core/tests/integration/extenders/FormatterTest.php +++ b/framework/core/tests/integration/extenders/FormatterTest.php @@ -13,6 +13,7 @@ use Flarum\Extend; use Flarum\Formatter\Formatter; use Flarum\Testing\integration\RefreshesFormatterCache; use Flarum\Testing\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class FormatterTest extends TestCase { @@ -23,9 +24,7 @@ class FormatterTest extends TestCase return $this->app()->getContainer()->make(Formatter::class); } - /** - * @test - */ + #[Test] public function custom_formatter_config_doesnt_work_by_default() { $formatter = $this->getFormatter(); @@ -33,9 +32,7 @@ class FormatterTest extends TestCase $this->assertEquals('[B]something[/B]', $formatter->parse('[B]something[/B]')); } - /** - * @test - */ + #[Test] public function custom_formatter_config_works_if_added_with_closure() { $this->extend((new Extend\Formatter)->configure(function ($config) { @@ -47,9 +44,7 @@ class FormatterTest extends TestCase $this->assertEquals('something', $formatter->render($formatter->parse('[B]something[/B]'))); } - /** - * @test - */ + #[Test] public function custom_formatter_config_works_if_added_with_invokable_class() { $this->extend((new Extend\Formatter)->configure(InvokableConfig::class)); @@ -59,17 +54,13 @@ class FormatterTest extends TestCase $this->assertEquals('something', $formatter->render($formatter->parse('[B]something[/B]'))); } - /** - * @test - */ + #[Test] public function custom_formatter_parsing_doesnt_work_by_default() { $this->assertEquals('Text<a>', $this->getFormatter()->parse('Text')); } - /** - * @test - */ + #[Test] public function custom_formatter_parsing_works_if_added_with_closure() { $this->extend((new Extend\Formatter)->parse(function ($parser, $context, $text) { @@ -79,9 +70,7 @@ class FormatterTest extends TestCase $this->assertEquals('ReplacedText<a>', $this->getFormatter()->parse('Text')); } - /** - * @test - */ + #[Test] public function custom_formatter_parsing_works_if_added_with_invokable_class() { $this->extend((new Extend\Formatter)->parse(InvokableParsing::class)); @@ -89,17 +78,13 @@ class FormatterTest extends TestCase $this->assertEquals('ReplacedText<a>', $this->getFormatter()->parse('Text')); } - /** - * @test - */ + #[Test] public function custom_formatter_unparsing_doesnt_work_by_default() { $this->assertEquals('Text', $this->getFormatter()->unparse('Text<a>')); } - /** - * @test - */ + #[Test] public function custom_formatter_unparsing_works_if_added_with_closure() { $this->extend((new Extend\Formatter)->unparse(function ($context, $xml) { @@ -109,9 +94,7 @@ class FormatterTest extends TestCase $this->assertEquals('ReplacedText', $this->getFormatter()->unparse('Text<a>')); } - /** - * @test - */ + #[Test] public function custom_formatter_unparsing_works_if_added_with_invokable_class() { $this->extend((new Extend\Formatter)->unparse(InvokableUnparsing::class)); @@ -119,17 +102,13 @@ class FormatterTest extends TestCase $this->assertEquals('ReplacedText', $this->getFormatter()->unparse('Text<a>')); } - /** - * @test - */ + #[Test] public function custom_formatter_rendering_doesnt_work_by_default() { $this->assertEquals('Text', $this->getFormatter()->render('

Text

')); } - /** - * @test - */ + #[Test] public function custom_formatter_rendering_works_if_added_with_closure() { $this->extend((new Extend\Formatter)->render(function ($renderer, $context, $xml, $request) { @@ -139,9 +118,7 @@ class FormatterTest extends TestCase $this->assertEquals('ReplacedText', $this->getFormatter()->render('Text')); } - /** - * @test - */ + #[Test] public function custom_formatter_rendering_works_if_added_with_invokable_class() { $this->extend((new Extend\Formatter)->render(InvokableRendering::class)); diff --git a/framework/core/tests/integration/extenders/FrontendContentTest.php b/framework/core/tests/integration/extenders/FrontendContentTest.php index ed5c0bd7e..2749de85b 100644 --- a/framework/core/tests/integration/extenders/FrontendContentTest.php +++ b/framework/core/tests/integration/extenders/FrontendContentTest.php @@ -13,14 +13,13 @@ use Flarum\Extend\Frontend; use Flarum\Frontend\Document; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class FrontendContentTest extends TestCase { use RetrievesAuthorizedUsers; - /** - * @test - */ + #[Test] public function content_added_with_low_priority_by_default() { $title = null; @@ -39,9 +38,7 @@ class FrontendContentTest extends TestCase $this->assertNotNull($title, $body); } - /** - * @test - */ + #[Test] public function content_can_be_added_with_high_priority() { $title = 1; @@ -60,9 +57,7 @@ class FrontendContentTest extends TestCase $this->assertNull($title, $body); } - /** - * @test - */ + #[Test] public function contents_can_be_added_with_different_priorities() { $test = []; diff --git a/framework/core/tests/integration/extenders/FrontendPreloadTest.php b/framework/core/tests/integration/extenders/FrontendPreloadTest.php index 050cd393f..b0d7599d2 100644 --- a/framework/core/tests/integration/extenders/FrontendPreloadTest.php +++ b/framework/core/tests/integration/extenders/FrontendPreloadTest.php @@ -11,14 +11,13 @@ namespace Flarum\Tests\integration\extenders; use Flarum\Extend; use Flarum\Testing\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class FrontendPreloadTest extends TestCase { private $customPreloadUrls = ['/my-preload', '/my-preload2']; - /** - * @test - */ + #[Test] public function default_preloads_are_present() { $response = $this->send( @@ -39,9 +38,7 @@ class FrontendPreloadTest extends TestCase } } - /** - * @test - */ + #[Test] public function preloads_can_be_added() { $urls = $this->customPreloadUrls; @@ -65,9 +62,7 @@ class FrontendPreloadTest extends TestCase } } - /** - * @test - */ + #[Test] public function preloads_can_be_added_via_callable() { $urls = $this->customPreloadUrls; diff --git a/framework/core/tests/integration/extenders/FrontendTitleTest.php b/framework/core/tests/integration/extenders/FrontendTitleTest.php index 92f9387d7..74c1672e2 100644 --- a/framework/core/tests/integration/extenders/FrontendTitleTest.php +++ b/framework/core/tests/integration/extenders/FrontendTitleTest.php @@ -17,6 +17,7 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; use Psr\Http\Message\ServerRequestInterface; class FrontendTitleTest extends TestCase @@ -40,17 +41,13 @@ class FrontendTitleTest extends TestCase $this->setting('forum_title', 'Flarum'); } - /** - * @test - */ + #[Test] public function basic_title_driver_is_used_by_default() { $this->assertTitleEquals('Test Discussion - Flarum'); } - /** - * @test - */ + #[Test] public function custom_title_driver_works_if_set() { $this->extend((new Frontend('forum'))->title(CustomTitleDriver::class)); diff --git a/framework/core/tests/integration/extenders/LocalesTest.php b/framework/core/tests/integration/extenders/LocalesTest.php index 8920d4f97..76acb68a1 100644 --- a/framework/core/tests/integration/extenders/LocalesTest.php +++ b/framework/core/tests/integration/extenders/LocalesTest.php @@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\extenders; use Flarum\Extend; use Flarum\Locale\Translator; use Flarum\Testing\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class LocalesTest extends TestCase { @@ -25,9 +26,7 @@ class LocalesTest extends TestCase array_map('unlink', glob($this->tmpDir().'/storage/locale/*')); } - /** - * @test - */ + #[Test] public function custom_translation_does_not_exist_by_default() { $this->app()->getContainer()->make('flarum.locales'); @@ -36,9 +35,7 @@ class LocalesTest extends TestCase $this->assertEquals('test.hello', $translator->trans('test.hello', ['name' => 'ACME'])); } - /** - * @test - */ + #[Test] public function custom_translation_exists_if_added() { $this->extend( @@ -51,9 +48,7 @@ class LocalesTest extends TestCase $this->assertEquals('World ACME', $translator->trans('test.hello', ['name' => 'ACME'])); } - /** - * @test - */ + #[Test] public function custom_translation_exists_if_added_with_intl_suffix() { $this->extend( @@ -66,9 +61,7 @@ class LocalesTest extends TestCase $this->assertEquals('World-intl ACME', $translator->trans('test.hello-intl', ['name' => 'ACME'])); } - /** - * @test - */ + #[Test] public function messageformat_works_in_translations() { $this->extend( @@ -81,9 +74,7 @@ class LocalesTest extends TestCase $this->assertEquals('ACME invites ACME2 and one other person to her party.', $translator->trans('test.party-invitation', ['gender_of_host' => 'female', 'host' => 'ACME', 'num_guests' => 2, 'guest' => 'ACME2'])); } - /** - * @test - */ + #[Test] public function laravel_interface_methods_work() { $this->extend( diff --git a/framework/core/tests/integration/extenders/MailTest.php b/framework/core/tests/integration/extenders/MailTest.php index d22dad21d..2354af990 100644 --- a/framework/core/tests/integration/extenders/MailTest.php +++ b/framework/core/tests/integration/extenders/MailTest.php @@ -16,6 +16,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Illuminate\Contracts\Validation\Factory; use Illuminate\Support\MessageBag; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\Mailer\Transport\NullTransport; use Symfony\Component\Mailer\Transport\TransportInterface; @@ -23,9 +24,7 @@ class MailTest extends TestCase { use RetrievesAuthorizedUsers; - /** - * @test - */ + #[Test] public function drivers_are_unchanged_by_default() { $response = $this->send( @@ -53,9 +52,7 @@ class MailTest extends TestCase ], $fields['smtp']); } - /** - * @test - */ + #[Test] public function added_driver_appears_in_mail_settings() { $this->extend( @@ -75,9 +72,7 @@ class MailTest extends TestCase $this->assertEquals(['customSetting1' => ''], $fields['custom']); } - /** - * @test - */ + #[Test] public function adding_driver_with_duplicate_name_overrides_fields() { $this->extend( diff --git a/framework/core/tests/integration/extenders/MiddlewareTest.php b/framework/core/tests/integration/extenders/MiddlewareTest.php index e69d5001e..8f171a6e6 100644 --- a/framework/core/tests/integration/extenders/MiddlewareTest.php +++ b/framework/core/tests/integration/extenders/MiddlewareTest.php @@ -11,6 +11,7 @@ namespace Flarum\Tests\integration\extenders; use Flarum\Extend; use Flarum\Testing\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; @@ -26,9 +27,7 @@ class MiddlewareTest extends TestCase ); } - /** - * @test - */ + #[Test] public function custom_header_is_not_present_by_default() { $response = $this->send($this->request('GET', '/')); @@ -37,9 +36,7 @@ class MiddlewareTest extends TestCase $this->assertArrayNotHasKey('X-First-Test-Middleware', $response->getHeaders()); } - /** - * @test - */ + #[Test] public function can_add_middleware() { $this->extend( @@ -52,9 +49,7 @@ class MiddlewareTest extends TestCase $this->assertArrayHasKey('X-First-Test-Middleware', $response->getHeaders()); } - /** - * @test - */ + #[Test] public function can_replace_middleware() { $this->add_first_middleware(); @@ -69,9 +64,7 @@ class MiddlewareTest extends TestCase $this->assertArrayHasKey('X-Second-Test-Middleware', $response->getHeaders()); } - /** - * @test - */ + #[Test] public function can_remove_middleware() { $this->add_first_middleware(); @@ -85,9 +78,7 @@ class MiddlewareTest extends TestCase $this->assertArrayNotHasKey('X-First-Test-Middleware', $response->getHeaders()); } - /** - * @test - */ + #[Test] public function can_insert_before_middleware() { $this->add_first_middleware(); @@ -104,9 +95,7 @@ class MiddlewareTest extends TestCase $this->assertLessThan($newMiddlewarePosition, $originalMiddlewarePosition); } - /** - * @test - */ + #[Test] public function can_insert_after_middleware() { $this->add_first_middleware(); diff --git a/framework/core/tests/integration/extenders/ModelPrivateTest.php b/framework/core/tests/integration/extenders/ModelPrivateTest.php index 1642a9bda..279e424a3 100644 --- a/framework/core/tests/integration/extenders/ModelPrivateTest.php +++ b/framework/core/tests/integration/extenders/ModelPrivateTest.php @@ -15,6 +15,7 @@ use Flarum\Extend; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class ModelPrivateTest extends TestCase { @@ -27,9 +28,7 @@ class ModelPrivateTest extends TestCase Discussion::unguard(); } - /** - * @test - */ + #[Test] public function discussion_isnt_saved_as_private_by_default() { $this->app(); @@ -45,9 +44,7 @@ class ModelPrivateTest extends TestCase $this->assertNull($discussion->is_private); } - /** - * @test - */ + #[Test] public function discussion_is_saved_as_private_if_privacy_checker_added() { $this->extend( @@ -76,9 +73,7 @@ class ModelPrivateTest extends TestCase $this->assertFalse($publicDiscussion->is_private); } - /** - * @test - */ + #[Test] public function discussion_is_saved_as_private_if_privacy_checker_added_via_invokable_class() { $this->extend( @@ -105,9 +100,7 @@ class ModelPrivateTest extends TestCase $this->assertFalse($publicDiscussion->is_private); } - /** - * @test - */ + #[Test] public function private_checkers_that_return_false_dont_matter() { $this->extend( diff --git a/framework/core/tests/integration/extenders/ModelTest.php b/framework/core/tests/integration/extenders/ModelTest.php index 1fb65ce15..5e94c187f 100644 --- a/framework/core/tests/integration/extenders/ModelTest.php +++ b/framework/core/tests/integration/extenders/ModelTest.php @@ -20,6 +20,7 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class ModelTest extends TestCase { @@ -51,9 +52,7 @@ class ModelTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function custom_relationship_does_not_exist_by_default() { $this->app(); @@ -64,9 +63,7 @@ class ModelTest extends TestCase $user->customRelation(); } - /** - * @test - */ + #[Test] public function custom_hasOne_relationship_exists_if_added() { $this->extend( @@ -81,9 +78,7 @@ class ModelTest extends TestCase $this->assertEquals([], $user->customRelation()->get()->toArray()); } - /** - * @test - */ + #[Test] public function custom_hasMany_relationship_exists_if_added() { $this->extend( @@ -98,9 +93,7 @@ class ModelTest extends TestCase $this->assertEquals([], $user->customRelation()->get()->toArray()); } - /** - * @test - */ + #[Test] public function custom_belongsTo_relationship_exists_if_added() { $this->extend( @@ -115,9 +108,7 @@ class ModelTest extends TestCase $this->assertEquals([], $user->customRelation()->get()->toArray()); } - /** - * @test - */ + #[Test] public function custom_relationship_exists_if_added() { $this->extend( @@ -134,9 +125,7 @@ class ModelTest extends TestCase $this->assertEquals([], $user->customRelation()->get()->toArray()); } - /** - * @test - */ + #[Test] public function custom_relationship_can_be_invokable_class() { $this->extend( @@ -151,9 +140,7 @@ class ModelTest extends TestCase $this->assertEquals([], $user->customRelation()->get()->toArray()); } - /** - * @test - */ + #[Test] public function custom_relationship_exists_and_can_return_instances_if_added() { $this->extend( @@ -177,9 +164,7 @@ class ModelTest extends TestCase $this->assertStringContainsString(json_encode(__CLASS__), json_encode($user->customRelation()->get())); } - /** - * @test - */ + #[Test] public function custom_relationship_is_inherited_to_child_classes() { $this->extend( @@ -197,9 +182,7 @@ class ModelTest extends TestCase $this->assertEquals(1, $post->ancestor->id); } - /** - * @test - */ + #[Test] public function custom_relationship_prioritizes_child_classes_within_2_parent_classes() { $this->extend( @@ -219,9 +202,7 @@ class ModelTest extends TestCase $this->assertEquals(1, $post->ancestor->id); } - /** - * @test - */ + #[Test] public function custom_relationship_prioritizes_child_classes_within_child_class_and_immediate_parent() { $this->extend( @@ -241,9 +222,7 @@ class ModelTest extends TestCase $this->assertEquals(2, $post->ancestor->id); } - /** - * @test - */ + #[Test] public function custom_relationship_does_not_exist_if_added_to_unrelated_model() { $this->extend( @@ -261,9 +240,7 @@ class ModelTest extends TestCase $group->customRelation(); } - /** - * @test - */ + #[Test] public function custom_default_attribute_doesnt_exist_if_not_set() { $group = new Group; @@ -273,9 +250,7 @@ class ModelTest extends TestCase $this->assertNotEquals('Custom Default', $group->name_singular); } - /** - * @test - */ + #[Test] public function custom_default_attribute_works_if_set() { $this->extend( @@ -290,9 +265,7 @@ class ModelTest extends TestCase $this->assertEquals('Custom Default', $group->name_singular); } - /** - * @test - */ + #[Test] public function custom_default_attribute_evaluated_at_runtime_if_callable() { $this->extend( @@ -315,9 +288,7 @@ class ModelTest extends TestCase $this->assertEquals(4, $group2->counter); } - /** - * @test - */ + #[Test] public function custom_default_attribute_is_inherited_to_child_classes() { $this->extend( @@ -332,9 +303,7 @@ class ModelTest extends TestCase $this->assertEquals(42, $post->answer); } - /** - * @test - */ + #[Test] public function custom_default_attribute_inheritance_prioritizes_child_class() { $this->extend( @@ -357,9 +326,7 @@ class ModelTest extends TestCase $this->assertEquals('ni!', $commentPost->answer); } - /** - * @test - */ + #[Test] public function custom_default_attribute_doesnt_work_if_set_on_unrelated_model() { $this->extend( @@ -374,9 +341,7 @@ class ModelTest extends TestCase $this->assertNotEquals('Custom Default', $user->name_singular); } - /** - * @test - */ + #[Test] public function custom_cast_attribute_doesnt_exist_by_default() { $post = new Post; @@ -386,9 +351,7 @@ class ModelTest extends TestCase $this->assertFalse($post->hasCast('custom')); } - /** - * @test - */ + #[Test] public function custom_cast_attribute_can_be_set() { $this->extend( @@ -403,9 +366,7 @@ class ModelTest extends TestCase $this->assertTrue($post->hasCast('custom', 'datetime')); } - /** - * @test - */ + #[Test] public function custom_cast_attribute_is_inherited_to_child_classes() { $this->extend( @@ -420,9 +381,7 @@ class ModelTest extends TestCase $this->assertTrue($post->hasCast('custom', 'boolean')); } - /** - * @test - */ + #[Test] public function custom_cast_attribute_doesnt_work_if_set_on_unrelated_model() { $this->extend( diff --git a/framework/core/tests/integration/extenders/ModelUrlTest.php b/framework/core/tests/integration/extenders/ModelUrlTest.php index eb03e7773..1cc9d4ca4 100644 --- a/framework/core/tests/integration/extenders/ModelUrlTest.php +++ b/framework/core/tests/integration/extenders/ModelUrlTest.php @@ -16,6 +16,7 @@ use Flarum\Http\SlugManager; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class ModelUrlTest extends TestCase { @@ -39,9 +40,7 @@ class ModelUrlTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function uses_default_driver_by_default() { $slugManager = $this->app()->getContainer()->make(SlugManager::class); @@ -52,9 +51,7 @@ class ModelUrlTest extends TestCase $this->assertEquals('1', $slugManager->forResource(User::class)->fromSlug('admin', $testUser)->id); } - /** - * @test - */ + #[Test] public function custom_slug_driver_has_effect_if_added() { $this->extend((new Extend\ModelUrl(User::class))->addSlugDriver('testDriver', TestSlugDriver::class)); diff --git a/framework/core/tests/integration/extenders/ModelVisibilityTest.php b/framework/core/tests/integration/extenders/ModelVisibilityTest.php index 7ead3bcf6..333c4c42d 100644 --- a/framework/core/tests/integration/extenders/ModelVisibilityTest.php +++ b/framework/core/tests/integration/extenders/ModelVisibilityTest.php @@ -19,6 +19,7 @@ use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class ModelVisibilityTest extends TestCase { @@ -47,9 +48,7 @@ class ModelVisibilityTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function when_allowed_guests_can_see_hidden_posts() { $this->extend( @@ -68,9 +67,7 @@ class ModelVisibilityTest extends TestCase $this->assertEquals(1, Arr::get($json, 'data.relationships.posts.data.0.id')); } - /** - * @test - */ + #[Test] public function user_can_see_posts_by_default() { $this->app(); @@ -82,9 +79,7 @@ class ModelVisibilityTest extends TestCase $this->assertCount(1, $visiblePosts); } - /** - * @test - */ + #[Test] public function custom_visibility_scoper_can_stop_user_from_seeing_posts() { $this->extend( @@ -103,9 +98,7 @@ class ModelVisibilityTest extends TestCase $this->assertCount(0, $visiblePosts); } - /** - * @test - */ + #[Test] public function custom_visibility_scoper_applies_if_added_to_parent_class() { $this->extend( @@ -124,9 +117,7 @@ class ModelVisibilityTest extends TestCase $this->assertCount(0, $visiblePosts); } - /** - * @test - */ + #[Test] public function custom_visibility_scoper_for_class_applied_after_scopers_for_parent_class() { $this->extend( @@ -149,9 +140,7 @@ class ModelVisibilityTest extends TestCase $this->assertCount(2, $visiblePosts); } - /** - * @test - */ + #[Test] public function custom_scoper_works_for_abilities_other_than_view() { $this->extend( @@ -174,9 +163,7 @@ class ModelVisibilityTest extends TestCase $this->assertCount(2, $visiblePosts); } - /** - * @test - */ + #[Test] public function universal_scoper_works() { $this->extend( diff --git a/framework/core/tests/integration/extenders/NotificationTest.php b/framework/core/tests/integration/extenders/NotificationTest.php index ee5e44f8c..df88e7b09 100644 --- a/framework/core/tests/integration/extenders/NotificationTest.php +++ b/framework/core/tests/integration/extenders/NotificationTest.php @@ -18,30 +18,25 @@ use Flarum\Notification\NotificationSyncer; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class NotificationTest extends TestCase { use RetrievesAuthorizedUsers; - /** - * @test - */ + #[Test] public function notification_type_doesnt_exist_by_default() { $this->assertArrayNotHasKey('customNotificationType', Notification::getSubjectModels()); } - /** - * @test - */ + #[Test] public function notification_driver_doesnt_exist_by_default() { $this->assertArrayNotHasKey('customNotificationDriver', NotificationSyncer::getNotificationDrivers()); } - /** - * @test - */ + #[Test] public function notification_type_exists_if_added() { $this->extend((new Extend\Notification)->type(CustomNotificationType::class)); @@ -51,9 +46,7 @@ class NotificationTest extends TestCase $this->assertArrayHasKey('customNotificationType', Notification::getSubjectModels()); } - /** - * @test - */ + #[Test] public function notification_driver_exists_if_added() { $this->extend((new Extend\Notification())->driver( @@ -66,9 +59,7 @@ class NotificationTest extends TestCase $this->assertArrayHasKey('customNotificationDriver', NotificationSyncer::getNotificationDrivers()); } - /** - * @test - */ + #[Test] public function notification_driver_enabled_types_exist_if_added() { $this->extend( @@ -91,9 +82,7 @@ class NotificationTest extends TestCase $this->assertEmpty($blueprints[ThirdCustomNotificationType::class]); } - /** - * @test - */ + #[Test] public function notification_before_sending_callback_works_if_added() { $this->extend( diff --git a/framework/core/tests/integration/extenders/PolicyTest.php b/framework/core/tests/integration/extenders/PolicyTest.php index 05b2c2a00..297bd9af6 100644 --- a/framework/core/tests/integration/extenders/PolicyTest.php +++ b/framework/core/tests/integration/extenders/PolicyTest.php @@ -19,6 +19,7 @@ use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\Access\AbstractPolicy; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class PolicyTest extends TestCase { @@ -48,9 +49,7 @@ class PolicyTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function unrelated_user_cant_hide_discussion_by_default() { $response = $this->send( @@ -60,9 +59,7 @@ class PolicyTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function unrelated_user_can_hide_discussion_if_allowed() { $this->extend( @@ -77,9 +74,7 @@ class PolicyTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function unrelated_user_cant_hide_discussion_if_denied() { $this->extend( @@ -95,9 +90,7 @@ class PolicyTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function unrelated_user_can_hide_discussion_if_force_allowed() { $this->extend( @@ -114,9 +107,7 @@ class PolicyTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function unrelated_user_cant_hide_discussion_if_force_denied() { $this->extend( @@ -134,9 +125,7 @@ class PolicyTest extends TestCase $this->assertEquals(403, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function regular_user_can_start_discussions_by_default() { $this->app(); @@ -146,9 +135,7 @@ class PolicyTest extends TestCase $this->assertEquals(true, $user->can('startDiscussion')); } - /** - * @test - */ + #[Test] public function regular_user_cant_start_discussions_if_blocked_by_global_policy() { $this->extend( @@ -163,9 +150,7 @@ class PolicyTest extends TestCase $this->assertEquals(false, $user->can('startDiscussion')); } - /** - * @test - */ + #[Test] public function global_policy_doesnt_apply_if_argument_provided() { $this->extend( @@ -180,9 +165,7 @@ class PolicyTest extends TestCase $this->assertEquals(true, $user->can('startDiscussion', Discussion::find(1))); } - /** - * @test - */ + #[Test] public function unrelated_user_cant_hide_post_by_default() { $this->app(); @@ -192,9 +175,7 @@ class PolicyTest extends TestCase $this->assertEquals(false, $user->can('hide', Post::find(1))); } - /** - * @test - */ + #[Test] public function unrelated_user_can_hide_post_if_allowed() { $this->extend( @@ -207,9 +188,7 @@ class PolicyTest extends TestCase $this->assertEquals(true, $user->can('hide', Post::find(1))); } - /** - * @test - */ + #[Test] public function policies_are_inherited_to_child_classes() { $this->extend( diff --git a/framework/core/tests/integration/extenders/PostTest.php b/framework/core/tests/integration/extenders/PostTest.php index 8effab49c..1201639b6 100644 --- a/framework/core/tests/integration/extenders/PostTest.php +++ b/framework/core/tests/integration/extenders/PostTest.php @@ -14,20 +14,17 @@ use Flarum\Post\AbstractEventPost; use Flarum\Post\MergeableInterface; use Flarum\Post\Post; use Flarum\Testing\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class PostTest extends TestCase { - /** - * @test - */ + #[Test] public function custom_post_type_doesnt_exist_by_default() { $this->assertArrayNotHasKey('customPost', Post::getModels()); } - /** - * @test - */ + #[Test] public function custom_post_type_exists_if_added() { $this->extend((new Extend\Post)->type(PostTestCustomPost::class)); diff --git a/framework/core/tests/integration/extenders/RoutesTest.php b/framework/core/tests/integration/extenders/RoutesTest.php index 3458219f4..3117a59e7 100644 --- a/framework/core/tests/integration/extenders/RoutesTest.php +++ b/framework/core/tests/integration/extenders/RoutesTest.php @@ -12,15 +12,14 @@ namespace Flarum\Tests\integration\extenders; use Flarum\Extend; use Flarum\Testing\integration\TestCase; use Laminas\Diactoros\Response\TextResponse; +use PHPUnit\Framework\Attributes\Test; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; class RoutesTest extends TestCase { - /** - * @test - */ + #[Test] public function custom_route_does_not_exist_by_default() { $response = $this->send( @@ -30,9 +29,7 @@ class RoutesTest extends TestCase $this->assertEquals(404, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function custom_route_can_be_added_by_extender() { $this->extend( @@ -48,9 +45,7 @@ class RoutesTest extends TestCase $this->assertEquals('Hello Flarumites!', $response->getBody()); } - /** - * @test - */ + #[Test] public function existing_route_can_be_removed() { $this->extend( @@ -65,9 +60,7 @@ class RoutesTest extends TestCase $this->assertEquals(404, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function custom_route_can_override_existing_route_if_removed() { $this->extend( diff --git a/framework/core/tests/integration/extenders/SearchDriverTest.php b/framework/core/tests/integration/extenders/SearchDriverTest.php index 6d44df7e9..534ce7bf8 100644 --- a/framework/core/tests/integration/extenders/SearchDriverTest.php +++ b/framework/core/tests/integration/extenders/SearchDriverTest.php @@ -24,6 +24,7 @@ use Flarum\Search\SearchState; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class SearchDriverTest extends TestCase { @@ -78,9 +79,7 @@ class SearchDriverTest extends TestCase ->getResults(); } - /** - * @test - */ + #[Test] public function works_as_expected_with_no_modifications() { $this->prepDb(); @@ -94,9 +93,7 @@ class SearchDriverTest extends TestCase $this->assertStringContainsString('DISCUSSION 2', $searchForSecond); } - /** - * @test - */ + #[Test] public function custom_full_text_gambit_has_effect_if_added() { $this->extend( @@ -107,9 +104,7 @@ class SearchDriverTest extends TestCase $this->assertEquals('[]', json_encode($this->searchDiscussions('in text', 5))); } - /** - * @test - */ + #[Test] public function custom_filter_has_effect_if_added() { $this->extend( @@ -125,9 +120,7 @@ class SearchDriverTest extends TestCase $this->assertEquals('[]', json_encode($this->searchDiscussions('', 5, ['noResult' => '1']))); } - /** - * @test - */ + #[Test] public function existing_filter_can_be_replaced() { $this->extend( @@ -142,9 +135,7 @@ class SearchDriverTest extends TestCase $this->assertEquals('[]', json_encode($this->searchDiscussions('', 5, ['noResult' => '1']))); } - /** - * @test - */ + #[Test] public function search_mutator_has_effect_if_added() { $this->extend( @@ -159,9 +150,7 @@ class SearchDriverTest extends TestCase $this->assertEquals('[]', json_encode($this->searchDiscussions('in text', 5))); } - /** - * @test - */ + #[Test] public function search_mutator_has_effect_if_added_with_invokable_class() { $this->extend( diff --git a/framework/core/tests/integration/extenders/SearchIndexTest.php b/framework/core/tests/integration/extenders/SearchIndexTest.php index 6a6c8ac84..2498a112e 100644 --- a/framework/core/tests/integration/extenders/SearchIndexTest.php +++ b/framework/core/tests/integration/extenders/SearchIndexTest.php @@ -18,6 +18,7 @@ use Flarum\Search\IndexerInterface; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; class SearchIndexTest extends TestCase { @@ -52,7 +53,7 @@ class SearchIndexTest extends TestCase ]; } - /** @dataProvider modelProvider */ + #[DataProvider('modelProvider')] public function test_indexer_triggered_on_create(string $type, string $modelClass, array $attributes) { $this->extend( @@ -84,7 +85,7 @@ class SearchIndexTest extends TestCase Assert::assertEquals('save', TestIndexer::$triggered, $response->getBody()->getContents()); } - /** @dataProvider modelProvider */ + #[DataProvider('modelProvider')] public function test_indexer_triggered_on_save(string $type, string $modelClass, array $attributes) { $this->extend( @@ -108,7 +109,7 @@ class SearchIndexTest extends TestCase Assert::assertEquals('save', TestIndexer::$triggered, $response->getBody()->getContents()); } - /** @dataProvider modelProvider */ + #[DataProvider('modelProvider')] public function test_indexer_triggered_on_delete(string $type, string $modelClass, array $attributes) { $this->extend( @@ -127,7 +128,7 @@ class SearchIndexTest extends TestCase Assert::assertEquals('delete', TestIndexer::$triggered, $response->getBody()->getContents()); } - /** @dataProvider modelProvider */ + #[DataProvider('modelProvider')] public function test_indexer_triggered_on_hide(string $type, string $modelClass, array $attributes) { $this->extend( @@ -153,7 +154,7 @@ class SearchIndexTest extends TestCase Assert::assertEquals('delete', TestIndexer::$triggered, $response->getBody()->getContents()); } - /** @dataProvider modelProvider */ + #[DataProvider('modelProvider')] public function test_indexer_triggered_on_restore(string $type, string $modelClass, array $attributes) { $this->extend( diff --git a/framework/core/tests/integration/extenders/ServiceProviderTest.php b/framework/core/tests/integration/extenders/ServiceProviderTest.php index 9115ef320..9e4511328 100644 --- a/framework/core/tests/integration/extenders/ServiceProviderTest.php +++ b/framework/core/tests/integration/extenders/ServiceProviderTest.php @@ -12,12 +12,11 @@ namespace Flarum\Tests\integration\extenders; use Flarum\Extend; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Testing\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class ServiceProviderTest extends TestCase { - /** - * @test - */ + #[Test] public function providers_dont_work_by_default() { $this->app(); @@ -27,9 +26,7 @@ class ServiceProviderTest extends TestCase ); } - /** - * @test - */ + #[Test] public function providers_first_register_order_is_correct() { $this->extend( @@ -45,9 +42,7 @@ class ServiceProviderTest extends TestCase ); } - /** - * @test - */ + #[Test] public function providers_second_register_order_is_correct() { $this->extend( @@ -64,9 +59,7 @@ class ServiceProviderTest extends TestCase ); } - /** - * @test - */ + #[Test] public function providers_boot_order_is_correct() { $this->extend( diff --git a/framework/core/tests/integration/extenders/SessionTest.php b/framework/core/tests/integration/extenders/SessionTest.php index 0470b8e39..2f89355be 100644 --- a/framework/core/tests/integration/extenders/SessionTest.php +++ b/framework/core/tests/integration/extenders/SessionTest.php @@ -18,33 +18,28 @@ use Flarum\User\SessionDriverInterface; use Illuminate\Session\FileSessionHandler; use Illuminate\Session\NullSessionHandler; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\Test; use SessionHandlerInterface; class SessionTest extends TestCase { use RetrievesAuthorizedUsers; - /** - * @test - */ + #[Test] public function default_driver_exists_by_default() { $this->expectNotToPerformAssertions(); $this->app()->getContainer()->make('session.handler'); } - /** - * @test - */ + #[Test] public function custom_driver_doesnt_exist_by_default() { $this->expectException(InvalidArgumentException::class); $this->app()->getContainer()->make('session')->driver('flarum-acme'); } - /** - * @test - */ + #[Test] public function custom_driver_exists_if_added() { $this->extend((new Extend\Session())->driver('flarum-acme', AcmeSessionDriver::class)); @@ -54,9 +49,7 @@ class SessionTest extends TestCase $this->assertEquals(NullSessionHandler::class, $driver->getHandler()::class); } - /** - * @test - */ + #[Test] public function custom_driver_overrides_laravel_defined_drivers_if_added() { $this->extend((new Extend\Session())->driver('redis', AcmeSessionDriver::class)); @@ -66,9 +59,7 @@ class SessionTest extends TestCase $this->assertEquals(NullSessionHandler::class, $driver->getHandler()::class); } - /** - * @test - */ + #[Test] public function uses_default_driver_if_driver_from_config_file_not_configured() { $this->config('session.driver', null); @@ -78,9 +69,7 @@ class SessionTest extends TestCase $this->assertEquals(FileSessionHandler::class, $handler::class); } - /** - * @test - */ + #[Test] public function uses_default_driver_if_configured_driver_from_config_file_unavailable() { $this->config('session.driver', 'nevergonnagiveyouup'); @@ -90,9 +79,7 @@ class SessionTest extends TestCase $this->assertEquals(FileSessionHandler::class, $handler::class); } - /** - * @test - */ + #[Test] public function uses_custom_driver_from_config_file_if_configured_and_available() { $this->extend( diff --git a/framework/core/tests/integration/extenders/SettingsTest.php b/framework/core/tests/integration/extenders/SettingsTest.php index 336f74745..8cf38afe7 100644 --- a/framework/core/tests/integration/extenders/SettingsTest.php +++ b/framework/core/tests/integration/extenders/SettingsTest.php @@ -13,6 +13,7 @@ use Flarum\Extend; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class SettingsTest extends TestCase { @@ -35,9 +36,7 @@ class SettingsTest extends TestCase $this->setting('custom-prefix.custom_setting2', 'customValue'); } - /** - * @test - */ + #[Test] public function custom_setting_isnt_serialized_by_default() { $response = $this->send( @@ -51,9 +50,7 @@ class SettingsTest extends TestCase $this->assertArrayNotHasKey('customPrefix.customSetting', $payload['data']['attributes']); } - /** - * @test - */ + #[Test] public function custom_setting_serialized_if_added() { $this->extend( @@ -73,9 +70,7 @@ class SettingsTest extends TestCase $this->assertEquals('customValue', $payload['data']['attributes']['customPrefix.customSetting']); } - /** - * @test - */ + #[Test] public function custom_setting_callback_works_if_added() { $this->extend( @@ -97,9 +92,7 @@ class SettingsTest extends TestCase $this->assertEquals('customValueModified', $payload['data']['attributes']['customPrefix.customSetting']); } - /** - * @test - */ + #[Test] public function custom_setting_callback_can_cast_to_type() { $this->extend( @@ -121,9 +114,7 @@ class SettingsTest extends TestCase $this->assertEquals(true, $payload['data']['attributes']['customPrefix.customSetting']); } - /** - * @test - */ + #[Test] public function custom_setting_callback_works_with_invokable_class() { $this->extend( @@ -143,9 +134,7 @@ class SettingsTest extends TestCase $this->assertEquals('customValueModifiedByInvokable', $payload['data']['attributes']['customPrefix.customSetting2']); } - /** - * @test - */ + #[Test] public function custom_setting_default_prioritizes_extender() { $this->extend( @@ -164,9 +153,7 @@ class SettingsTest extends TestCase $this->assertEquals('extenderDefault200', $settings->get('custom-prefix.unavailable_custom_setting200')); } - /** - * @test - */ + #[Test] public function custom_setting_default_falls_back_to_parameter() { $this->extend( @@ -182,9 +169,7 @@ class SettingsTest extends TestCase $this->assertEquals('defaultParameterValue', $value); } - /** - * @test - */ + #[Test] public function null_custom_setting_returns_null() { $this->setting('custom-prefix.custom_null_setting', null); @@ -202,9 +187,7 @@ class SettingsTest extends TestCase $this->assertEquals(null, $value); } - /** - * @test - */ + #[Test] public function custom_less_var_does_not_work_by_default() { $this->extend( @@ -217,9 +200,7 @@ class SettingsTest extends TestCase $this->assertEquals(500, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function custom_less_var_works_if_registered() { $this->extend( @@ -237,9 +218,7 @@ class SettingsTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function cant_save_setting_if_invalid_less_var() { $this->extend( diff --git a/framework/core/tests/integration/extenders/ThemeTest.php b/framework/core/tests/integration/extenders/ThemeTest.php index 85cb578ae..5257dcf6b 100644 --- a/framework/core/tests/integration/extenders/ThemeTest.php +++ b/framework/core/tests/integration/extenders/ThemeTest.php @@ -11,12 +11,11 @@ namespace Flarum\Tests\integration\extenders; use Flarum\Extend; use Flarum\Testing\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class ThemeTest extends TestCase { - /** - * @test - */ + #[Test] public function theme_extender_override_import_doesnt_work_by_default() { $response = $this->send($this->request('GET', '/')); @@ -27,9 +26,7 @@ class ThemeTest extends TestCase $this->assertStringNotContainsString('.dummy_test_case{color:red}', file_get_contents($cssFilePath)); } - /** - * @test - */ + #[Test] public function theme_extender_override_import_works() { $this->extend( @@ -46,9 +43,7 @@ class ThemeTest extends TestCase $this->assertStringContainsString('.dummy_test_case{color:red}', file_get_contents($cssFilePath)); } - /** - * @test - */ + #[Test] public function theme_extender_override_import_works_with_external_sources() { $this->extend( @@ -70,9 +65,7 @@ class ThemeTest extends TestCase $this->assertStringContainsString('.dummy{color:yellow}', $contents); } - /** - * @test - */ + #[Test] public function theme_extender_override_file_source_works() { $this->extend( @@ -89,9 +82,7 @@ class ThemeTest extends TestCase $this->assertEquals('body{color:orange}', file_get_contents($cssFilePath)); } - /** - * @test - */ + #[Test] public function theme_extender_override_file_source_works_by_failing_when_necessary() { $this->extend( @@ -105,9 +96,7 @@ class ThemeTest extends TestCase $this->assertEquals(500, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function theme_extender_can_add_custom_function() { $this->extend( @@ -133,9 +122,7 @@ class ThemeTest extends TestCase $this->assertStringContainsString('.dummy_func_test2{--x:1000;--y:false}', $contents); } - /** - * @test - */ + #[Test] public function theme_extender_can_add_custom_variable() { $this->extend( diff --git a/framework/core/tests/integration/extenders/ThrottleApiTest.php b/framework/core/tests/integration/extenders/ThrottleApiTest.php index fa121a39a..4ae852159 100644 --- a/framework/core/tests/integration/extenders/ThrottleApiTest.php +++ b/framework/core/tests/integration/extenders/ThrottleApiTest.php @@ -13,6 +13,7 @@ use Flarum\Extend; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class ThrottleApiTest extends TestCase { @@ -32,9 +33,7 @@ class ThrottleApiTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function list_discussions_not_restricted_by_default() { $response = $this->send($this->request('GET', '/api/discussions', ['authenticatedAs' => 2])); @@ -42,9 +41,7 @@ class ThrottleApiTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function list_discussions_can_be_restricted() { $this->extend((new Extend\ThrottleApi)->set('blockListDiscussions', function ($request) { @@ -58,9 +55,7 @@ class ThrottleApiTest extends TestCase $this->assertEquals(429, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function false_overrides_true_for_evaluating_throttlers() { $this->extend( @@ -81,9 +76,7 @@ class ThrottleApiTest extends TestCase $this->assertEquals(200, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function throttling_applies_to_api_client() { $this->extend((new Extend\ThrottleApi)->set('blockRegistration', function ($request) { diff --git a/framework/core/tests/integration/extenders/UserTest.php b/framework/core/tests/integration/extenders/UserTest.php index 18a2821d1..954bd3b62 100644 --- a/framework/core/tests/integration/extenders/UserTest.php +++ b/framework/core/tests/integration/extenders/UserTest.php @@ -15,6 +15,7 @@ use Flarum\Testing\integration\TestCase; use Flarum\User\DisplayName\DriverInterface; use Flarum\User\User; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Test; class UserTest extends TestCase { @@ -44,9 +45,7 @@ class UserTest extends TestCase ); } - /** - * @test - */ + #[Test] public function username_display_name_driver_used_by_default() { $this->app(); @@ -56,9 +55,7 @@ class UserTest extends TestCase $this->assertEquals('admin', $user->displayName); } - /** - * @test - */ + #[Test] public function can_use_custom_display_name_driver() { $this->extend( @@ -73,9 +70,7 @@ class UserTest extends TestCase $this->assertEquals('admin@machine.local$$$suffix', $user->displayName); } - /** - * @test - */ + #[Test] public function user_has_permissions_for_expected_groups_if_no_processors_added() { $this->app(); @@ -85,9 +80,7 @@ class UserTest extends TestCase $this->assertContains('searchUsers', $user->getPermissions()); } - /** - * @test - */ + #[Test] public function processor_can_restrict_user_groups() { $this->extend((new Extend\User)->permissionGroups(function (User $user, array $groupIds) { @@ -103,9 +96,7 @@ class UserTest extends TestCase $this->assertNotContains('searchUsers', $user->getPermissions()); } - /** - * @test - */ + #[Test] public function processor_can_be_invokable_class() { $this->extend((new Extend\User)->permissionGroups(CustomGroupProcessorClass::class)); @@ -117,9 +108,7 @@ class UserTest extends TestCase $this->assertNotContains('searchUsers', $user->getPermissions()); } - /** - * @test - */ + #[Test] public function can_add_user_preference() { $this->registerTestPreference(); @@ -131,9 +120,7 @@ class UserTest extends TestCase $this->assertEquals(true, Arr::get($user->preferences, 'test')); } - /** - * @test - */ + #[Test] public function can_store_user_preference() { $this->registerTestPreference(); @@ -148,9 +135,7 @@ class UserTest extends TestCase $this->assertEquals(false, $user->getPreference('test')); } - /** - * @test - */ + #[Test] public function storing_user_preference_modified_by_transformer() { $this->registerTestPreference(); diff --git a/framework/core/tests/integration/extenders/ValidatorTest.php b/framework/core/tests/integration/extenders/ValidatorTest.php index cf83bd0d6..8e3c344d3 100644 --- a/framework/core/tests/integration/extenders/ValidatorTest.php +++ b/framework/core/tests/integration/extenders/ValidatorTest.php @@ -14,6 +14,7 @@ use Flarum\Foundation\AbstractValidator; use Flarum\Testing\integration\TestCase; use Flarum\User\User; use Illuminate\Validation\ValidationException; +use PHPUnit\Framework\Attributes\Test; class ValidatorTest extends TestCase { @@ -34,9 +35,7 @@ class ValidatorTest extends TestCase $this->extend((new Extend\Validator(CustomUserValidator::class))->configure(CustomValidatorClass::class)); } - /** - * @test - */ + #[Test] public function custom_validation_rule_does_not_exist_by_default() { $this->app()->getContainer()->make(CustomUserValidator::class)->assertValid(['password' => 'simplePassword']); @@ -45,9 +44,7 @@ class ValidatorTest extends TestCase $this->assertTrue(true); } - /** - * @test - */ + #[Test] public function custom_validation_rule_exists_if_added() { $this->extendToRequireLongPassword(); @@ -57,9 +54,7 @@ class ValidatorTest extends TestCase $this->app()->getContainer()->make(CustomUserValidator::class)->assertValid(['password' => 'simplePassword']); } - /** - * @test - */ + #[Test] public function custom_validation_rule_exists_if_added_via_invokable_class() { $this->extendToRequireLongPasswordViaInvokableClass(); @@ -69,9 +64,7 @@ class ValidatorTest extends TestCase $this->app()->getContainer()->make(CustomUserValidator::class)->assertValid(['password' => 'simplePassword']); } - /** - * @test - */ + #[Test] public function custom_validation_rule_doesnt_affect_other_validators() { $this->extendToRequireLongPassword(); diff --git a/framework/core/tests/integration/extenders/ViewTest.php b/framework/core/tests/integration/extenders/ViewTest.php index 7eb87a274..a50b76297 100644 --- a/framework/core/tests/integration/extenders/ViewTest.php +++ b/framework/core/tests/integration/extenders/ViewTest.php @@ -12,21 +12,18 @@ namespace Flarum\Tests\integration\extenders; use Flarum\Extend; use Flarum\Testing\integration\TestCase; use Illuminate\Contracts\View\Factory; +use PHPUnit\Framework\Attributes\Test; class ViewTest extends TestCase { - /** - * @test - */ + #[Test] public function custom_view_namespace_does_not_exist_by_default() { $this->expectException(\InvalidArgumentException::class); $this->app()->getContainer()->make(Factory::class)->make('integration.test::test'); } - /** - * @test - */ + #[Test] public function custom_view_namespace_can_be_added_by_extender() { $this->extend( @@ -37,9 +34,7 @@ class ViewTest extends TestCase $this->assertEquals('Hello World!', trim($this->app()->getContainer()->make(Factory::class)->make('integration.test::test')->render())); } - /** - * @test - */ + #[Test] public function can_add_view_to_namespace_by_prepend_extender() { $this->extend( @@ -50,9 +45,7 @@ class ViewTest extends TestCase $this->assertEquals('Hello World!', trim($this->app()->getContainer()->make(Factory::class)->make('flarum::test')->render())); } - /** - * @test - */ + #[Test] public function can_override_view_in_namespace_by_prepend_extender() { $this->extend( diff --git a/framework/core/tests/integration/forum/DefaultRouteTest.php b/framework/core/tests/integration/forum/DefaultRouteTest.php index 788058cef..fcf1acb7a 100644 --- a/framework/core/tests/integration/forum/DefaultRouteTest.php +++ b/framework/core/tests/integration/forum/DefaultRouteTest.php @@ -16,6 +16,7 @@ use Flarum\Foundation\AbstractServiceProvider; use Flarum\Post\Post; use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Testing\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class DefaultRouteTest extends TestCase { @@ -47,9 +48,7 @@ class DefaultRouteTest extends TestCase ); } - /** - * @test - */ + #[Test] public function default_route_payload_includes_discussions() { $response = $this->send( @@ -59,9 +58,7 @@ class DefaultRouteTest extends TestCase $this->assertStringContainsString('apiDocument', $response->getBody()); } - /** - * @test - */ + #[Test] public function nonexistent_custom_homepage_uses_default_payload() { $this->setDefaultRoute('/nonexistent'); @@ -73,9 +70,7 @@ class DefaultRouteTest extends TestCase $this->assertStringContainsString('apiDocument', $response->getBody()); } - /** - * @test - */ + #[Test] public function existent_custom_homepage_doesnt_use_default_payload() { $this->setDefaultRoute('/settings'); diff --git a/framework/core/tests/integration/forum/GlobalLogoutTest.php b/framework/core/tests/integration/forum/GlobalLogoutTest.php index d4c84dbcc..ad9be5508 100644 --- a/framework/core/tests/integration/forum/GlobalLogoutTest.php +++ b/framework/core/tests/integration/forum/GlobalLogoutTest.php @@ -17,6 +17,8 @@ use Flarum\Testing\integration\TestCase; use Flarum\User\EmailToken; use Flarum\User\PasswordToken; use Flarum\User\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class GlobalLogoutTest extends TestCase { @@ -56,10 +58,8 @@ class GlobalLogoutTest extends TestCase ]); } - /** - * @dataProvider canGloballyLogoutDataProvider - * @test - */ + #[Test] + #[DataProvider('canGloballyLogoutDataProvider')] public function can_globally_log_out(int $authenticatedAs) { $response = $this->send( @@ -75,7 +75,7 @@ class GlobalLogoutTest extends TestCase $this->assertEquals(0, PasswordToken::query()->where('user_id', $authenticatedAs)->count()); } - public function canGloballyLogoutDataProvider(): array + public static function canGloballyLogoutDataProvider(): array { return [ // Admin diff --git a/framework/core/tests/integration/forum/IndexTest.php b/framework/core/tests/integration/forum/IndexTest.php index cd02d2935..de2582a7d 100644 --- a/framework/core/tests/integration/forum/IndexTest.php +++ b/framework/core/tests/integration/forum/IndexTest.php @@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\forum; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class IndexTest extends TestCase { @@ -29,9 +30,7 @@ class IndexTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function guest_not_serialized_by_current_user_serializer() { $response = $this->send( @@ -42,9 +41,7 @@ class IndexTest extends TestCase $this->assertStringNotContainsString('preferences', $response->getBody()->getContents()); } - /** - * @test - */ + #[Test] public function user_serialized_by_current_user_serializer() { $response = $this->send( diff --git a/framework/core/tests/integration/forum/LoginTest.php b/framework/core/tests/integration/forum/LoginTest.php index eef7239b3..6165b3cf9 100644 --- a/framework/core/tests/integration/forum/LoginTest.php +++ b/framework/core/tests/integration/forum/LoginTest.php @@ -14,6 +14,7 @@ use Flarum\Http\AccessToken; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class LoginTest extends TestCase { @@ -35,9 +36,7 @@ class LoginTest extends TestCase ]); } - /** - * @test - */ + #[Test] public function cant_login_without_data() { $response = $this->send( @@ -49,9 +48,7 @@ class LoginTest extends TestCase $this->assertEquals(401, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function cant_login_with_wrong_password() { $response = $this->send( @@ -66,9 +63,7 @@ class LoginTest extends TestCase $this->assertEquals(401, $response->getStatusCode()); } - /** - * @test - */ + #[Test] public function can_login_with_data() { $response = $this->send( diff --git a/framework/core/tests/integration/forum/RegisterTest.php b/framework/core/tests/integration/forum/RegisterTest.php index 3cb5631a0..b9bfcc8c5 100644 --- a/framework/core/tests/integration/forum/RegisterTest.php +++ b/framework/core/tests/integration/forum/RegisterTest.php @@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\forum; use Flarum\Extend; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class RegisterTest extends TestCase { @@ -25,9 +26,7 @@ class RegisterTest extends TestCase ); } - /** - * @test - */ + #[Test] public function cant_register_without_data() { $response = $this->send( @@ -64,9 +63,7 @@ class RegisterTest extends TestCase ], json_decode($body, true)); } - /** - * @test - */ + #[Test] public function can_register_with_data() { $response = $this->send( diff --git a/framework/core/tests/integration/middleware/ContentTypeOptionsTest.php b/framework/core/tests/integration/middleware/ContentTypeOptionsTest.php index 4109b57d6..53efbc40b 100644 --- a/framework/core/tests/integration/middleware/ContentTypeOptionsTest.php +++ b/framework/core/tests/integration/middleware/ContentTypeOptionsTest.php @@ -10,12 +10,11 @@ namespace Flarum\Tests\integration\middleware; use Flarum\Testing\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class ContentTypeOptionsTest extends TestCase { - /** - * @test - */ + #[Test] public function has_content_type_options_header() { $response = $this->send( diff --git a/framework/core/tests/integration/middleware/ReferrerPolicyTest.php b/framework/core/tests/integration/middleware/ReferrerPolicyTest.php index 734f0082b..7fe2a3b53 100644 --- a/framework/core/tests/integration/middleware/ReferrerPolicyTest.php +++ b/framework/core/tests/integration/middleware/ReferrerPolicyTest.php @@ -10,12 +10,11 @@ namespace Flarum\Tests\integration\middleware; use Flarum\Testing\integration\TestCase; +use PHPUnit\Framework\Attributes\Test; class ReferrerPolicyTest extends TestCase { - /** - * @test - */ + #[Test] public function has_referer_header() { $response = $this->send( @@ -25,9 +24,7 @@ class ReferrerPolicyTest extends TestCase $this->assertArrayHasKey('Referrer-Policy', $response->getHeaders()); } - /** - * @test - */ + #[Test] public function has_default_referer_policy() { $response = $this->send( diff --git a/framework/core/tests/integration/notification/NotificationSyncerTest.php b/framework/core/tests/integration/notification/NotificationSyncerTest.php deleted file mode 100644 index 18cb6ff64..000000000 --- a/framework/core/tests/integration/notification/NotificationSyncerTest.php +++ /dev/null @@ -1,120 +0,0 @@ -prepareDatabase([ - User::class => [ - $this->normalUser(), - ['id' => 3, 'username' => 'Receiver', 'email' => 'receiver@machine.local', 'is_email_confirmed' => 1], - ], - Discussion::class => [ - ['id' => 1, 'title' => 'Public discussion', 'created_at' => Carbon::parse('2021-11-01 13:00:00')->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 2, 'is_private' => 0, 'last_post_number' => 2], - - ['id' => 2, 'title' => 'Private discussion', 'created_at' => Carbon::parse('2021-11-01 13:00:00')->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 3, 'comment_count' => 2, 'is_private' => 1, 'last_post_number' => 2], - ], - Post::class => [ - ['id' => 1, 'discussion_id' => 1, 'number' => 1, 'created_at' => Carbon::parse('2021-11-01 13:00:00')->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => '', 'is_private' => 0], - ['id' => 2, 'discussion_id' => 1, 'number' => 2, 'created_at' => Carbon::parse('2021-11-01 13:00:03')->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => '', 'is_private' => 1], - - ['id' => 3, 'discussion_id' => 2, 'number' => 1, 'created_at' => Carbon::parse('2021-11-01 13:00:00')->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => '', 'is_private' => 0], - ], - ]); - } - - /** - * @param class-string $subjectClass - */ - protected function expect_notification_count_from_sending_notification_type_with_subject(int $count, string $subjectClass, int $subjectId, string $serializer) - { - CustomNotificationType::$subjectModel = $subjectClass; - - $this->extend( - (new Extend\Notification()) - ->type(CustomNotificationType::class, $serializer, ['alert']) - ); - - /** @var NotificationSyncer $syncer */ - $syncer = $this->app()->getContainer()->make(NotificationSyncer::class); - - $subject = $subjectClass::query()->find($subjectId); - - $syncer->sync( - $blueprint = new CustomNotificationType($subject), - User::query() - ->whereIn('id', [1, 3]) - ->get() - ->all() - ); - - $this->assertEquals( - $count, - Notification::query() - ->matchingBlueprint($blueprint) - ->whereSubject($subject) - ->count() - ); - } -} - -class CustomNotificationType implements BlueprintInterface -{ - protected $subject; - public static $subjectModel; - - public function __construct($subject) - { - $this->subject = $subject; - } - - public function getFromUser(): ?User - { - return null; - } - - public function getSubject(): ?AbstractModel - { - return $this->subject; - } - - public function getData(): array - { - return []; - } - - public static function getType(): string - { - return 'customNotificationType'; - } - - public static function getSubjectModel(): string - { - return self::$subjectModel; - } -} diff --git a/framework/core/tests/integration/policy/DiscussionPolicyTest.php b/framework/core/tests/integration/policy/DiscussionPolicyTest.php index 45cb91946..7623a6a13 100644 --- a/framework/core/tests/integration/policy/DiscussionPolicyTest.php +++ b/framework/core/tests/integration/policy/DiscussionPolicyTest.php @@ -18,6 +18,7 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class DiscussionPolicyTest extends TestCase { @@ -54,9 +55,7 @@ class DiscussionPolicyTest extends TestCase Carbon::setTestNow(); } - /** - * @test - */ + #[Test] public function rename_indefinitely() { $this->setting('allow_renaming', '-1'); @@ -76,9 +75,7 @@ class DiscussionPolicyTest extends TestCase $this->assertTrue($user->can('rename', $discussion)); } - /** - * @test - */ + #[Test] public function rename_until_reply() { $this->setting('allow_renaming', 'reply'); @@ -126,9 +123,7 @@ class DiscussionPolicyTest extends TestCase $this->assertFalse($user->can('rename', $discussionWithReply)); } - /** - * @test - */ + #[Test] public function rename_10_minutes() { $this->setting('allow_renaming', '10'); diff --git a/framework/core/tests/integration/policy/PostPolicyTest.php b/framework/core/tests/integration/policy/PostPolicyTest.php index b5e185b90..dd9d0e415 100644 --- a/framework/core/tests/integration/policy/PostPolicyTest.php +++ b/framework/core/tests/integration/policy/PostPolicyTest.php @@ -15,6 +15,7 @@ use Flarum\Post\Post; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\Test; class PostPolicyTest extends TestCase { @@ -48,9 +49,7 @@ class PostPolicyTest extends TestCase Carbon::setTestNow(); } - /** - * @test - */ + #[Test] public function edit_indefinitely() { $this->setting('allow_post_editing', '-1'); @@ -73,9 +72,7 @@ class PostPolicyTest extends TestCase $this->assertTrue($user->can('edit', $lastPost)); } - /** - * @test - */ + #[Test] public function edit_until_reply() { $this->setting('allow_post_editing', 'reply'); @@ -98,9 +95,7 @@ class PostPolicyTest extends TestCase $this->assertTrue($user->can('edit', $lastPost)); } - /** - * @test - */ + #[Test] public function edit_10_minutes() { $this->setting('allow_post_editing', '10'); @@ -123,9 +118,7 @@ class PostPolicyTest extends TestCase $this->assertFalse($user->can('edit', $lastPost)); } - /** - * @test - */ + #[Test] public function hide_indefinitely() { $this->setting('allow_hide_own_posts', '-1'); @@ -148,9 +141,7 @@ class PostPolicyTest extends TestCase $this->assertTrue($user->can('hide', $lastPost)); } - /** - * @test - */ + #[Test] public function hide_until_reply() { $this->setting('allow_hide_own_posts', 'reply'); @@ -173,9 +164,7 @@ class PostPolicyTest extends TestCase $this->assertTrue($user->can('hide', $lastPost)); } - /** - * @test - */ + #[Test] public function hide_10_minutes() { $this->setting('allow_hide_own_posts', '10'); @@ -198,9 +187,7 @@ class PostPolicyTest extends TestCase $this->assertFalse($user->can('hide', $lastPost)); } - /** - * @test - */ + #[Test] public function hide_never() { $this->setting('allow_hide_own_posts', '0'); diff --git a/framework/core/tests/integration/slugger/SlugDriverTest.php b/framework/core/tests/integration/slugger/SlugDriverTest.php index b8bd7d39e..3989e1106 100644 --- a/framework/core/tests/integration/slugger/SlugDriverTest.php +++ b/framework/core/tests/integration/slugger/SlugDriverTest.php @@ -15,6 +15,8 @@ use Flarum\Http\SlugManager; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; use Flarum\User\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class SlugDriverTest extends TestCase { @@ -38,10 +40,8 @@ class SlugDriverTest extends TestCase ]); } - /** - * @dataProvider slugInstancePairDataProvider - * @test - */ + #[Test] + #[DataProvider('slugInstancePairDataProvider')] public function slugger_formats_the_correct_slug_from_instance(string $driver, string $modelClassName, int $id, string $slug) { $this->setting("slug_driver_$modelClassName", $driver); @@ -59,10 +59,8 @@ class SlugDriverTest extends TestCase $this->assertEquals($slug, $slugger->toSlug($instance)); } - /** - * @dataProvider slugInstancePairDataProvider - * @test - */ + #[Test] + #[DataProvider('slugInstancePairDataProvider')] public function slugger_returns_the_correct_instance_from_slug(string $driver, string $modelClassName, int $id, string $slug) { $this->setting("slug_driver_$modelClassName", $driver); @@ -73,7 +71,7 @@ class SlugDriverTest extends TestCase $this->assertEquals($modelClassName::query()->find($id), $slugger->fromSlug($slug, User::query()->find(1))); } - public function slugInstancePairDataProvider(): array + public static function slugInstancePairDataProvider(): array { return [ ['default', Discussion::class, 20, '20-empty-discussion'], diff --git a/framework/core/tests/phpunit.integration.xml b/framework/core/tests/phpunit.integration.xml index 7319d929a..e3e14eab9 100644 --- a/framework/core/tests/phpunit.integration.xml +++ b/framework/core/tests/phpunit.integration.xml @@ -1,22 +1,20 @@ - + ../src/ - + ./integration diff --git a/framework/core/tests/phpunit.unit.xml b/framework/core/tests/phpunit.unit.xml index 66262dd9f..67367a782 100644 --- a/framework/core/tests/phpunit.unit.xml +++ b/framework/core/tests/phpunit.unit.xml @@ -1,28 +1,23 @@ - + ../src/ - + ./unit - - - diff --git a/framework/core/tests/unit/Foundation/ConfigTest.php b/framework/core/tests/unit/Foundation/ConfigTest.php index 4d0cbbd84..4f3d03f9d 100644 --- a/framework/core/tests/unit/Foundation/ConfigTest.php +++ b/framework/core/tests/unit/Foundation/ConfigTest.php @@ -13,11 +13,12 @@ use Flarum\Foundation\Config; use Flarum\Foundation\MaintenanceMode; use Flarum\Testing\unit\TestCase; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\Test; use RuntimeException; class ConfigTest extends TestCase { - /** @test */ + #[Test] public function it_complains_when_base_url_is_missing() { $this->expectException(InvalidArgumentException::class); @@ -25,7 +26,7 @@ class ConfigTest extends TestCase new Config([]); } - /** @test */ + #[Test] public function it_wraps_base_url_in_value_object() { $config = new Config([ @@ -38,7 +39,7 @@ class ConfigTest extends TestCase $this->assertEquals('https://flarum.localhost/myforum', (string) $url); } - /** @test */ + #[Test] public function it_has_a_helper_for_debug_mode() { $config = new Config([ @@ -56,7 +57,7 @@ class ConfigTest extends TestCase $this->assertTrue($config->inDebugMode()); } - /** @test */ + #[Test] public function it_turns_off_debug_mode_by_default() { $config = new Config([ @@ -66,7 +67,7 @@ class ConfigTest extends TestCase $this->assertFalse($config->inDebugMode()); } - /** @test */ + #[Test] public function it_has_a_helper_for_maintenance_mode() { $config = new Config([ @@ -102,7 +103,7 @@ class ConfigTest extends TestCase $this->assertFalse($config->inHighMaintenanceMode()); } - /** @test */ + #[Test] public function it_turns_off_maintenance_mode_by_default() { $config = new Config([ @@ -112,7 +113,7 @@ class ConfigTest extends TestCase $this->assertFalse($config->inHighMaintenanceMode()); } - /** @test */ + #[Test] public function it_exposes_additional_keys_via_array_access() { $config = new Config([ @@ -123,7 +124,7 @@ class ConfigTest extends TestCase $this->assertEquals('b', $config['custom_a']); } - /** @test */ + #[Test] public function it_exposes_nested_keys_via_dot_syntax() { $config = new Config([ @@ -138,7 +139,7 @@ class ConfigTest extends TestCase $this->assertEquals('2', $config['nested.second']); } - /** @test */ + #[Test] public function it_does_not_allow_mutation_via_array_access() { $config = new Config([ @@ -155,7 +156,7 @@ class ConfigTest extends TestCase $this->assertEquals('b', $config['custom_a']); } - /** @test */ + #[Test] public function it_does_not_allow_removal_via_array_access() { $config = new Config([ diff --git a/framework/core/tests/unit/Foundation/ContainerUtilTest.php b/framework/core/tests/unit/Foundation/ContainerUtilTest.php index 1dbe77a57..be0aed6fe 100644 --- a/framework/core/tests/unit/Foundation/ContainerUtilTest.php +++ b/framework/core/tests/unit/Foundation/ContainerUtilTest.php @@ -12,6 +12,7 @@ namespace Flarum\Tests\unit\Foundation; use Flarum\Foundation\ContainerUtil; use Flarum\Testing\unit\TestCase; use Illuminate\Container\Container; +use PHPUnit\Framework\Attributes\Test; class ContainerUtilTest extends TestCase { @@ -27,7 +28,7 @@ class ContainerUtilTest extends TestCase $this->container = new Container(); } - /** @test */ + #[Test] public function it_works_with_closures() { $callback = ContainerUtil::wrapCallback(function ($array) { @@ -43,7 +44,7 @@ class ContainerUtilTest extends TestCase $this->assertEquals('return', $return); } - /** @test */ + #[Test] public function it_works_with_invokable_classes() { $callback = ContainerUtil::wrapCallback(CustomInvokableClass::class, $this->container); @@ -55,7 +56,7 @@ class ContainerUtilTest extends TestCase $this->assertEquals('return2', $return); } - /** @test */ + #[Test] public function it_works_with_invokable_objects() { $callback = ContainerUtil::wrapCallback(new class { @@ -74,7 +75,7 @@ class ContainerUtilTest extends TestCase $this->assertEquals('return5', $return); } - /** @test */ + #[Test] public function it_works_with_global_functions() { $callback = ContainerUtil::wrapCallback('boolval', $this->container); @@ -86,7 +87,7 @@ class ContainerUtilTest extends TestCase $this->assertEquals(false, $callback(false)); } - /** @test */ + #[Test] public function it_works_with_static_class_method_arrays() { $callback = ContainerUtil::wrapCallback([ClassWithMethod::class, 'staticMethod'], $this->container); @@ -94,7 +95,7 @@ class ContainerUtilTest extends TestCase $this->assertEquals('returnStatic', $callback()); } - /** @test */ + #[Test] public function it_allows_passing_args_by_reference_on_closures() { $callback = ContainerUtil::wrapCallback(function (&$array) { @@ -110,7 +111,7 @@ class ContainerUtilTest extends TestCase $this->assertEquals('return3', $return); } - /** @test */ + #[Test] public function it_allows_passing_args_by_reference_on_invokable_classes() { $callback = ContainerUtil::wrapCallback(SecondCustomInvokableClass::class, $this->container); @@ -122,7 +123,7 @@ class ContainerUtilTest extends TestCase $this->assertEquals('return4', $return); } - /** @test */ + #[Test] public function it_allows_passing_args_by_reference_on_invokable_objects() { $callback = ContainerUtil::wrapCallback(new class { diff --git a/framework/core/tests/unit/Foundation/ExtensionDependencyResolutionTest.php b/framework/core/tests/unit/Foundation/ExtensionDependencyResolutionTest.php index d75ba6cf6..ca96f3c83 100644 --- a/framework/core/tests/unit/Foundation/ExtensionDependencyResolutionTest.php +++ b/framework/core/tests/unit/Foundation/ExtensionDependencyResolutionTest.php @@ -11,6 +11,7 @@ namespace Flarum\Tests\unit\Foundation; use Flarum\Extension\ExtensionManager; use Flarum\Testing\unit\TestCase; +use PHPUnit\Framework\Attributes\Test; class ExtensionDependencyResolutionTest extends TestCase { @@ -39,7 +40,7 @@ class ExtensionDependencyResolutionTest extends TestCase $this->optionalDependencyCategories = new FakeExtension('flarum-categories', ['flarum-tags'], ['flarum-tag-backgrounds', 'non-existent-optional-dependency']); } - /** @test */ + #[Test] public function works_with_empty_set() { $expected = [ @@ -51,7 +52,7 @@ class ExtensionDependencyResolutionTest extends TestCase $this->assertEquals($expected, ExtensionManager::resolveExtensionOrder([])); } - /** @test */ + #[Test] public function works_with_proper_data() { $exts = [$this->tags, $this->categories, $this->tagBackgrounds, $this->something, $this->help]; @@ -65,7 +66,7 @@ class ExtensionDependencyResolutionTest extends TestCase $this->assertEquals($expected, ExtensionManager::resolveExtensionOrder($exts)); } - /** @test */ + #[Test] public function works_with_missing_dependencies() { $exts = [$this->tags, $this->categories, $this->tagBackgrounds, $this->something, $this->help, $this->missing]; @@ -79,7 +80,7 @@ class ExtensionDependencyResolutionTest extends TestCase $this->assertEquals($expected, ExtensionManager::resolveExtensionOrder($exts)); } - /** @test */ + #[Test] public function works_with_circular_dependencies() { $exts = [$this->tags, $this->categories, $this->tagBackgrounds, $this->something, $this->help, $this->circular1, $this->circular2]; @@ -93,7 +94,7 @@ class ExtensionDependencyResolutionTest extends TestCase $this->assertEquals($expected, ExtensionManager::resolveExtensionOrder($exts)); } - /** @test */ + #[Test] public function works_with_optional_dependencies() { $exts = [$this->tags, $this->optionalDependencyCategories, $this->tagBackgrounds, $this->something, $this->help]; @@ -107,7 +108,7 @@ class ExtensionDependencyResolutionTest extends TestCase $this->assertEquals($expected, ExtensionManager::resolveExtensionOrder($exts)); } - /** @test */ + #[Test] public function works_with_optional_dependencies_if_optional_dependency_missing() { $exts = [$this->tags, $this->optionalDependencyCategories, $this->something, $this->help]; diff --git a/framework/core/tests/unit/Foundation/PathsTest.php b/framework/core/tests/unit/Foundation/PathsTest.php index e29b065cf..5f669722d 100644 --- a/framework/core/tests/unit/Foundation/PathsTest.php +++ b/framework/core/tests/unit/Foundation/PathsTest.php @@ -12,10 +12,11 @@ namespace Flarum\Tests\unit\Foundation; use Flarum\Foundation\Paths; use Flarum\Testing\unit\TestCase; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\Test; class PathsTest extends TestCase { - /** @test */ + #[Test] public function it_complains_when_paths_are_missing() { $this->expectException(InvalidArgumentException::class); @@ -25,7 +26,7 @@ class PathsTest extends TestCase ]); } - /** @test */ + #[Test] public function it_makes_paths_available_as_properties() { $paths = new Paths([ @@ -39,7 +40,7 @@ class PathsTest extends TestCase $this->assertEquals('/var/www/flarum/storage', $paths->storage); } - /** @test */ + #[Test] public function it_derives_the_vendor_dir_from_the_base_path() { $paths = new Paths([ @@ -51,7 +52,7 @@ class PathsTest extends TestCase $this->assertEquals('/var/www/flarum/vendor', $paths->vendor); } - /** @test */ + #[Test] public function it_allows_setting_a_custom_vendor_dir() { $paths = new Paths([ @@ -64,7 +65,7 @@ class PathsTest extends TestCase $this->assertEquals('/share/composer-vendor', $paths->vendor); } - /** @test */ + #[Test] public function it_strips_trailing_forward_slashes_from_paths() { $paths = new Paths([ @@ -78,7 +79,7 @@ class PathsTest extends TestCase $this->assertEquals('/var/www/flarum/storage', $paths->storage); } - /** @test */ + #[Test] public function it_strips_trailing_backslashes_from_paths() { $paths = new Paths([ diff --git a/framework/core/tests/unit/Foundation/RouteCollectionTest.php b/framework/core/tests/unit/Foundation/RouteCollectionTest.php index a1699225c..d1f1c2d3b 100644 --- a/framework/core/tests/unit/Foundation/RouteCollectionTest.php +++ b/framework/core/tests/unit/Foundation/RouteCollectionTest.php @@ -11,11 +11,12 @@ namespace Flarum\Tests\unit\Foundation; use Flarum\Http\RouteCollection; use Flarum\Testing\unit\TestCase; +use PHPUnit\Framework\Attributes\Test; use RuntimeException; class RouteCollectionTest extends TestCase { - /** @test */ + #[Test] public function it_errors_when_nonexistent_route_requested() { $collection = new RouteCollection(); @@ -25,7 +26,7 @@ class RouteCollectionTest extends TestCase $collection->getPath('nonexistent'); } - /** @test */ + #[Test] public function it_properly_processes_a_simple_route_with_no_parameters() { $collection = new RouteCollection(); @@ -35,7 +36,7 @@ class RouteCollectionTest extends TestCase $this->assertEquals('/custom/route', $collection->getPath('custom')); } - /** @test */ + #[Test] public function it_properly_processes_a_route_with_all_parameters_required() { $collection = new RouteCollection(); @@ -49,7 +50,7 @@ class RouteCollectionTest extends TestCase ])); } - /** @test */ + #[Test] public function it_works_if_optional_parameters_are_missing() { $collection = new RouteCollection(); @@ -61,7 +62,7 @@ class RouteCollectionTest extends TestCase ])); } - /** @test */ + #[Test] public function it_works_with_optional_parameters() { $collection = new RouteCollection(); diff --git a/framework/core/tests/unit/Http/CookieFactoryTest.php b/framework/core/tests/unit/Http/CookieFactoryTest.php index c0bab6463..231d341de 100644 --- a/framework/core/tests/unit/Http/CookieFactoryTest.php +++ b/framework/core/tests/unit/Http/CookieFactoryTest.php @@ -13,6 +13,7 @@ use Carbon\Carbon; use Flarum\Foundation\Config; use Flarum\Http\CookieFactory; use Flarum\Testing\unit\TestCase; +use PHPUnit\Framework\Attributes\Test; class CookieFactoryTest extends TestCase { @@ -25,7 +26,7 @@ class CookieFactoryTest extends TestCase return new CookieFactory($config); } - /** @test */ + #[Test] public function can_create_cookies() { $cookie = $this->factory()->make('test', 'australia'); @@ -37,7 +38,7 @@ class CookieFactoryTest extends TestCase $this->assertEquals('/', $cookie->getPath()); } - /** @test */ + #[Test] public function can_override_cookie_settings_from_config() { $cookie = $this->factory([ @@ -55,7 +56,7 @@ class CookieFactoryTest extends TestCase $this->assertEquals('SameSite=None', $cookie->getSameSite()->asString()); } - /** @test */ + #[Test] public function can_expire_cookies() { $cookie = $this->factory()->expire('test'); diff --git a/framework/core/tests/unit/Http/RouteCollectionTest.php b/framework/core/tests/unit/Http/RouteCollectionTest.php index 00db58d5f..1cdb2bc48 100644 --- a/framework/core/tests/unit/Http/RouteCollectionTest.php +++ b/framework/core/tests/unit/Http/RouteCollectionTest.php @@ -11,10 +11,11 @@ namespace Flarum\Tests\unit\Http; use Flarum\Http\RouteCollection; use Flarum\Testing\unit\TestCase; +use PHPUnit\Framework\Attributes\Test; class RouteCollectionTest extends TestCase { - /** @test */ + #[Test] public function can_add_routes() { $routeCollection = (new RouteCollection) @@ -29,7 +30,7 @@ class RouteCollectionTest extends TestCase $this->assertEquals('/posts', $routeCollection->getPath('forum.posts.delete')); } - /** @test */ + #[Test] public function can_add_routes_late() { $routeCollection = (new RouteCollection)->addRoute('GET', '/index', 'index', function () { @@ -45,7 +46,7 @@ class RouteCollectionTest extends TestCase $this->assertEquals('/posts', $routeCollection->getPath('forum.posts.delete')); } - /** @test */ + #[Test] public function must_provide_required_parameters() { $this->expectException(\InvalidArgumentException::class); @@ -58,7 +59,7 @@ class RouteCollectionTest extends TestCase $routeCollection->getPath('user', []); } - /** @test */ + #[Test] public function dont_need_to_provide_optional_parameters() { $routeCollection = (new RouteCollection)->addRoute('GET', '/user/{user}[/{test}]', 'user', function () { @@ -70,7 +71,7 @@ class RouteCollectionTest extends TestCase $this->assertEquals('/user/SomeUser', $path); } - /** @test */ + #[Test] public function can_provide_optional_parameters() { $routeCollection = (new RouteCollection)->addRoute('GET', '/user/{user}[/{test}]', 'user', function () { diff --git a/framework/core/tests/unit/Install/BaseUrlTest.php b/framework/core/tests/unit/Install/BaseUrlTest.php index b9777d2bc..76bf39f60 100644 --- a/framework/core/tests/unit/Install/BaseUrlTest.php +++ b/framework/core/tests/unit/Install/BaseUrlTest.php @@ -12,20 +12,17 @@ namespace Flarum\Tests\unit\Install; use Flarum\Install\BaseUrl; use Flarum\Testing\unit\TestCase; use Laminas\Diactoros\Uri; +use PHPUnit\Framework\Attributes\DataProvider; class BaseUrlTest extends TestCase { - /** - * @dataProvider urlProvider - */ + #[DataProvider('urlProvider')] public function test_base_url_simulating_cli_installer($uri, $expected) { $this->assertEquals($expected, BaseUrl::fromString($uri)); } - /** - * @dataProvider urlProvider - */ + #[DataProvider('urlProvider')] public function test_base_url_simulating_web_installer($uri, $expected) { $uri = new Uri($uri); @@ -33,9 +30,7 @@ class BaseUrlTest extends TestCase $this->assertEquals($expected, BaseUrl::fromUri($uri)); } - /** - * @dataProvider emailProvider - */ + #[DataProvider('emailProvider')] public function test_default_email_generation($uri, $expected) { $this->assertEquals( @@ -44,7 +39,7 @@ class BaseUrlTest extends TestCase ); } - public function urlProvider() + public static function urlProvider() { return [ ['', ''], @@ -75,7 +70,7 @@ class BaseUrlTest extends TestCase ]; } - public function emailProvider() + public static function emailProvider() { return [ ['flarum.org', 'noreply@flarum.org'], diff --git a/php-packages/phpstan/.gitignore b/php-packages/phpstan/.gitignore index 30e01fbd2..87a995b34 100644 --- a/php-packages/phpstan/.gitignore +++ b/php-packages/phpstan/.gitignore @@ -3,6 +3,7 @@ composer.lock composer.phar .DS_Store Thumbs.db +tests/.phpunit.cache tests/.phpunit.result.cache /tests/integration/tmp .vagrant diff --git a/php-packages/phpstan/phpstan-baseline.neon b/php-packages/phpstan/phpstan-baseline.neon index 9add6ef15..7e7d38a3c 100644 --- a/php-packages/phpstan/phpstan-baseline.neon +++ b/php-packages/phpstan/phpstan-baseline.neon @@ -50,3 +50,5 @@ parameters: # Ignore overriden classes from packages so that it's always easier to keep track of what's being overriden. - message: '#^Method Flarum\\Api\\Serializer\:\:[A-z0-9_]+\(\) has parameter \$[A-z0-9_]+ with no type specified\.$#' - message: '#^Method Flarum\\Api\\Endpoint\\[A-z0-9_]+\:\:[A-z0-9_]+\(\) has parameter \$[A-z0-9_]+ with no type specified\.$#' + + - message: '#^Unable to resolve the template type TRelatedModel in call to method Illuminate\\Database\\Eloquent\\Model\:\:[A-z]+\(\)$#' diff --git a/php-packages/testing/composer.json b/php-packages/testing/composer.json index d9f15262d..c8e7a885a 100644 --- a/php-packages/testing/composer.json +++ b/php-packages/testing/composer.json @@ -10,7 +10,7 @@ "require": { "ext-json": "*", "mockery/mockery": "^1.5", - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^11.0" }, "require-dev": { "flarum/core": "*@dev" diff --git a/php-packages/testing/tests/tests/phpunit.integration.xml b/php-packages/testing/tests/tests/phpunit.integration.xml index f9fbdf591..5f2ed2eb9 100644 --- a/php-packages/testing/tests/tests/phpunit.integration.xml +++ b/php-packages/testing/tests/tests/phpunit.integration.xml @@ -1,22 +1,20 @@ - + ../src/ - + ./integration diff --git a/php-packages/testing/tests/tests/phpunit.unit.xml b/php-packages/testing/tests/tests/phpunit.unit.xml index 66262dd9f..67367a782 100644 --- a/php-packages/testing/tests/tests/phpunit.unit.xml +++ b/php-packages/testing/tests/tests/phpunit.unit.xml @@ -1,28 +1,23 @@ - + ../src/ - + ./unit - - -