Skip to content

Commit 2be6b0c

Browse files
minor symfony#57523 Add more precise types in reusable test cases (stof)
This PR was merged into the 7.2 branch. Discussion ---------- Add more precise types in reusable test cases | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | yes | Issues | n/a | License | MIT This deprecates extending `FormIntegrationTestCase` without adding the `array` return type when overriding its protected method. This is similar to our return type additions done between Symfony 6 and 7.0 (those were forgotten because the phpdoc was missing) Commits ------- 73da5e2 Add more precise types in reusable test cases
2 parents 2cb470e + 73da5e2 commit 2be6b0c

21 files changed

+178
-49
lines changed

.github/expected-missing-return-types.diff

Lines changed: 98 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
# Run these steps to update this file:
2-
sed -i 's/ *"\*\*\/Tests\/"//' composer.json
2+
sed -i 's/ *"\*\*\/Tests\/",\?//' composer.json
33
composer u -o
44
SYMFONY_PATCH_TYPE_DECLARATIONS='force=2&php=8.1' php .github/patch-types.php
55
head=$(sed '/^diff /Q' .github/expected-missing-return-types.diff)
66
git checkout src/Symfony/Contracts/Service/ResetInterface.php
77
(echo "$head" && echo && git diff -U2 src/ | grep '^index ' -v) > .github/expected-missing-return-types.diff
88
git checkout composer.json src/
99

