Skip to content

Commit 0a640f1

Browse files
authored
Use fluent withComposerBasedRule() in composer-based set (#816)
1 parent 619b8b8 commit 0a640f1

1 file changed

Lines changed: 34 additions & 35 deletions

File tree

‎config/sets/composer-based.php‎

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@
7171
* Thanks to the composer package constraint, these rules can be registered once here, instead of being
7272
* repeated in every PHPUnit version set to cover a direct upgrade from an older version.
7373
*/
74-
return static function (RectorConfig $rectorConfig): void {
74+
return RectorConfig::configure()
7575
// each of these rules declares the "phpunit/phpunit" version its attributes were added in,
7676
// @see ComposerPackageConstraintInterface
77-
$rectorConfig->rules([
77+
->withRules([
7878
TicketAnnotationToAttributeRector::class,
7979
TestWithAnnotationToAttributeRector::class,
8080
DataProviderAnnotationToAttributeRector::class,
@@ -157,10 +157,10 @@
157157

158158
// PHPUnit 11.0
159159
NamedArgumentForDataProviderRector::class,
160-
]);
160+
])
161161

162162
// both attributes were added in PHPUnit 10.0
163-
$rectorConfig->ruleWithConfigurationComposerVersionBound(AnnotationWithValueToAttributeRector::class, [
163+
->withComposerBasedRule(AnnotationWithValueToAttributeRector::class, [
164164
// the PHPUnit 10 spelling of the "backupStaticAttributes" annotation
165165
new AnnotationWithValueToAttribute(
166166
'backupStaticProperties',
@@ -174,35 +174,35 @@
174174
'excludeGlobalVariableFromBackup',
175175
'PHPUnit\Framework\Attributes\ExcludeGlobalVariableFromBackup'
176176
),
177-
], 'phpunit/phpunit', '>=10.0');
177+
], 'phpunit/phpunit', '>=10.0')
178178

179179
// the RunClassInSeparateProcess attribute was added in PHPUnit 10.0 and removed in PHPUnit 13.0
180-
$rectorConfig->ruleWithConfigurationComposerVersionBound(AnnotationToAttributeRector::class, [
180+
->withComposerBasedRule(AnnotationToAttributeRector::class, [
181181
new AnnotationToAttribute(
182182
'runClassInSeparateProcess',
183183
'PHPUnit\Framework\Attributes\RunClassInSeparateProcess'
184184
),
185-
], 'phpunit/phpunit', '>=10.0 <13.0');
185+
], 'phpunit/phpunit', '>=10.0 <13.0')
186186

187187
// the MockBuilder::onlyMethods() method was added in PHPUnit 8.3
188188
// @see https://github.com/sebastianbergmann/phpunit/pull/3687
189-
$rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [
189+
->withComposerBasedRule(RenameMethodRector::class, [
190190
new MethodCallRename('PHPUnit\Framework\MockObject\MockBuilder', 'setMethods', 'onlyMethods'),
191-
], 'phpunit/phpunit', '>=8.3');
191+
], 'phpunit/phpunit', '>=8.3')
192192

193193
// the expectExceptionMessageMatches() method was added in PHPUnit 8.4
194194
// @see https://github.com/sebastianbergmann/phpunit/issues/3957
195-
$rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [
195+
->withComposerBasedRule(RenameMethodRector::class, [
196196
new MethodCallRename(
197197
'PHPUnit\Framework\TestCase',
198198
'expectExceptionMessageRegExp',
199199
'expectExceptionMessageMatches'
200200
),
201-
], 'phpunit/phpunit', '>=8.4');
201+
], 'phpunit/phpunit', '>=8.4')
202202

203203
// all these assert methods were added in PHPUnit 9.1
204204
// @see https://github.com/sebastianbergmann/phpunit/blob/9.1.0/ChangeLog-9.1.md
205-
$rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [
205+
->withComposerBasedRule(RenameMethodRector::class, [
206206
new MethodCallRename('PHPUnit\Framework\Assert', 'assertRegExp', 'assertMatchesRegularExpression'),
207207
new MethodCallRename('PHPUnit\Framework\Assert', 'assertNotRegExp', 'assertDoesNotMatchRegularExpression'),
208208
new MethodCallRename('PHPUnit\Framework\Assert', 'assertFileNotExists', 'assertFileDoesNotExist'),
@@ -220,49 +220,49 @@
220220
),
221221
new MethodCallRename('PHPUnit\Framework\Assert', 'assertNotIsReadable', 'assertIsNotReadable'),
222222
new MethodCallRename('PHPUnit\Framework\Assert', 'assertNotIsWritable', 'assertIsNotWritable'),
223-
], 'phpunit/phpunit', '>=9.1');
223+
], 'phpunit/phpunit', '>=9.1')
224224

