chore: upgrade phpunit to 12.5
This commit is contained in:
1 parent
da039d0527
commit
849da8d471
53 files changed
+832
-856
No files matched your search
@@ -13,7 +13,9 @@ use App\Entity\User;
|
||||
use App\RequiredTeamerCheck\RequiredTeamerCheckRegistry;
|
||||
use App\Security\BpnAuthenticator;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\MockObject\Stub;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -23,14 +25,15 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
|
||||
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
|
||||
|
||||
#[AllowMockObjectsWithoutExpectations]
|
||||
class BpnAuthenticatorTest extends TestCase
|
||||
{
|
||||
private ApiClient&MockObject $apiClient;
|
||||
private ApiClient&Stub $apiClient;
|
||||
private UserDataHandler&MockObject $userDataHandler;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->apiClient = $this->createMock(ApiClient::class);
|
||||
$this->apiClient = $this->createStub(ApiClient::class);
|
||||
$this->userDataHandler = $this->createMock(UserDataHandler::class);
|
||||
}
|
||||
|
||||
@@ -148,12 +151,12 @@ class BpnAuthenticatorTest extends TestCase
|
||||
private function loadUser(): ?User
|
||||
{
|
||||
$authenticator = new BpnAuthenticator(
|
||||
$this->createMock(UrlGeneratorInterface::class),
|
||||
$this->createMock(EntityManagerInterface::class),
|
||||
$this->createStub(UrlGeneratorInterface::class),
|
||||
$this->createStub(EntityManagerInterface::class),
|
||||
$this->apiClient,
|
||||
$this->createMock(LoggerInterface::class),
|
||||
$this->createStub(LoggerInterface::class),
|
||||
$this->userDataHandler,
|
||||
$this->createMock(RequiredTeamerCheckRegistry::class),
|
||||
$this->createStub(RequiredTeamerCheckRegistry::class),
|
||||
);
|
||||
|
||||
$request = new Request(request: [
|
||||
|
||||
@@ -13,6 +13,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Flagception\Manager\FeatureManagerInterface;
|
||||
use League\OAuth2\Client\Token\AccessToken;
|
||||
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@@ -25,6 +26,7 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
|
||||
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
|
||||
|
||||
#[AllowMockObjectsWithoutExpectations]
|
||||
class MyEpAuthenticatorTest extends TestCase
|
||||
{
|
||||
private EntityManagerInterface&MockObject $entityManager;
|
||||
@@ -425,21 +427,21 @@ class MyEpAuthenticatorTest extends TestCase
|
||||
|
||||
private function createAuthenticator(array $userinfo, bool $featureActive = true, ?MockHttpClient $httpClient = null): MyEpAuthenticator
|
||||
{
|
||||
$client = $this->createMock(MyEpClient::class);
|
||||
$client = $this->createStub(MyEpClient::class);
|
||||
$client->method('fetchAccessToken')->willReturn(new AccessToken(['access_token' => 'token']));
|
||||
|
||||
$featureManager = $this->createMock(FeatureManagerInterface::class);
|
||||
$featureManager = $this->createStub(FeatureManagerInterface::class);
|
||||
$featureManager->method('isActive')->willReturn($featureActive);
|
||||
|
||||
return new MyEpAuthenticator(
|
||||
$client,
|
||||
$httpClient ?? $this->userinfoClient($userinfo),
|
||||
new UserDataHandler($this->entityManager, $this->createMock(LoggerInterface::class)),
|
||||
new UserDataHandler($this->entityManager, $this->createStub(LoggerInterface::class)),
|
||||
$this->entityManager,
|
||||
$this->createMock(UrlGeneratorInterface::class),
|
||||
$this->createMock(LoggerInterface::class),
|
||||
$this->createStub(UrlGeneratorInterface::class),
|
||||
$this->createStub(LoggerInterface::class),
|
||||
$featureManager,
|
||||
$this->createMock(RequiredTeamerCheckRegistry::class),
|
||||
$this->createStub(RequiredTeamerCheckRegistry::class),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -137,13 +137,13 @@ class MyEpClientTest extends TestCase
|
||||
|
||||
private function createClient(): MyEpClient
|
||||
{
|
||||
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
|
||||
$urlGenerator = $this->createStub(UrlGeneratorInterface::class);
|
||||
$urlGenerator
|
||||
->method('generate')
|
||||
->willReturn('https://myep-team.example.org/myep-auth/check')
|
||||
;
|
||||
|
||||
return new MyEpClient($urlGenerator, $this->createMock(LoggerInterface::class), [
|
||||
return new MyEpClient($urlGenerator, $this->createStub(LoggerInterface::class), [
|
||||
'myep_oauth2_client_id' => 'client-id',
|
||||
'myep_oauth2_client_secret' => 'client-secret',
|
||||
'myep_oauth2_url_authorize' => 'https://my.example.org/authorize',
|
||||
|
||||
@@ -19,10 +19,7 @@ class DriverLicenseRequiredCheckTest extends TestCase
|
||||
$this->check = new DriverLicenseRequiredCheck();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider mixedRoleProvider
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('mixedRoleProvider')]
|
||||
public function testDoesNotApplyToExcludedMixedRoleUsersWithTeamerRole(string $excludedRole): void
|
||||
{
|
||||
$user = $this->createTeamerUser();
|
||||
@@ -31,7 +28,7 @@ class DriverLicenseRequiredCheckTest extends TestCase
|
||||
$this->assertFalse($this->check->appliesTo($user));
|
||||
}
|
||||
|
||||
public function mixedRoleProvider(): array
|
||||
public static function mixedRoleProvider(): array
|
||||
{
|
||||
return [
|
||||
['ROLE_TEAM_ADMIN'],
|
||||
|
||||
@@ -19,9 +19,7 @@ class FinancialDataRequiredCheckTest extends TestCase
|
||||
$this->check = new FinancialDataRequiredCheck();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider mixedRoleProvider
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('mixedRoleProvider')]
|
||||
public function testDoesNotApplyToExcludedMixedRoleUsersWithTeamerRole(string $excludedRole): void
|
||||
{
|
||||
$user = $this->createTeamerUser();
|
||||
@@ -30,7 +28,7 @@ class FinancialDataRequiredCheckTest extends TestCase
|
||||
$this->assertFalse($this->check->appliesTo($user));
|
||||
}
|
||||
|
||||
public function mixedRoleProvider(): array
|
||||
public static function mixedRoleProvider(): array
|
||||
{
|
||||
return [
|
||||
['ROLE_TEAM_ADMIN'],
|
||||
@@ -76,9 +74,7 @@ class FinancialDataRequiredCheckTest extends TestCase
|
||||
$this->assertFalse($this->check->isSatisfied($user));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider missingBankAccountFieldProvider
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('missingBankAccountFieldProvider')]
|
||||
public function testIsNotSatisfiedWhenBankAccountFieldIsMissing(string $setter): void
|
||||
{
|
||||
$bankAccount = $this->createBankAccount();
|
||||
@@ -93,7 +89,7 @@ class FinancialDataRequiredCheckTest extends TestCase
|
||||
$this->assertFalse($this->check->isSatisfied($user));
|
||||
}
|
||||
|
||||
public function missingBankAccountFieldProvider(): array
|
||||
public static function missingBankAccountFieldProvider(): array
|
||||
{
|
||||
return [
|
||||
['setIban'],
|
||||
|
||||
@@ -19,9 +19,7 @@ class MealPreferenceRequiredCheckTest extends TestCase
|
||||
$this->check = new MealPreferenceRequiredCheck();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider mixedRoleProvider
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('mixedRoleProvider')]
|
||||
public function testDoesNotApplyToExcludedMixedRoleUsersWithTeamerRole(string $excludedRole): void
|
||||
{
|
||||
$user = $this->createTeamerUser();
|
||||
@@ -30,7 +28,7 @@ class MealPreferenceRequiredCheckTest extends TestCase
|
||||
$this->assertFalse($this->check->appliesTo($user));
|
||||
}
|
||||
|
||||
public function mixedRoleProvider(): array
|
||||
public static function mixedRoleProvider(): array
|
||||
{
|
||||
return [
|
||||
['ROLE_TEAM_ADMIN'],
|
||||
|
||||
@@ -30,9 +30,7 @@ class PersonalDataVerificationRequiredCheckTest extends TestCase
|
||||
$this->assertTrue($this->createCheck()->appliesTo($user));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider mixedRoleProvider
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('mixedRoleProvider')]
|
||||
public function testDoesNotApplyToExcludedMixedRoleUsersWithTeamerRole(string $excludedRole): void
|
||||
{
|
||||
$user = (new User())->setRoles([$excludedRole, 'ROLE_TEAMER']);
|
||||
@@ -40,7 +38,7 @@ class PersonalDataVerificationRequiredCheckTest extends TestCase
|
||||
$this->assertFalse($this->createCheck()->appliesTo($user));
|
||||
}
|
||||
|
||||
public function mixedRoleProvider(): array
|
||||
public static function mixedRoleProvider(): array
|
||||
{
|
||||
return [
|
||||
['ROLE_TEAM_ADMIN'],
|
||||
|
||||
@@ -10,7 +10,7 @@ use App\Entity\Disposition;
|
||||
use App\Entity\Teamer;
|
||||
use App\Entity\User;
|
||||
use App\Security\Voter\DispositionVoter;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\MockObject\Stub;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
@@ -23,16 +23,14 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
||||
*/
|
||||
class DispositionVoterTest extends TestCase
|
||||
{
|
||||
private Security&MockObject $security;
|
||||
private Security&Stub $security;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->security = $this->createMock(Security::class);
|
||||
$this->security = $this->createStub(Security::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider documentAndFeedbackAttributes
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('documentAndFeedbackAttributes')]
|
||||
public function testAnAdminIsDeniedOnASkipFormalitiesAssignment(string $attribute): void
|
||||
{
|
||||
$this->security->method('isGranted')->willReturn(true);
|
||||
@@ -46,9 +44,8 @@ class DispositionVoterTest extends TestCase
|
||||
/**
|
||||
* The same admin on a normal assignment must still get through - the flag is the only thing
|
||||
* that may take these away.
|
||||
*
|
||||
* @dataProvider documentAndFeedbackAttributes
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('documentAndFeedbackAttributes')]
|
||||
public function testTheSameAdminIsGrantedOnANormalAssignment(string $attribute): void
|
||||
{
|
||||
$this->security->method('isGranted')->willReturn(true);
|
||||
@@ -91,9 +88,8 @@ class DispositionVoterTest extends TestCase
|
||||
* transition, because there is none to derive it from: while the Honorarnote is being checked
|
||||
* the state machine offers nothing at all, and that is exactly when receipts must stay
|
||||
* manageable.
|
||||
*
|
||||
* @dataProvider receiptWindowStatuses
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('receiptWindowStatuses')]
|
||||
public function testTheReceiptWindowIsTheTwoInvoiceStates(string $status, bool $expected): void
|
||||
{
|
||||
$this->security->method('isGranted')->willReturn(true);
|
||||
@@ -139,9 +135,8 @@ class DispositionVoterTest extends TestCase
|
||||
|
||||
/**
|
||||
* The owning teamer gets in without being administrative; anyone else's teamer does not.
|
||||
*
|
||||
* @dataProvider receiptOwnership
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('receiptOwnership')]
|
||||
public function testOnlyTheOwningTeamerMayManageTheirReceipts(bool $owning, bool $expected): void
|
||||
{
|
||||
$this->security
|
||||
@@ -158,7 +153,7 @@ class DispositionVoterTest extends TestCase
|
||||
|
||||
$user = (new User())->setTeamer($owning ? $teamer : new Teamer());
|
||||
|
||||
$token = $this->createMock(TokenInterface::class);
|
||||
$token = $this->createStub(TokenInterface::class);
|
||||
$token->method('getUser')->willReturn($user);
|
||||
|
||||
$this->assertSame(
|
||||
@@ -181,7 +176,7 @@ class DispositionVoterTest extends TestCase
|
||||
private function vote(string $attribute, Disposition $disposition): int
|
||||
{
|
||||
return (new DispositionVoter($this->security))->vote(
|
||||
$this->createMock(TokenInterface::class),
|
||||
$this->createStub(TokenInterface::class),
|
||||
$disposition,
|
||||
[$attribute],
|
||||
);
|
||||
|
||||
@@ -9,7 +9,7 @@ use App\Entity\Teamer;
|
||||
use App\Entity\Upload;
|
||||
use App\Entity\User;
|
||||
use App\Security\Voter\UploadVoter;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\MockObject\Stub;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
@@ -22,11 +22,11 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
||||
*/
|
||||
class UploadVoterTest extends TestCase
|
||||
{
|
||||
private Security&MockObject $security;
|
||||
private Security&Stub $security;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->security = $this->createMock(Security::class);
|
||||
$this->security = $this->createStub(Security::class);
|
||||
$this->security
|
||||
->method('isGranted')
|
||||
->willReturnCallback(static fn (string $role): bool => 'ROLE_TEAMER' === $role)
|
||||
@@ -68,9 +68,8 @@ class UploadVoterTest extends TestCase
|
||||
/**
|
||||
* Downloading is all the new rule grants: the file stays the office's, so the teamer it was
|
||||
* issued to may not delete it or reach it through any other attribute.
|
||||
*
|
||||
* @dataProvider otherAttributes
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('otherAttributes')]
|
||||
public function testTheNewRuleGrantsNothingButDownloading(string $attribute): void
|
||||
{
|
||||
$teamer = new Teamer();
|
||||
@@ -124,7 +123,7 @@ class UploadVoterTest extends TestCase
|
||||
|
||||
private function vote(string $attribute, Upload $upload, Teamer $teamer): int
|
||||
{
|
||||
$token = $this->createMock(TokenInterface::class);
|
||||
$token = $this->createStub(TokenInterface::class);
|
||||
$token->method('getUser')->willReturn((new User())->setTeamer($teamer));
|
||||
|
||||
return (new UploadVoter($this->security))->vote($token, $upload, [$attribute]);
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace App\Tests\Security\Voter;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Security\Voter\UserVoter;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\MockObject\Stub;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
@@ -14,11 +14,11 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
||||
|
||||
class UserVoterTest extends TestCase
|
||||
{
|
||||
private Security&MockObject $security;
|
||||
private Security&Stub $security;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->security = $this->createMock(Security::class);
|
||||
$this->security = $this->createStub(Security::class);
|
||||
}
|
||||
|
||||
public function testSuperAdminMayEditOtherUsers(): void
|
||||
@@ -59,10 +59,9 @@ class UserVoterTest extends TestCase
|
||||
{
|
||||
$this->security
|
||||
->method('isGranted')
|
||||
->with('IS_IMPERSONATOR')
|
||||
->willReturn($isImpersonator);
|
||||
->willReturnCallback(static fn (mixed $attribute): bool => 'IS_IMPERSONATOR' === $attribute && $isImpersonator);
|
||||
|
||||
$token = $this->createMock(TokenInterface::class);
|
||||
$token = $this->createStub(TokenInterface::class);
|
||||
$token
|
||||
->method('getUser')
|
||||
->willReturn($currentUser);
|
||||
|
||||
Reference in new issue
Block a user