Skip to content

Commit bf8e7ef

Browse files
committed
tidy #3839 [CI] Add void return type to PHPUnit test methods (Kocal)
This PR was merged into the 3.x branch. Discussion ---------- [CI] Add void return type to PHPUnit test methods | Q | A | -------------- | --- | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- if yes, also update UPGRADE-*.md and src/**/CHANGELOG.md --> | Documentation? | no <!-- required for new features, or documentation updates --> | Issues | Fix #3833 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT This PR's adds back `: void` return type to `test*` methods, as stated in #3833. It also touch two source files which were _kind of forgotten_, `src/TwigComponent/src/ComponentStack.php` and `src/Translator/src/Intl/IntlMessageParser.php` which are internal, so it's fine. Commits ------- 5a3ae00 [CI] Add void return type to PHPUnit test methods
2 parents 19315d3 + 5a3ae00 commit bf8e7ef

271 files changed

Lines changed: 1713 additions & 1723 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/fabbot.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ jobs:
1010
name: Fabbot
1111
permissions:
1212
contents: read
13-
uses: symfony-tools/fabbot/.github/workflows/fabbot.yml@ad55ed5ac95aaa9794c60473178a007b342a73b4 # main
13+
uses: symfony-tools/fabbot/.github/workflows/fabbot.yml@93bbf91e340fd0b35d12e412c82a3a927465050e # main
1414
with:
1515
package: Symfony UX
1616
check_license: true
17+
check_test_return_type: false

.php-cs-fixer.dist.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,11 @@ public function getRuleCustomisers(): array
5151
{
5252
return [
5353
'void_return' => static function (SplFileInfo $file) {
54-
// temporary hack due to bug: https://github.com/symfony/symfony/issues/62734
55-
if (!$file instanceof Symfony\Component\Finder\SplFileInfo) {
56-
return false;
57-
}
54+
// parallel workers pass a plain SplFileInfo, which has no getRelativePathname()
55+
$pathname = str_replace('\\', '/', $file->getPathname());
5856

59-
$relativePathname = $file->getRelativePathname();
60-
61-
if (
62-
str_contains($relativePathname, '/tests/') // don't touch test files, as massive change with little benefit - as outside of public contract anyway
63-
|| str_contains($relativePathname, '/Test/') // public namespace not following the rule, do not mistake it with `/Tests/`
64-
) {
65-
return false;
66-
}
67-
68-
return true;
57+
// `src/*/src/Test/` ships test helpers meant to be extended by users, adding a native return type there would break their subclasses
58+
return !str_contains($pathname, '/src/Test/');
6959
},
7060
];
7161
}

src/Autocomplete/tests/Functional/AutocompleteFormRenderingTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AutocompleteFormRenderingTest extends KernelTestCase
2525
use HasBrowser;
2626
use ResetDatabase;
2727

28-
public function testFieldsRenderWithStimulusController()
28+
public function testFieldsRenderWithStimulusController(): void
2929
{
3030
$this->browser()
3131
->throwExceptions()
@@ -44,7 +44,7 @@ public function testFieldsRenderWithStimulusController()
4444
;
4545
}
4646

47-
public function testCategoryFieldSubmitsCorrectly()
47+
public function testCategoryFieldSubmitsCorrectly(): void
4848
{
4949
$firstCat = CategoryFactory::createOne(['name' => 'First cat']);
5050
CategoryFactory::createOne(['name' => 'in space']);
@@ -78,7 +78,7 @@ public function testCategoryFieldSubmitsCorrectly()
7878
;
7979
}
8080

81-
public function testProperlyLoadsChoicesWithIdValueObjects()
81+
public function testProperlyLoadsChoicesWithIdValueObjects(): void
8282
{
8383
$ingredient1 = IngredientFactory::createOne(['name' => 'Flour']);
8484
$ingredient2 = IngredientFactory::createOne(['name' => 'Sugar']);
@@ -106,7 +106,7 @@ public function testProperlyLoadsChoicesWithIdValueObjects()
106106
;
107107
}
108108