225225
// the numberOfInvocations() method was added in PHPUnit 10.0
226226
// @see https://github.com/sebastianbergmann/phpunit/commit/2ba8b7fded44a1a75cf5712a3b7310a8de0b6bb8
227-
$rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [
227+
->withComposerBasedRule(RenameMethodRector::class, [
228228
new MethodCallRename(
229229
'PHPUnit\Framework\MockObject\Rule\InvocationOrder',
230230
'getInvocationCount',
231231
'numberOfInvocations'
232232
),
233-
], 'phpunit/phpunit', '>=10.0');
233+
], 'phpunit/phpunit', '>=10.0')
234234

235235
// the assertObjectHasProperty() and assertObjectNotHasProperty() methods were added in PHPUnit 10.1
236236
// @see https://github.com/sebastianbergmann/phpunit/issues/5220
237-
$rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [
237+
->withComposerBasedRule(RenameMethodRector::class, [
238238
new MethodCallRename('PHPUnit\Framework\Assert', 'assertObjectHasAttribute', 'assertObjectHasProperty'),
239239
new MethodCallRename('PHPUnit\Framework\Assert', 'assertObjectNotHasAttribute', 'assertObjectNotHasProperty'),
240-
], 'phpunit/phpunit', '>=10.1');
240+
], 'phpunit/phpunit', '>=10.1')
241241

242242
// the expectExceptionMessageIsOrContains() method was added in PHPUnit 13.2
243243
// @see https://github.com/sebastianbergmann/phpunit/issues/6560
244-
$rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [
244+
->withComposerBasedRule(RenameMethodRector::class, [
245245
new MethodCallRename(
246246
'PHPUnit\Framework\TestCase',
247247
'expectExceptionMessage',
248248
'expectExceptionMessageIsOrContains'
249249
),
250-
], 'phpunit/phpunit', '>=13.2');
250+
], 'phpunit/phpunit', '>=13.2')
251251
// the staticExpects() method was removed in PHPUnit 4.0
252252
// @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/137
253-
$rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [
253+
->withComposerBasedRule(RenameMethodRector::class, [
254254
new MethodCallRename('PHPUnit_Framework_MockObject_MockObject', 'staticExpects', 'expects'),
255-
], 'phpunit/phpunit', '>=4.0');
255+
], 'phpunit/phpunit', '>=4.0')
256256

257257
// the namespaced class names were introduced in PHPUnit 6.0
258258
// @see https://github.com/sebastianbergmann/phpunit/compare/5.7.9...6.0.0
259-
$rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [
259+
->withComposerBasedRule(RenameMethodRector::class, [
260260
new MethodCallRename('PHPUnit\Framework\TestClass', 'setExpectedException', 'expectedException'),
261261
new MethodCallRename('PHPUnit\Framework\TestClass', 'setExpectedExceptionRegExp', 'expectedException'),
262262
new MethodCallRename('PHPUnit\Framework\TestCase', 'createMockBuilder', 'getMockBuilder'),
263-
], 'phpunit/phpunit', '>=6.0');
263+
], 'phpunit/phpunit', '>=6.0')
264264

265-
$rectorConfig->ruleWithConfigurationComposerVersionBound(RenameClassRector::class, [
265+
->withComposerBasedRule(RenameClassRector::class, [
266266
// ref. https://github.com/sebastianbergmann/phpunit/compare/5.7.9...6.0.0
267267
'PHPUnit_Framework_MockObject_Stub' => 'PHPUnit\Framework\MockObject\Stub',
268268
'PHPUnit_Framework_MockObject_Stub_Return' => 'PHPUnit\Framework\MockObject\Stub\ReturnStub',
@@ -390,28 +390,28 @@
390390
'PHPUnit_Util_TestSuiteIterator' => 'PHPUnit\Framework\TestSuiteIterator',
391391
'PHPUnit_Util_Type' => 'PHPUnit\Util\Type',
392392
'PHPUnit_Util_Test' => 'PHPUnit\Util\Test',
393-
], 'phpunit/phpunit', '>=6.0');
393+
], 'phpunit/phpunit', '>=6.0')
394394

