Skip to content

Commit 0b510f4

Browse files
committed
Adjust test for no longer supported passing of options array
1 parent 01ae9eb commit 0b510f4

File tree

6 files changed

+38
-4
lines changed

6 files changed

+38
-4
lines changed

tests/Security/TwoFactor/Validator/Constraints/UserGoogleTotpCodeDummy.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class UserGoogleTotpCodeDummy
1414
#[UserGoogleTotpCode(message: 'myMessage', translationDomain: 'myDomain', service: 'my_service')]
1515
public string $b;
1616

17-
#[UserGoogleTotpCode(['groups' => ['my_group'], 'payload' => 'some attached data'])]
17+
#[UserGoogleTotpCode(groups: ['my_group'], payload: 'some attached data')]
1818
public string $c;
19+
20+
// Test backwards compatibility with Symfony 7.4
21+
// Associative arrays are only supported under Symfony 7.4
22+
#[UserGoogleTotpCode(['groups' => ['my_group'], 'payload' => 'some attached data'])]
23+
public string $c74;
1924
}

tests/Security/TwoFactor/Validator/Constraints/UserGoogleTotpCodeTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PHPUnit\Framework\Attributes\Test;
88
use Scheb\TwoFactorBundle\Tests\TestCase;
9+
use Symfony\Component\HttpKernel\Kernel;
910
use Symfony\Component\Validator\Mapping\ClassMetadata;
1011
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;
1112

@@ -32,5 +33,12 @@ public function configureConstraintFromAttribute_configurationIsCorrect(): void
3233
[$cConstraint] = $metadata->getPropertyMetadata('c')[0]->getConstraints();
3334
$this->assertSame(['my_group'], $cConstraint->groups);
3435
$this->assertSame('some attached data', $cConstraint->payload);
36+
37+
// Backwards compatibility for Symfony 7.4
38+
if (Kernel::VERSION_ID < 80000) {
39+
[$cConstraint] = $metadata->getPropertyMetadata('c')[0]->getConstraints();
40+
$this->assertSame(['my_group'], $cConstraint->groups);
41+
$this->assertSame('some attached data', $cConstraint->payload);
42+
}
3543
}
3644
}

tests/Security/TwoFactor/Validator/Constraints/UserGoogleTotpCodeValidatorTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Scheb\TwoFactorBundle\Security\TwoFactor\Validator\Constraints\UserGoogleTotpCode;
1313
use Scheb\TwoFactorBundle\Security\TwoFactor\Validator\Constraints\UserGoogleTotpCodeValidator;
1414
use Scheb\TwoFactorBundle\Tests\Security\TwoFactor\Provider\Google\UserWithTwoFactorInterface;
15+
use Symfony\Component\HttpKernel\Kernel;
1516
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1617
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1718
use Symfony\Component\Security\Core\User\UserInterface;
@@ -76,7 +77,10 @@ public function validate_invalidCode_raisedViolation(UserGoogleTotpCode $constra
7677
*/
7778
public static function provideConstraints(): iterable
7879
{
79-
yield 'Doctrine style' => [new UserGoogleTotpCode(['message' => 'myMessage', 'translationDomain' => 'myDomain'])];
80+
// Test backwards compatibility with Symfony 7.4
81+
if (Kernel::VERSION_ID < 80000) {
82+
yield 'Doctrine style' => [new UserGoogleTotpCode(['message' => 'myMessage', 'translationDomain' => 'myDomain'])];
83+
}
8084

8185
yield 'named arguments' => [new UserGoogleTotpCode(message: 'myMessage', translationDomain: 'myDomain')];
8286
}

tests/Security/TwoFactor/Validator/Constraints/UserTotpCodeDummy.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class UserTotpCodeDummy
1414
#[UserTotpCode(message: 'myMessage', translationDomain: 'myDomain', service: 'my_service')]
1515
public string $b;
1616

17-
#[UserTotpCode(['groups' => ['my_group'], 'payload' => 'some attached data'])]
17+
#[UserTotpCode(groups: ['my_group'], payload: 'some attached data')]
1818
public string $c;
19+
20+
// Test backwards compatibility with Symfony 7.4
21+
// Associative arrays are only supported under Symfony 7.4
22+
#[UserTotpCode(['groups' => ['my_group'], 'payload' => 'some attached data'])]
23+
public string $c74;
1924
}

tests/Security/TwoFactor/Validator/Constraints/UserTotpCodeTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PHPUnit\Framework\Attributes\Test;
88
use Scheb\TwoFactorBundle\Tests\TestCase;
9+
use Symfony\Component\HttpKernel\Kernel;
910
use Symfony\Component\Validator\Mapping\ClassMetadata;
1011
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;
1112

@@ -32,5 +33,12 @@ public function configureConstraintFromAttribute_configurationIsCorrect(): void
3233
[$cConstraint] = $metadata->getPropertyMetadata('c')[0]->getConstraints();
3334
$this->assertSame(['my_group'], $cConstraint->groups);
3435
$this->assertSame('some attached data', $cConstraint->payload);
36+
37+
// Backwards compatibility for Symfony 7.4
38+
if (Kernel::VERSION_ID < 80000) {
39+
[$cConstraint] = $metadata->getPropertyMetadata('c74')[0]->getConstraints();
40+
$this->assertSame(['my_group'], $cConstraint->groups);
41+
$this->assertSame('some attached data', $cConstraint->payload);
42+
}
3543
}
3644
}

tests/Security/TwoFactor/Validator/Constraints/UserTotpCodeValidatorTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Scheb\TwoFactorBundle\Security\TwoFactor\Validator\Constraints\UserTotpCode;
1414
use Scheb\TwoFactorBundle\Security\TwoFactor\Validator\Constraints\UserTotpCodeValidator;
1515
use Scheb\TwoFactorBundle\Tests\Security\TwoFactor\Provider\Totp\UserWithTwoFactorInterface;
16+
use Symfony\Component\HttpKernel\Kernel;
1617
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1718
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1819
use Symfony\Component\Security\Core\User\UserInterface;
@@ -77,7 +78,10 @@ public function validate_invalidCode_raisedViolation(UserTotpCode $constraint):
7778
*/
7879
public static function provideConstraints(): iterable
7980
{
80-
yield 'Doctrine style' => [new UserTotpCode(['message' => 'myMessage', 'translationDomain' => 'myDomain'])];
81+
// Test backwards compatibility with Symfony 7.4
82+
if (Kernel::VERSION_ID < 80000) {
83+
yield 'Doctrine style' => [new UserTotpCode(['message' => 'myMessage', 'translationDomain' => 'myDomain'])];
84+
}
8185

8286
yield 'named arguments' => [new UserTotpCode(message: 'myMessage', translationDomain: 'myDomain')];
8387
}

0 commit comments

Comments
 (0)