109-
public function testMultipleDoesNotFailWithoutSelectedChoices()
109+
public function testMultipleDoesNotFailWithoutSelectedChoices(): void
110110
{
111111
$this->browser()
112112
->throwExceptions()
@@ -127,7 +127,7 @@ public function testMultipleDoesNotFailWithoutSelectedChoices()
127127
;
128128
}
129129

130-
public function testItUsesPassedExtraOptions()
130+
public function testItUsesPassedExtraOptions(): void
131131
{
132132
$ingredient1 = IngredientFactory::createOne(['name' => 'Flour']);
133133
$ingredient2 = IngredientFactory::createOne(['name' => 'Sugar']);
@@ -160,7 +160,7 @@ public function testItUsesPassedExtraOptions()
160160
;
161161
}
162162

163-
public function testItReturnsErrorWhenSendingMalformedExtraOptions()
163+
public function testItReturnsErrorWhenSendingMalformedExtraOptions(): void
164164
{
165165
$extraOptionsWithoutChecksum = $this->encodeData(['foo' => 'bar']);
166166
$extraOptionsWithInvalidChecksum = $this->encodeData(['foo' => 'bar', '@checksum' => 'invalid']);

src/Autocomplete/tests/Functional/CustomAutocompleterTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CustomAutocompleterTest extends KernelTestCase
2525
use HasBrowser;
2626
use ResetDatabase;
2727

28-
public function testItReturnsBasicResults()
28+
public function testItReturnsBasicResults(): void
2929
{
3030
$product = ProductFactory::createOne(['name' => 'foo']);
3131
ProductFactory::createOne(['name' => 'bar']);
@@ -43,7 +43,7 @@ public function testItReturnsBasicResults()
4343
;
4444
}
4545

46-
public function testItUsesTheCustomQuery()
46+
public function testItUsesTheCustomQuery(): void
4747
{
4848
ProductFactory::createOne(['name' => 'foo']);
4949
ProductFactory::new(['name' => 'foo and bar'])
@@ -59,7 +59,7 @@ public function testItUsesTheCustomQuery()
5959
;
6060
}
6161

62-
public function testItOnlySearchedOnSearchableFields()
62+
public function testItOnlySearchedOnSearchableFields(): void
6363
{
6464
ProductFactory::createOne(['name' => 'foo', 'price' => 50]);
6565
ProductFactory::createOne(['name' => 'bar', 'description' => 'foo 50', 'price' => 55]);
@@ -77,7 +77,7 @@ public function testItOnlySearchedOnSearchableFields()
7777
;
7878
}
7979

80-
public function testItEnforcesSecurity()
80+
public function testItEnforcesSecurity(): void
8181
{
8282
ProductFactory::createMany(3);
8383

@@ -97,15 +97,15 @@ public function testItEnforcesSecurity()
9797
;
9898
}
9999

100-
public function testItReturns404OnBadAlias()
100+
public function testItReturns404OnBadAlias(): void
101101
{
102102
$this->browser()
103103
->get('/test/autocomplete/not_real')
104104
->assertStatus(404)
105105
;
106106
}
107107

108-
public function testItWorksWithCustomRoute()
108+
public function testItWorksWithCustomRoute(): void
109109
{
110110
$product = ProductFactory::createOne(['name' => 'foo']);
111111
ProductFactory::createOne(['name' => 'bar']);

src/Autocomplete/tests/Functional/FieldAutocompleterTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class FieldAutocompleterTest extends KernelTestCase
2727
use HasBrowser;
2828
use ResetDatabase;
2929

30-
public function testItReturnsBasicResults()
30+
public function testItReturnsBasicResults(): void
3131
{
3232
$category = CategoryFactory::createOne(['name' => 'foo and baz']);
3333
CategoryFactory::createOne(['name' => 'foo and bar']);
@@ -44,7 +44,7 @@ public function testItReturnsBasicResults()
4444
;
4545
}
4646

47-
public function testItUsesTheCustomQuery()
47+
public function testItUsesTheCustomQuery(): void
4848
{
4949
CategoryFactory::createOne(['name' => 'foo and bar']);
5050
CategoryFactory::createOne(['name' => 'baz and bar']);
@@ -59,7 +59,7 @@ public function testItUsesTheCustomQuery()
5959
;
6060
}
6161

62-
public function testItEnforcesSecurity()
62+
public function testItEnforcesSecurity(): void
6363
{
6464
CategoryFactory::createMany(3, [
6565
'name' => 'foo so that it matches custom query',
@@ -81,7 +81,7 @@ public function testItEnforcesSecurity()
8181
;
8282
}
8383

84-
public function testItCheckMaxResultsOption()
84+
public function testItCheckMaxResultsOption(): void
8585
{
8686
CategoryFactory::createMany(30, ['name' => 'foo']);
8787

@@ -93,7 +93,7 @@ public function testItCheckMaxResultsOption()
9393
;
9494
}
9595

96-
public function testItWorksWithoutAChoiceLabel()
96+
public function testItWorksWithoutAChoiceLabel(): void
9797
{
9898
CategoryFactory::createMany(5, ['name' => 'foo']);
9999

@@ -105,7 +105,7 @@ public function testItWorksWithoutAChoiceLabel()
105105
;
106106
}
107107

108-
public function testItUsesTheCustomStringValue()
108+
public function testItUsesTheCustomStringValue(): void
109109
{
110110
$category = CategoryFactory::createOne(['code' => 'foo']);
111111

@@ -118,7 +118,7 @@ public function testItUsesTheCustomStringValue()
118118
;
119119
}
120120

121-
public function testItUsesTheCustomCallbackValue()
121+
public function testItUsesTheCustomCallbackValue(): void
122122
{
123123
$category = CategoryFactory::createOne(['code' => 'foo']);
124124

@@ -131,7 +131,7 @@ public function testItUsesTheCustomCallbackValue()
131131
;
132132
}
133133

134-
public function testItSearchesByTags()
134+
public function testItSearchesByTags(): void
135135
{
136136
$productTag = ProductTagFactory::createOne(['name' => 'technology']);
137137
$categoryTag = CategoryTagFactory::createOne(['name' => 'home appliances']);

src/Autocomplete/tests/Integration/AutocompleteResultsExecutorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class AutocompleteResultsExecutorTest extends KernelTestCase
2424
use Factories;
2525
use ResetDatabase;
2626

27-
public function testItReturnsExtraAttributes()
27+
public function testItReturnsExtraAttributes(): void
2828
{
2929
$kernel = new Kernel('test', true);
3030
$kernel->disableForms();

src/Autocomplete/tests/Integration/Doctrine/EntityMetadataFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
class EntityMetadataFactoryTest extends KernelTestCase
2020
{
21-
public function testItSuccessfullyCreatesMetadata()
21+
public function testItSuccessfullyCreatesMetadata(): void
2222
{
2323
/** @var EntityMetadataFactory $factory */
2424
$factory = self::getContainer()->get('ux.autocomplete.entity_metadata_factory');

src/Autocomplete/tests/Integration/Doctrine/EntityMetadataTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@ class EntityMetadataTest extends KernelTestCase
2525
use Factories;
2626
use ResetDatabase;
2727

28-
public function testGetAllPropertyNames()
28+
public function testGetAllPropertyNames(): void
2929
{
3030
$this->assertSame(
3131
['id', 'name', 'description', 'price', 'isEnabled'],
3232
$this->getMetadata()->getAllPropertyNames()
3333
);
3434
}
3535

36-
public function testIsAssociation()
36+
public function testIsAssociation(): void
3737
{
3838
$metadata = $this->getMetadata();
3939
$this->assertFalse($metadata->isAssociation('name'));
4040
$this->assertTrue($metadata->isAssociation('category'));
4141
}
4242

43-
public function testGetIdValue()
43+
public function testGetIdValue(): void
4444
{
4545
$product = ProductFactory::createOne();
4646
$this->assertEquals($product->getId(), $this->getMetadata()->getIdValue($product));
4747
}
4848

49-
public function testGetPropertyDataType()
49+
public function testGetPropertyDataType(): void
5050
{
5151
$metadata = $this->getMetadata();
5252
$this->assertSame(Types::STRING, $metadata->getPropertyDataType('name'));
@@ -55,7 +55,7 @@ public function testGetPropertyDataType()
5555
$this->assertEquals(2, $metadata->getPropertyDataType('category'));
5656
}
5757

58-
public function testGetFieldMetadata()
58+
public function testGetFieldMetadata(): void
5959
{
6060
$metadata = $this->getMetadata();
6161
$nameMetadata = $metadata->getFieldMetadata('name');
@@ -75,7 +75,7 @@ public function testGetFieldMetadata()
7575
}
7676
}
7777

78-
public function testGetAssociationMetadata()
78+
public function testGetAssociationMetadata(): void
7979
{
8080
$metadata = $this->getMetadata();
8181
$expected = [
@@ -132,7 +132,7 @@ public function testGetAssociationMetadata()
132132
}
133133
}
134134

135-
public function testIsEmbeddedClassProperty()
135+
public function testIsEmbeddedClassProperty(): void
136136
{
137137
// TODO
138138
$this->markTestIncomplete();

src/Autocomplete/tests/Integration/Doctrine/EntitySearchUtilTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class EntitySearchUtilTest extends KernelTestCase
2626
use Factories;
2727
use ResetDatabase;
2828

29-
public function testItCreatesBasicStringSearchQuery()
29+
public function testItCreatesBasicStringSearchQuery(): void
3030
{
3131
$prod1 = ProductFactory::createOne(['name' => 'bar prod1']);
3232
$prod2 = ProductFactory::createOne(['name' => 'foo prod2']);
@@ -37,7 +37,7 @@ public function testItCreatesBasicStringSearchQuery()
3737
$this->assertSame([$prod1, $prod2, $prod4], $results);
3838
}
3939

40-
public function testItSearchesOnCorrectFields()
40+
public function testItSearchesOnCorrectFields(): void
4141
{
4242
$prod1 = ProductFactory::createOne(['name' => 'bar prod1']);
4343
ProductFactory::createOne(['description' => 'foo prod2']);
@@ -46,7 +46,7 @@ public function testItSearchesOnCorrectFields()
4646
$this->assertSame([$prod1], $results);
4747
}
4848

49-
public function testItCanSearchOnRelationFields()
49+
public function testItCanSearchOnRelationFields(): void
5050
{
5151
$category1 = CategoryFactory::createOne(['name' => 'foods']);
5252
$category2 = CategoryFactory::createOne(['name' => 'toys']);
@@ -58,7 +58,7 @@ public function testItCanSearchOnRelationFields()
5858
$this->assertSame([$prod1, $prod2], $results);
5959
}
6060

61-
public function testItEscapesLikeWildcardsInTheQuery()
61+
public function testItEscapesLikeWildcardsInTheQuery(): void
6262
{
6363
$percent = ProductFactory::createOne(['name' => '100% legit']);
6464
$underscore = ProductFactory::createOne(['name' => 'foo_bar']);

src/Autocomplete/tests/Integration/WiringTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected static function createKernel(array $options = []): KernelInterface
3535
return $kernel;
3636
}
3737

38-
public function testWiringWithoutForm()
38+
public function testWiringWithoutForm(): void
3939
{
4040
$kernel = new Kernel('test', true);
4141
$kernel->disableForms();
@@ -51,7 +51,7 @@ public function testWiringWithoutForm()
5151
$this->assertFalse($data->hasNextPage);
5252
}
5353

54-
public function testWiringWithManyResults()
54+
public function testWiringWithManyResults(): void
5555
{
5656
$kernel = new Kernel('test', true);
5757
$kernel->disableForms();
@@ -76,7 +76,7 @@ public function testWiringWithManyResults()
7676
$this->assertFalse($data->hasNextPage);
7777
}
7878

79-
public function testWiringWithoutFormAndGroupByOption()
79+
public function testWiringWithoutFormAndGroupByOption(): void
8080
{
8181
$kernel = new Kernel('test', true);
8282
$kernel->disableForms();

0 commit comments

Comments
 (0)