395395
// the TestCase methods were given native types in PHPUnit 8.0
396-
$rectorConfig->ruleWithConfigurationComposerVersionBound(AddParamTypeDeclarationRector::class, [
396+
->withComposerBasedRule(AddParamTypeDeclarationRector::class, [
397397
// @see https://github.com/rectorphp/rector/issues/1024 - no type, $dataName
398398
new AddParamTypeDeclaration('PHPUnit\Framework\TestCase', MethodName::CONSTRUCT, 2, new MixedType()),
399-
], 'phpunit/phpunit', '>=8.0');
399+
], 'phpunit/phpunit', '>=8.0')
400400

401-
$rectorConfig->ruleWithConfigurationComposerVersionBound(AddReturnTypeDeclarationRector::class, [
401+
->withComposerBasedRule(AddReturnTypeDeclarationRector::class, [
402402
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'setUpBeforeClass', new VoidType()),
403403
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'setUp', new VoidType()),
404404
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'assertPreConditions', new VoidType()),
405405
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'assertPostConditions', new VoidType()),
406406
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'tearDown', new VoidType()),
407407
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'tearDownAfterClass', new VoidType()),
408408
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'onNotSuccessfulTest', new VoidType()),
409-
], 'phpunit/phpunit', '>=8.0');
409+
], 'phpunit/phpunit', '>=8.0')
410410

411411
// the expectDeprecationMessage(), expectNoticeMessage(), expectWarningMessage() and expectErrorMessage()
412412
// methods were removed in PHPUnit 10.0
413413
// @see https://github.com/sebastianbergmann/phpunit/issues/5062
414-
$rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [
414+
->withComposerBasedRule(RenameMethodRector::class, [
415415
new MethodCallRename('PHPUnit\Framework\TestCase', 'expectDeprecationMessage', 'expectExceptionMessage'),
416416
new MethodCallRename(
417417
'PHPUnit\Framework\TestCase',
@@ -436,9 +436,9 @@
436436
'expectErrorMessageMatches',
437437
'expectExceptionMessageMatches'
438438
),
439-
], 'phpunit/phpunit', '>=10.0');
439+
], 'phpunit/phpunit', '>=10.0')
440440
// the attributes replacing these annotations were all added in PHPUnit 10.0
441-
$rectorConfig->ruleWithConfigurationComposerVersionBound(AnnotationWithValueToAttributeRector::class, [
441+
->withComposerBasedRule(AnnotationWithValueToAttributeRector::class, [
442442
new AnnotationWithValueToAttribute('backupGlobals', 'PHPUnit\Framework\Attributes\BackupGlobals', [
443443
'enabled' => true,
444444
'disabled' => false,
@@ -457,9 +457,9 @@
457457
new AnnotationWithValueToAttribute('uses', 'PHPUnit\Framework\Attributes\UsesClass', [], true),
458458
new AnnotationWithValueToAttribute('testDox', 'PHPUnit\Framework\Attributes\TestDox'),
459459
new AnnotationWithValueToAttribute('testdox', 'PHPUnit\Framework\Attributes\TestDox'),
460-
], 'phpunit/phpunit', '>=10.0');
460+
], 'phpunit/phpunit', '>=10.0')
461461

462-
$rectorConfig->ruleWithConfigurationComposerVersionBound(AnnotationToAttributeRector::class, [
462+
->withComposerBasedRule(AnnotationToAttributeRector::class, [
463463
// @see https://github.com/sebastianbergmann/phpunit/issues/4502
464464
new AnnotationToAttribute('after', 'PHPUnit\Framework\Attributes\After'),
465465
new AnnotationToAttribute('afterClass', 'PHPUnit\Framework\Attributes\AfterClass'),
@@ -482,4 +482,3 @@
482482
new AnnotationToAttribute('small', 'PHPUnit\Framework\Attributes\Small'),
483483
new AnnotationToAttribute('test', 'PHPUnit\Framework\Attributes\Test'),
484484
], 'phpunit/phpunit', '>=10.0');
485-
};

0 commit comments

Comments
 (0)