Skip to content

Commit 206f593

Browse files
authored
Updated PhpUnit & Fixed all deprecations (#62)
1 parent 6fa2cc0 commit 206f593

File tree

12 files changed

+78
-59
lines changed

12 files changed

+78
-59
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"yokai/dependency-injection": "^1.0"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "^9.5",
21+
"phpunit/phpunit": "^10.0|12.0",
2222
"symfony/yaml": "^6.4|^7.4|^8.0",
2323
"phpstan/phpstan": "^2.1",
2424
"symplify/easy-coding-standard": "^13.0"

phpunit.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
44
backupGlobals="false"
5-
backupStaticAttributes="false"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
95
processIsolation="false"
106
stopOnFailure="false"
117
colors="true"
8+
displayDetailsOnTestsThatTriggerDeprecations="true"
9+
displayDetailsOnTestsThatTriggerErrors="true"
10+
displayDetailsOnTestsThatTriggerNotices="true"
11+
displayDetailsOnTestsThatTriggerWarnings="true"
12+
displayDetailsOnPhpunitDeprecations="true"
1213
bootstrap="vendor/autoload.php">
1314
<php>
1415
<server name="KERNEL_CLASS" value="Yokai\SecurityTokenBundle\Tests\Kernel"/>
@@ -18,9 +19,9 @@
1819
<directory>./tests</directory>
1920
</testsuite>
2021
</testsuites>
21-
<coverage>
22+
<source>
2223
<include>
2324
<directory>./src</directory>
2425
</include>
25-
</coverage>
26+
</source>
2627
</phpunit>

tests/Command/ArchiveTokenCommandTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ protected function setUp(): void
4141
protected function tearDown(): void
4242
{
4343
parent::tearDown();
44+
\restore_exception_handler();
4445

4546
unset(
4647
$this->archivist,
@@ -65,7 +66,7 @@ protected function runCommand(Command $command, array $options = []): string
6566
return $tester->getDisplay();
6667
}
6768

68-
public function testIt_archive_every_token_when_run_without_options_with_confirmation(): void
69+
public function test_it_archive_every_token_when_run_without_options_with_confirmation(): void
6970
{
7071
$command = $this->command();
7172

@@ -79,7 +80,7 @@ public function testIt_archive_every_token_when_run_without_options_with_confirm
7980
self::assertStringContainsString('Successfully archived 10 security token(s).', $output);
8081
}
8182

82-
public function testIt_archive_partial_tokens_when_run_with_options(): void
83+
public function test_it_archive_partial_tokens_when_run_with_options(): void
8384
{
8485
$command = $this->command();
8586

tests/DependencyInjection/DependencyInjectionTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Doctrine\Persistence\ManagerRegistry;
1010
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
1111
use Generator;
12+
use PHPUnit\Framework\Attributes\DataProvider;
1213
use PHPUnit\Framework\TestCase;
1314
use Psr\Log\LoggerInterface;
1415
use Symfony\Component\Config\FileLocator;
@@ -85,10 +86,8 @@ protected function setUp(): void
8586
$bundle->build($this->container);
8687
}
8788

88-
/**
89-
* @dataProvider configurationProvider
90-
*/
91-
public function testIt_parse_configuration_as_expected(string $resource, array $tokens, array $aliases): void
89+
#[DataProvider('configurationProvider')]
90+
public function test_it_parse_configuration_as_expected(string $resource, array $tokens, array $aliases): void
9291
{
9392
// for test purpose, all services are switched to public
9493
$this->container->addCompilerPass(new class implements CompilerPassInterface {
@@ -144,7 +143,7 @@ protected function loadConfiguration(string $resource): void
144143
$loader->load($resource);
145144
}
146145

147-
public function configurationProvider(): Generator
146+
public static function configurationProvider(): Generator
148147
{
149148
$defaultAliases = [
150149
'yokai_security_token.information_guesser' => 'yokai_security_token.default_information_guesser',
@@ -154,7 +153,7 @@ public function configurationProvider(): Generator
154153
'yokai_security_token.archivist' => 'yokai_security_token.delete_archivist',
155154
];
156155

157-
foreach ($this->formatProvider() as $format) {
156+
foreach (self::formatProvider() as $format) {
158157
$format = $format[0];
159158

160159
yield $format . ' - none' => [
@@ -205,7 +204,7 @@ public function configurationProvider(): Generator
205204
}
206205
}
207206

208-
public function formatProvider(): Generator
207+
public static function formatProvider(): Generator
209208
{
210209
yield ['yml'];
211210
}

tests/Entity/TokenTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
final class TokenTest extends TestCase
1616
{
17-
public function testIt_allow_limited_usage_token(): void
17+
public function test_it_allow_limited_usage_token(): void
1818
{
1919
$token = new Token('string', 'jdoe', 'unique-token', 'reset-password', '+1 day', '+1 month', 2);
2020
self::assertFalse($token->isConsumed());
@@ -29,7 +29,7 @@ public function testIt_allow_limited_usage_token(): void
2929
self::assertSame([2], $token->getLastUsage()->getInformation());
3030
}
3131

32-
public function testIt_allow_unlimited_usage_token(): void
32+
public function test_it_allow_unlimited_usage_token(): void
3333
{
3434
$token = new Token('string', 'jdoe', 'unique-token', 'reset-password', '+1 day', '+1 month', 0);
3535
self::assertFalse($token->isConsumed());

tests/Factory/TokenFactoryTest.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,33 @@ protected function factory(array $configuration): TokenFactory
6464
);
6565
}
6666

67-
public function testIt_create_token_according_to_configuration(): void
67+
public function test_it_create_token_according_to_configuration(): void
6868
{
6969
$generator1 = $this->createMock(TokenGeneratorInterface::class);
70-
$generator1->method('generate')
71-
->will($this->onConsecutiveCalls('existtoken-1', 'uniquetoken-1'));
70+
$generator1->expects($matcher = $this->atMost(2))
71+
->method('generate')
72+
->willReturnCallback(fn() => match ($matcher->numberOfInvocations()) {
73+
1 => 'existtoken-1',
74+
2 => 'uniquetoken-1',
75+
});
7276
$user1 = 'user-1';
7377

7478
$generator2 = $this->createMock(TokenGeneratorInterface::class);
75-
$generator2->method('generate')
76-
->will($this->onConsecutiveCalls('existtoken-2', 'uniquetoken-2'));
79+
$generator2->expects($matcher = $this->atMost(2))
80+
->method('generate')
81+
->willReturnCallback(fn() => match ($matcher->numberOfInvocations()) {
82+
1 => 'existtoken-2',
83+
2 => 'uniquetoken-2',
84+
});
7785
$user2 = 'user-2';
7886

7987
$generator3 = $this->createMock(TokenGeneratorInterface::class);
80-
$generator3->method('generate')
81-
->will($this->onConsecutiveCalls('existtoken-3', 'uniquetoken-3'));
88+
$generator3->expects($matcher = $this->atMost(2))
89+
->method('generate')
90+
->willReturnCallback(fn() => match ($matcher->numberOfInvocations()) {
91+
1 => 'existtoken-3',
92+
2 => 'uniquetoken-3',
93+
});
8294
$user3 = 'user-3';
8395
$token3FromRepository = new Token(
8496
'string',
@@ -111,7 +123,7 @@ public function testIt_create_token_according_to_configuration(): void
111123

112124
$this->userManager->expects(self::exactly(3))
113125
->method('getClass')
114-
->with(self::isType('string'))
126+
->with(\method_exists(self::class, 'isString') ? self::isString() : self::isType('string'))
115127
->willReturnMap([
116128
[$user1, 'string'],
117129
[$user2, 'string'],
@@ -120,7 +132,7 @@ public function testIt_create_token_according_to_configuration(): void
120132

121133
$this->userManager->expects(self::exactly(3))
122134
->method('getId')
123-
->with(self::isType('string'))
135+
->with(\method_exists(self::class, 'isString') ? self::isString() : self::isType('string'))
124136
->willReturnMap([
125137
[$user1, 'u1'],
126138
[$user2, 'u2'],

tests/Generator/OpenSslTokenGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
final class OpenSslTokenGeneratorTest extends TestCase
1616
{
17-
public function testIt_generate_unique_token(): void
17+
public function test_it_generate_unique_token(): void
1818
{
1919
$generator = new OpenSslTokenGenerator();
2020

tests/InformationGuesser/InformationGuesserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected function guesser(RequestStack $requestStack): InformationGuesser
2121
return new InformationGuesser($requestStack);
2222
}
2323

24-
public function testIt_return_empty_array_if_no_master_request(): void
24+
public function test_it_return_empty_array_if_no_master_request(): void
2525
{
2626
$requestStack = new RequestStack();
2727

@@ -30,7 +30,7 @@ public function testIt_return_empty_array_if_no_master_request(): void
3030
self::assertSame([], $info);
3131
}
3232

33-
public function testIt_return_array_with_ip_from_master_request(): void
33+
public function test_it_return_array_with_ip_from_master_request(): void
3434
{
3535
$requestStack = new RequestStack();
3636
$requestStack->push(new Request([], [], [], [], [], ['REMOTE_ADDR' => '88.88.88.88']));

tests/Manager/ChainUserManagerTest.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ private function entityManager(): UserManagerInterface
4242
$manager->method('getId')
4343
->willReturn('increment');
4444
$manager->method('get')
45-
->with(UserEntity::class, self::isType('string'))
45+
->with(
46+
UserEntity::class,
47+
\method_exists(self::class, 'isString') ? self::isString() : self::isType('string'),
48+
)
4649
->willReturn(new UserEntity());
4750

4851
return $manager;
@@ -66,13 +69,16 @@ private function documentManager(): UserManagerInterface
6669
$manager->method('getId')
6770
->willReturn('uuid');
6871
$manager->method('get')
69-
->with(UserDocument::class, self::isType('string'))
72+
->with(
73+
UserDocument::class,
74+
\method_exists(self::class, 'isString') ? self::isString() : self::isType('string'),
75+
)
7076
->willReturn(new UserDocument());
7177

7278
return $manager;
7379
}
7480

75-
public function testIt_supports_same_classes_as_managers(): void
81+
public function test_it_supports_same_classes_as_managers(): void
7682
{
7783
$entityManager = $this->entityManager();
7884
$documentManager = $this->documentManager();
@@ -97,7 +103,7 @@ public function testIt_supports_same_classes_as_managers(): void
97103
self::assertFalse($userEmptyManager->supportsClass($document));
98104
}
99105

100-
public function testIt_supports_same_users_as_managers(): void
106+
public function test_it_supports_same_users_as_managers(): void
101107
{
102108
$entityManager = $this->entityManager();
103109
$documentManager = $this->documentManager();
@@ -122,7 +128,7 @@ public function testIt_supports_same_users_as_managers(): void
122128
self::assertFalse($userEmptyManager->supportsUser($document));
123129
}
124130

125-
public function testIt_get_user_class_from_appropriate_manager(): void
131+
public function test_it_get_user_class_from_appropriate_manager(): void
126132
{
127133
$entity = new UserEntity();
128134
$document = new UserDocument();
@@ -132,7 +138,7 @@ public function testIt_get_user_class_from_appropriate_manager(): void
132138
self::assertSame(UserDocument::class, $userCompleteManager->getClass($document));
133139
}
134140

135-
public function testIt_get_user_id_from_appropriate_manager()
141+
public function test_it_get_user_id_from_appropriate_manager()
136142
{
137143
$entity = new UserEntity();
138144
$document = new UserDocument();
@@ -142,7 +148,7 @@ public function testIt_get_user_id_from_appropriate_manager()
142148
self::assertSame('uuid', $userCompleteManager->getId($document));
143149
}
144150

145-
public function testIt_get_user_from_appropriate_manager(): void
151+
public function test_it_get_user_from_appropriate_manager(): void
146152
{
147153
$userCompleteManager = $this->manager([$this->entityManager(), $this->documentManager()]);
148154
self::assertInstanceOf(UserEntity::class, $userCompleteManager->get(UserEntity::class, '9999'));
@@ -152,23 +158,23 @@ public function testIt_get_user_from_appropriate_manager(): void
152158
);
153159
}
154160

155-
public function testIt_throw_exception_on_get_user_class_without_appropriate_manager(): void
161+
public function test_it_throw_exception_on_get_user_class_without_appropriate_manager(): void
156162
{
157163
$this->expectException(InvalidArgumentException::class);
158164

159165
$userCompleteManager = $this->manager([$this->entityManager(), $this->documentManager()]);
160166
$userCompleteManager->getClass(new \stdClass());
161167
}
162168

163-
public function testIt_throw_exception_on_get_user_id_without_appropriate_manager(): void
169+
public function test_it_throw_exception_on_get_user_id_without_appropriate_manager(): void
164170
{
165171
$this->expectException(InvalidArgumentException::class);
166172

167173
$userCompleteManager = $this->manager([$this->entityManager(), $this->documentManager()]);
168174
$userCompleteManager->getId(new \stdClass());
169175
}
170176

171-
public function testIt_throw_exception_on_get_user_without_appropriate_manager(): void
177+
public function test_it_throw_exception_on_get_user_without_appropriate_manager(): void
172178
{
173179
$this->expectException(InvalidArgumentException::class);
174180

tests/Manager/DoctrineUserManagerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function getId()
7272
};
7373
}
7474

75-
public function testIt_supports_doctrine_entities(): void
75+
public function test_it_supports_doctrine_entities(): void
7676
{
7777
$user = $this->user('jdoe');
7878

@@ -85,7 +85,7 @@ public function testIt_supports_doctrine_entities(): void
8585
self::assertTrue($manager->supportsUser($user));
8686
}
8787

88-
public function testIt_do_not_supports_objects_out_of_doctrine(): void
88+
public function test_it_do_not_supports_objects_out_of_doctrine(): void
8989
{
9090
$user = $this->user('jdoe');
9191

@@ -98,7 +98,7 @@ public function testIt_do_not_supports_objects_out_of_doctrine(): void
9898
self::assertFalse($manager->supportsUser($user));
9999
}
100100

101-
public function testIt_get_user(): void
101+
public function test_it_get_user(): void
102102
{
103103
$expected = $this->user('jdoe');
104104

@@ -117,7 +117,7 @@ public function testIt_get_user(): void
117117
self::assertSame($expected, $user);
118118
}
119119

120-
public function testIt_get_user_class(): void
120+
public function test_it_get_user_class(): void
121121
{
122122
$expected = $this->user('jdoe');
123123

@@ -126,7 +126,7 @@ public function testIt_get_user_class(): void
126126
self::assertSame(\get_class($expected), $class);
127127
}
128128

129-
public function testIt_get_user_id(): void
129+
public function test_it_get_user_id(): void
130130
{
131131
$expected = $this->user('jdoe');
132132

0 commit comments

Comments
 (0)