Skip to content

Commit

Permalink
chore: phpunit 11
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Aug 2, 2024
1 parent 2f92a6c commit 0ed6c35
Show file tree
Hide file tree
Showing 89 changed files with 614 additions and 1,456 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
},
"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"
Expand Down
4 changes: 2 additions & 2 deletions framework/core/tests/integration/admin/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function setUp(): void
]);
}

public function admin_can_access_admin_route(): void
public function test_admin_can_access_admin_route(): void
{
$response = $this->send(
$this->request('GET', '/admin', [
Expand All @@ -40,7 +40,7 @@ public function admin_can_access_admin_route(): void
$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', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Laminas\Diactoros\ServerRequest;
use PHPUnit\Framework\Attributes\Test;

class AccessTokenLifecycleTest extends TestCase
{
Expand All @@ -35,9 +36,7 @@ protected function setUp(): void
]);
}

/**
* @test
*/
#[Test]
public function tokens_expire()
{
$this->populateDatabase();
Expand All @@ -52,9 +51,7 @@ public function tokens_expire()
$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();
Expand All @@ -69,9 +66,7 @@ public function tokens_valid()
$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();
Expand All @@ -87,9 +82,7 @@ public function touch_updates_lifetime()
$this->assertTrue(AccessToken::whereValid(Carbon::parse('2021-01-01 03:30:00'))->whereToken('a')->exists());
}

/**
* @test
*/
#[Test]
public function touch_without_request()
{
$this->populateDatabase();
Expand All @@ -104,9 +97,7 @@ public function touch_without_request()
$this->assertNull($token->last_user_agent);
}

/**
* @test
*/
#[Test]
public function touch_with_request()
{
$this->populateDatabase();
Expand All @@ -123,9 +114,7 @@ public function touch_with_request()
$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();
Expand Down
22 changes: 9 additions & 13 deletions framework/core/tests/integration/api/access_tokens/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
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
{
Expand Down Expand Up @@ -42,10 +44,8 @@ protected function setUp(): void
]);
}

/**
* @dataProvider canCreateTokens
* @test
*/
#[Test]
#[DataProvider('canCreateTokens')]
public function user_can_create_developer_tokens(int $authenticatedAs)
{
$response = $this->send(
Expand All @@ -65,10 +65,8 @@ public function user_can_create_developer_tokens(int $authenticatedAs)
$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(
Expand All @@ -88,9 +86,7 @@ public function user_cannot_delete_other_users_tokens(int $authenticatedAs)
$this->assertEquals(403, $response->getStatusCode(), (string) $response->getBody());
}

/**
* @test
*/
#[Test]
public function user_cannot_create_token_without_title()
{
$response = $this->send(
Expand All @@ -108,15 +104,15 @@ public function user_cannot_create_token_without_title()
$this->assertEquals(422, $response->getStatusCode(), (string) $response->getBody());
}

public function canCreateTokens(): array
public static function canCreateTokens(): array
{
return [
[1], // Admin
[3], // User with permission
];
}

public function cannotCreateTokens(): array
public static function cannotCreateTokens(): array
{
return [
[2]
Expand Down
30 changes: 11 additions & 19 deletions framework/core/tests/integration/api/access_tokens/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
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
{
Expand Down Expand Up @@ -56,10 +58,8 @@ protected function setUp(): void
]);
}

/**
* @dataProvider canDeleteTokensDataProvider
* @test
*/
#[Test]
#[DataProvider('canDeleteTokensDataProvider')]
public function user_can_delete_tokens(int $authenticatedAs, array $canDeleteIds)
{
foreach ($canDeleteIds as $id) {
Expand All @@ -71,10 +71,8 @@ public function user_can_delete_tokens(int $authenticatedAs, array $canDeleteIds
}
}

/**
* @dataProvider cannotDeleteTokensDataProvider
* @test
*/
#[Test]
#[DataProvider('cannotDeleteTokensDataProvider')]
public function user_cannot_delete_tokens(int $authenticatedAs, array $canDeleteIds)
{
foreach ($canDeleteIds as $id) {
Expand All @@ -86,9 +84,7 @@ public function user_cannot_delete_tokens(int $authenticatedAs, array $canDelete
}
}

/**
* @test
*/
#[Test]
public function user_cannot_delete_current_session_token()
{
$responseWithSession = $this->send(
Expand Down Expand Up @@ -120,9 +116,7 @@ public function user_cannot_delete_current_session_token()
$this->assertEquals(403, $response->getStatusCode(), $response->getBody()->getContents());
}

/**
* @test
*/
#[Test]
public function user_can_terminate_all_other_sessions()
{
$responseWithSession = $this->send(
Expand Down Expand Up @@ -165,9 +159,7 @@ public function user_can_terminate_all_other_sessions()
);
}

/**
* @test
*/
#[Test]
public function terminting_all_other_sessions_does_not_delete_dev_tokens()
{
$response = $this->send(
Expand All @@ -186,7 +178,7 @@ public function terminting_all_other_sessions_does_not_delete_dev_tokens()
);
}

public function canDeleteTokensDataProvider(): array
public static function canDeleteTokensDataProvider(): array
{
return [
// Admin can delete any user tokens.
Expand All @@ -201,7 +193,7 @@ public function canDeleteTokensDataProvider(): array
];
}

public function cannotDeleteTokensDataProvider(): array
public static function cannotDeleteTokensDataProvider(): array
{
return [
// Normal users cannot delete other users' tokens.
Expand Down
26 changes: 11 additions & 15 deletions framework/core/tests/integration/api/access_tokens/ListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
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
{
Expand Down Expand Up @@ -54,10 +56,8 @@ protected function setUp(): void
]);
}

/**
* @dataProvider canViewTokensDataProvider
* @test
*/
#[Test]
#[DataProvider('canViewTokensDataProvider')]
public function user_can_view_access_tokens(int $authenticatedAs, array $canViewIds)
{
$response = $this->send(
Expand All @@ -72,10 +72,8 @@ public function user_can_view_access_tokens(int $authenticatedAs, array $canView
$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) {
Expand All @@ -101,10 +99,8 @@ public function user_cannot_see_token_values(int $authenticatedAs, ?int $userId,
$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(
Expand All @@ -125,7 +121,7 @@ public function user_needs_permissions_to_use_user_filter(int $authenticatedAs,
$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.
Expand All @@ -140,7 +136,7 @@ public function canViewTokensDataProvider(): array
];
}

public function cannotSeeTokenValuesDataProvider(): array
public static function cannotSeeTokenValuesDataProvider(): array
{
return [
// Admin can only see his own developer token value.
Expand All @@ -161,7 +157,7 @@ public function cannotSeeTokenValuesDataProvider(): array
];
}

public function needsPermissionToUseUserfilterDataProvider(): array
public static function needsPermissionToUseUserfilterDataProvider(): array
{
return [
// Admin can use user filter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Flarum\Http\AccessToken;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use PHPUnit\Framework\Attributes\Test;

class RemembererTest extends TestCase
{
Expand All @@ -33,9 +34,7 @@ protected function setUp(): void
]);
}

/**
* @test
*/
#[Test]
public function non_remember_tokens_cannot_be_used()
{
$this->populateDatabase();
Expand All @@ -54,9 +53,7 @@ public function non_remember_tokens_cannot_be_used()
$this->assertFalse($data['data']['attributes']['canSearchUsers']);
}

/**
* @test
*/
#[Test]
public function expired_tokens_cannot_be_used()
{
$this->populateDatabase();
Expand All @@ -75,9 +72,7 @@ public function expired_tokens_cannot_be_used()
$this->assertFalse($data['data']['attributes']['canSearchUsers']);
}

/**
* @test
*/
#[Test]
public function valid_tokens_can_be_used()
{
$this->populateDatabase();
Expand Down
Loading

0 comments on commit 0ed6c35

Please sign in to comment.