10+
diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractLayoutTestCase.php b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractLayoutTestCase.php
11+
--- a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractLayoutTestCase.php
12+
+++ b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractLayoutTestCase.php
13+
@@ -52,5 +52,5 @@ abstract class AbstractLayoutTestCase extends FormLayoutTestCase
14+
* @return FormExtensionInterface[]
15+
*/
16+
- protected function getExtensions()
17+
+ protected function getExtensions(): array
18+
{
19+
return [
1020
diff --git a/src/Symfony/Component/BrowserKit/AbstractBrowser.php b/src/Symfony/Component/BrowserKit/AbstractBrowser.php
1121
--- a/src/Symfony/Component/BrowserKit/AbstractBrowser.php
1222
+++ b/src/Symfony/Component/BrowserKit/AbstractBrowser.php
@@ -22,7 +32,7 @@ diff --git a/src/Symfony/Component/BrowserKit/AbstractBrowser.php b/src/Symfony/
2232
*/
2333
- abstract protected function doRequest(object $request);
2434
+ abstract protected function doRequest(object $request): object;
25-
35+
2636
/**
2737
@@ -451,5 +451,5 @@ abstract class AbstractBrowser
2838
* @throws LogicException When this abstract class is not implemented
@@ -146,21 +156,21 @@ diff --git a/src/Symfony/Component/DependencyInjection/Extension/ExtensionInterf
146156
*/
147157
- public function load(array $configs, ContainerBuilder $container);
148158
+ public function load(array $configs, ContainerBuilder $container): void;
149-
159+
150160
/**
151161
@@ -37,5 +37,5 @@ interface ExtensionInterface
152162
* @return string
153163
*/
154164
- public function getNamespace();
155165
+ public function getNamespace(): string;
156-
166+
157167
/**
158168
@@ -44,5 +44,5 @@ interface ExtensionInterface
159169
* @return string|false
160170
*/
161171
- public function getXsdValidationBasePath();
162172
+ public function getXsdValidationBasePath(): string|false;
163-
173+
164174
/**
165175
@@ -53,4 +53,4 @@ interface ExtensionInterface
166176
* @return string
@@ -189,13 +199,13 @@ diff --git a/src/Symfony/Component/EventDispatcher/EventSubscriberInterface.php
189199
diff --git a/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php b/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php
190200
--- a/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php
191201
+++ b/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php
192-
@@ -139,5 +139,5 @@ class ExpressionLanguage
202+
@@ -149,5 +149,5 @@ class ExpressionLanguage
193203
* @return void
194204
*/
195205
- protected function registerFunctions()
196206
+ protected function registerFunctions(): void
197207
{
198-
$this->addFunction(ExpressionFunction::fromPhp('constant'));
208+
$basicPhpFunctions = ['constant', 'min', 'max'];
199209
diff --git a/src/Symfony/Component/Form/AbstractType.php b/src/Symfony/Component/Form/AbstractType.php
200210
--- a/src/Symfony/Component/Form/AbstractType.php
201211
+++ b/src/Symfony/Component/Form/AbstractType.php
@@ -249,42 +259,97 @@ diff --git a/src/Symfony/Component/Form/FormTypeInterface.php b/src/Symfony/Comp
249259
*/
250260
- public function getParent();
251261
+ public function getParent(): ?string;
252-
262+
253263
/**
254264
@@ -34,5 +34,5 @@ interface FormTypeInterface
255265
* @return void
256266
*/
257267
- public function configureOptions(OptionsResolver $resolver);
258268
+ public function configureOptions(OptionsResolver $resolver): void;
259-
269+
260270
/**
261271
@@ -48,5 +48,5 @@ interface FormTypeInterface
262272
* @see FormTypeExtensionInterface::buildForm()
263273
*/
264274
- public function buildForm(FormBuilderInterface $builder, array $options);
265275
+ public function buildForm(FormBuilderInterface $builder, array $options): void;
266-
276+
267277
/**
268278
@@ -66,5 +66,5 @@ interface FormTypeInterface
269279
* @see FormTypeExtensionInterface::buildView()
270280
*/
271281
- public function buildView(FormView $view, FormInterface $form, array $options);
272282
+ public function buildView(FormView $view, FormInterface $form, array $options): void;
273-
283+
274284
/**
275285
@@ -85,5 +85,5 @@ interface FormTypeInterface
276286
* @see FormTypeExtensionInterface::finishView()
277287
*/
278288
- public function finishView(FormView $view, FormInterface $form, array $options);
279289
+ public function finishView(FormView $view, FormInterface $form, array $options): void;
280-
290+
281291
/**
282292
@@ -95,4 +95,4 @@ interface FormTypeInterface
283293
* @return string
284294
*/
285295
- public function getBlockPrefix();
286296
+ public function getBlockPrefix(): string;
287297
}
298+
diff --git a/src/Symfony/Component/Form/Test/FormIntegrationTestCase.php b/src/Symfony/Component/Form/Test/FormIntegrationTestCase.php
299+
--- a/src/Symfony/Component/Form/Test/FormIntegrationTestCase.php
300+
+++ b/src/Symfony/Component/Form/Test/FormIntegrationTestCase.php
301+
@@ -40,5 +40,5 @@ abstract class FormIntegrationTestCase extends TestCase
302+
* @return FormExtensionInterface[]
303+
*/
304+
- protected function getExtensions()
305+
+ protected function getExtensions(): array
306+
{
307+
return [];
308+
@@ -48,5 +48,5 @@ abstract class FormIntegrationTestCase extends TestCase
309+
* @return FormTypeExtensionInterface[]
310+
*/
311+
- protected function getTypeExtensions()
312+
+ protected function getTypeExtensions(): array
313+
{
314+
return [];
315+
@@ -56,5 +56,5 @@ abstract class FormIntegrationTestCase extends TestCase
316+
* @return FormTypeInterface[]
317+
*/
318+
- protected function getTypes()
319+
+ protected function getTypes(): array
320+
{
321+
return [];
322+
@@ -64,5 +64,5 @@ abstract class FormIntegrationTestCase extends TestCase
323+
* @return FormTypeGuesserInterface[]
324+
*/
325+
- protected function getTypeGuessers()
326+
+ protected function getTypeGuessers(): array
327+
{
328+
return [];
329+
diff --git a/src/Symfony/Component/Form/Test/TypeTestCase.php b/src/Symfony/Component/Form/Test/TypeTestCase.php
330+
--- a/src/Symfony/Component/Form/Test/TypeTestCase.php
331+
+++ b/src/Symfony/Component/Form/Test/TypeTestCase.php
332+
@@ -33,5 +33,5 @@ abstract class TypeTestCase extends FormIntegrationTestCase
333+
* @return FormExtensionInterface[]
334+
*/
335+
- protected function getExtensions()
336+
+ protected function getExtensions(): array
337+
{
338+
$extensions = [];
339+
@@ -47,5 +47,5 @@ abstract class TypeTestCase extends FormIntegrationTestCase
340+
* @return void
341+
*/
342+
- public static function assertDateTimeEquals(\DateTime $expected, \DateTime $actual)
343+
+ public static function assertDateTimeEquals(\DateTime $expected, \DateTime $actual): void
344+
{
345+
self::assertEquals($expected->format('c'), $actual->format('c'));
346+
@@ -55,5 +55,5 @@ abstract class TypeTestCase extends FormIntegrationTestCase
347+
* @return void
348+
*/
349+
- public static function assertDateIntervalEquals(\DateInterval $expected, \DateInterval $actual)
350+
+ public static function assertDateIntervalEquals(\DateInterval $expected, \DateInterval $actual): void
351+
{
352+
self::assertEquals($expected->format('%RP%yY%mM%dDT%hH%iM%sS'), $actual->format('%RP%yY%mM%dDT%hH%iM%sS'));
288353
diff --git a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php
289354
--- a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php
290355
+++ b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php
@@ -324,26 +389,26 @@ diff --git a/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php b/src/S
324389
*/
325390
- public function boot();
326391
+ public function boot(): void;
327-
392+
328393
/**
329394
@@ -35,5 +35,5 @@ interface BundleInterface
330395
* @return void
331396
*/
332397
- public function shutdown();
333398
+ public function shutdown(): void;
334-
399+
335400
/**
336401
@@ -44,5 +44,5 @@ interface BundleInterface
337402
* @return void
338403
*/
339404
- public function build(ContainerBuilder $container);
340405
+ public function build(ContainerBuilder $container): void;
341-
406+
342407
/**
343408
diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php
344409
--- a/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php
345410
+++ b/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php
346-
@@ -101,5 +101,5 @@ abstract class DataCollector implements DataCollectorInterface
411+
@@ -113,5 +113,5 @@ abstract class DataCollector implements DataCollectorInterface
347412
* @return void
348413
*/
349414
- public function reset()
@@ -358,7 +423,7 @@ diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DataCollectorInterfa
358423
*/
359424
- public function collect(Request $request, Response $response, ?\Throwable $exception = null);
360425
+ public function collect(Request $request, Response $response, ?\Throwable $exception = null): void;
361-
426+
362427
/**
363428
@@ -35,4 +35,4 @@ interface DataCollectorInterface extends ResetInterface
364429
* @return string
@@ -383,38 +448,38 @@ diff --git a/src/Symfony/Component/HttpKernel/KernelInterface.php b/src/Symfony/
383448
*/
384449
- public function registerContainerConfiguration(LoaderInterface $loader);
385450
+ public function registerContainerConfiguration(LoaderInterface $loader): void;
386-
451+
387452
/**
388453
@@ -44,5 +44,5 @@ interface KernelInterface extends HttpKernelInterface
389454
* @return void
390455
*/
391456
- public function boot();
392457
+ public function boot(): void;
393-
458+
394459
/**
395460
@@ -53,5 +53,5 @@ interface KernelInterface extends HttpKernelInterface
396461
* @return void
397462
*/
398463
- public function shutdown();
399464
+ public function shutdown(): void;
400-
465+
401466
/**
402467
diff --git a/src/Symfony/Component/Routing/Loader/AttributeClassLoader.php b/src/Symfony/Component/Routing/Loader/AttributeClassLoader.php
403468
--- a/src/Symfony/Component/Routing/Loader/AttributeClassLoader.php
404469
+++ b/src/Symfony/Component/Routing/Loader/AttributeClassLoader.php
405-
@@ -234,5 +234,5 @@ abstract class AttributeClassLoader implements LoaderInterface
470+
@@ -236,5 +236,5 @@ abstract class AttributeClassLoader implements LoaderInterface
406471
* @return string
407472
*/
408473
- protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
409474
+ protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method): string
410475
{
411476
$name = str_replace('\\', '_', $class->name).'_'.$method->name;
412-
@@ -333,5 +333,5 @@ abstract class AttributeClassLoader implements LoaderInterface
477+
@@ -335,5 +335,5 @@ abstract class AttributeClassLoader implements LoaderInterface
413478
* @return void
414479
*/
415480
- abstract protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot);
416481
+ abstract protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot): void;
417-
482+
418483
/**
419484
diff --git a/src/Symfony/Component/Security/Core/Authentication/RememberMe/TokenProviderInterface.php b/src/Symfony/Component/Security/Core/Authentication/RememberMe/TokenProviderInterface.php
420485
--- a/src/Symfony/Component/Security/Core/Authentication/RememberMe/TokenProviderInterface.php
@@ -424,21 +489,21 @@ diff --git a/src/Symfony/Component/Security/Core/Authentication/RememberMe/Token
424489
*/
425490
- public function loadTokenBySeries(string $series);
426491
+ public function loadTokenBySeries(string $series): PersistentTokenInterface;
427-
492+
428493
/**
429494
@@ -35,5 +35,5 @@ interface TokenProviderInterface
430495
* @return void
431496
*/
432497
- public function deleteTokenBySeries(string $series);
433498
+ public function deleteTokenBySeries(string $series): void;
434-
499+
435500
/**
436501
@@ -44,5 +44,5 @@ interface TokenProviderInterface
437502
* @throws TokenNotFoundException if the token is not found
438503
*/
439504
- public function updateToken(string $series, #[\SensitiveParameter] string $tokenValue, \DateTimeInterface $lastUsed);
440505
+ public function updateToken(string $series, #[\SensitiveParameter] string $tokenValue, \DateTimeInterface $lastUsed): void;
441-
506+
442507
/**
443508
@@ -51,4 +51,4 @@ interface TokenProviderInterface
444509
* @return void
@@ -449,28 +514,28 @@ diff --git a/src/Symfony/Component/Security/Core/Authentication/RememberMe/Token
449514
diff --git a/src/Symfony/Component/Security/Http/Firewall.php b/src/Symfony/Component/Security/Http/Firewall.php
450515
--- a/src/Symfony/Component/Security/Http/Firewall.php
451516
+++ b/src/Symfony/Component/Security/Http/Firewall.php
452-
@@ -51,5 +51,5 @@ class Firewall implements EventSubscriberInterface
517+
@@ -48,5 +48,5 @@ class Firewall implements EventSubscriberInterface
453518
* @return void
454519
*/
455520
- public function onKernelRequest(RequestEvent $event)
456521
+ public function onKernelRequest(RequestEvent $event): void
457522
{
458523
if (!$event->isMainRequest()) {
459-
@@ -99,5 +99,5 @@ class Firewall implements EventSubscriberInterface
524+
@@ -96,5 +96,5 @@ class Firewall implements EventSubscriberInterface
460525
* @return void
461526
*/
462527
- public function onKernelFinishRequest(FinishRequestEvent $event)
463528
+ public function onKernelFinishRequest(FinishRequestEvent $event): void
464529
{
465530
$request = $event->getRequest();
466-
@@ -112,5 +112,5 @@ class Firewall implements EventSubscriberInterface
531+
@@ -109,5 +109,5 @@ class Firewall implements EventSubscriberInterface
467532
* @return array
468533
*/
469534
- public static function getSubscribedEvents()
470535
+ public static function getSubscribedEvents(): array
471536
{
472537
return [
473-
@@ -123,5 +123,5 @@ class Firewall implements EventSubscriberInterface
538+
@@ -120,5 +120,5 @@ class Firewall implements EventSubscriberInterface
474539
* @return void
475540
*/
476541
- protected function callListeners(RequestEvent $event, iterable $listeners)
@@ -485,7 +550,7 @@ diff --git a/src/Symfony/Component/Translation/Extractor/ExtractorInterface.php
485550
*/
486551
- public function extract(string|iterable $resource, MessageCatalogue $catalogue);
487552
+ public function extract(string|iterable $resource, MessageCatalogue $catalogue): void;
488-
553+
489554
/**
490555
@@ -36,4 +36,4 @@ interface ExtractorInterface
491556
* @return void
@@ -501,7 +566,7 @@ diff --git a/src/Symfony/Component/Validator/ConstraintValidatorInterface.php b/
501566
*/
502567
- public function initialize(ExecutionContextInterface $context);
503568
+ public function initialize(ExecutionContextInterface $context): void;
504-
569+
505570
/**
506571
@@ -31,4 +31,4 @@ interface ConstraintValidatorInterface
507572
* @return void
@@ -526,7 +591,7 @@ diff --git a/src/Symfony/Contracts/Translation/LocaleAwareInterface.php b/src/Sy
526591
*/
527592
- public function setLocale(string $locale);
528593
+ public function setLocale(string $locale): void;
529-
594+
530595
/**
531596
diff --git a/src/Symfony/Contracts/Translation/TranslatorTrait.php b/src/Symfony/Contracts/Translation/TranslatorTrait.php
532597
--- a/src/Symfony/Contracts/Translation/TranslatorTrait.php

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase
2929

3030
private EntityManager $em;
3131

32-
protected function getExtensions()
32+
protected function getExtensions(): array
3333
{
3434
$manager = $this->createMock(ManagerRegistry::class);
3535

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected function setUp(): void
8686
}
8787
}
8888

89-
protected function getExtensions()
89+
protected function getExtensions(): array
9090
{
9191
return array_merge(parent::getExtensions(), [
9292
new DoctrineOrmExtension($this->emRegistry),

0 commit comments

Comments
 (0)