|
71 | 71 | * Thanks to the composer package constraint, these rules can be registered once here, instead of being |
72 | 72 | * repeated in every PHPUnit version set to cover a direct upgrade from an older version. |
73 | 73 | */ |
74 | | -return static function (RectorConfig $rectorConfig): void { |
| 74 | +return RectorConfig::configure() |
75 | 75 | // each of these rules declares the "phpunit/phpunit" version its attributes were added in, |
76 | 76 | // @see ComposerPackageConstraintInterface |
77 | | - $rectorConfig->rules([ |
| 77 | + ->withRules([ |
78 | 78 | TicketAnnotationToAttributeRector::class, |
79 | 79 | TestWithAnnotationToAttributeRector::class, |
80 | 80 | DataProviderAnnotationToAttributeRector::class, |
|
157 | 157 |
|
158 | 158 | // PHPUnit 11.0 |
159 | 159 | NamedArgumentForDataProviderRector::class, |
160 | | - ]); |
| 160 | + ]) |
161 | 161 |
|
162 | 162 | // both attributes were added in PHPUnit 10.0 |
163 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(AnnotationWithValueToAttributeRector::class, [ |
| 163 | + ->withComposerBasedRule(AnnotationWithValueToAttributeRector::class, [ |
164 | 164 | // the PHPUnit 10 spelling of the "backupStaticAttributes" annotation |
165 | 165 | new AnnotationWithValueToAttribute( |
166 | 166 | 'backupStaticProperties', |
|
174 | 174 | 'excludeGlobalVariableFromBackup', |
175 | 175 | 'PHPUnit\Framework\Attributes\ExcludeGlobalVariableFromBackup' |
176 | 176 | ), |
177 | | - ], 'phpunit/phpunit', '>=10.0'); |
| 177 | + ], 'phpunit/phpunit', '>=10.0') |
178 | 178 |
|
179 | 179 | // the RunClassInSeparateProcess attribute was added in PHPUnit 10.0 and removed in PHPUnit 13.0 |
180 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(AnnotationToAttributeRector::class, [ |
| 180 | + ->withComposerBasedRule(AnnotationToAttributeRector::class, [ |
181 | 181 | new AnnotationToAttribute( |
182 | 182 | 'runClassInSeparateProcess', |
183 | 183 | 'PHPUnit\Framework\Attributes\RunClassInSeparateProcess' |
184 | 184 | ), |
185 | | - ], 'phpunit/phpunit', '>=10.0 <13.0'); |
| 185 | + ], 'phpunit/phpunit', '>=10.0 <13.0') |
186 | 186 |
|
187 | 187 | // the MockBuilder::onlyMethods() method was added in PHPUnit 8.3 |
188 | 188 | // @see https://github.com/sebastianbergmann/phpunit/pull/3687 |
189 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [ |
| 189 | + ->withComposerBasedRule(RenameMethodRector::class, [ |
190 | 190 | new MethodCallRename('PHPUnit\Framework\MockObject\MockBuilder', 'setMethods', 'onlyMethods'), |
191 | | - ], 'phpunit/phpunit', '>=8.3'); |
| 191 | + ], 'phpunit/phpunit', '>=8.3') |
192 | 192 |
|
193 | 193 | // the expectExceptionMessageMatches() method was added in PHPUnit 8.4 |
194 | 194 | // @see https://github.com/sebastianbergmann/phpunit/issues/3957 |
195 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [ |
| 195 | + ->withComposerBasedRule(RenameMethodRector::class, [ |
196 | 196 | new MethodCallRename( |
197 | 197 | 'PHPUnit\Framework\TestCase', |
198 | 198 | 'expectExceptionMessageRegExp', |
199 | 199 | 'expectExceptionMessageMatches' |
200 | 200 | ), |
201 | | - ], 'phpunit/phpunit', '>=8.4'); |
| 201 | + ], 'phpunit/phpunit', '>=8.4') |
202 | 202 |
|
203 | 203 | // all these assert methods were added in PHPUnit 9.1 |
204 | 204 | // @see https://github.com/sebastianbergmann/phpunit/blob/9.1.0/ChangeLog-9.1.md |
205 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [ |
| 205 | + ->withComposerBasedRule(RenameMethodRector::class, [ |
206 | 206 | new MethodCallRename('PHPUnit\Framework\Assert', 'assertRegExp', 'assertMatchesRegularExpression'), |
207 | 207 | new MethodCallRename('PHPUnit\Framework\Assert', 'assertNotRegExp', 'assertDoesNotMatchRegularExpression'), |
208 | 208 | new MethodCallRename('PHPUnit\Framework\Assert', 'assertFileNotExists', 'assertFileDoesNotExist'), |
|
220 | 220 | ), |
221 | 221 | new MethodCallRename('PHPUnit\Framework\Assert', 'assertNotIsReadable', 'assertIsNotReadable'), |
222 | 222 | new MethodCallRename('PHPUnit\Framework\Assert', 'assertNotIsWritable', 'assertIsNotWritable'), |
223 | | - ], 'phpunit/phpunit', '>=9.1'); |
| 223 | + ], 'phpunit/phpunit', '>=9.1') |
224 | 224 |
|
225 | 225 | // the numberOfInvocations() method was added in PHPUnit 10.0 |
226 | 226 | // @see https://github.com/sebastianbergmann/phpunit/commit/2ba8b7fded44a1a75cf5712a3b7310a8de0b6bb8 |
227 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [ |
| 227 | + ->withComposerBasedRule(RenameMethodRector::class, [ |
228 | 228 | new MethodCallRename( |
229 | 229 | 'PHPUnit\Framework\MockObject\Rule\InvocationOrder', |
230 | 230 | 'getInvocationCount', |
231 | 231 | 'numberOfInvocations' |
232 | 232 | ), |
233 | | - ], 'phpunit/phpunit', '>=10.0'); |
| 233 | + ], 'phpunit/phpunit', '>=10.0') |
234 | 234 |
|
235 | 235 | // the assertObjectHasProperty() and assertObjectNotHasProperty() methods were added in PHPUnit 10.1 |
236 | 236 | // @see https://github.com/sebastianbergmann/phpunit/issues/5220 |
237 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [ |
| 237 | + ->withComposerBasedRule(RenameMethodRector::class, [ |
238 | 238 | new MethodCallRename('PHPUnit\Framework\Assert', 'assertObjectHasAttribute', 'assertObjectHasProperty'), |
239 | 239 | new MethodCallRename('PHPUnit\Framework\Assert', 'assertObjectNotHasAttribute', 'assertObjectNotHasProperty'), |
240 | | - ], 'phpunit/phpunit', '>=10.1'); |
| 240 | + ], 'phpunit/phpunit', '>=10.1') |
241 | 241 |
|
242 | 242 | // the expectExceptionMessageIsOrContains() method was added in PHPUnit 13.2 |
243 | 243 | // @see https://github.com/sebastianbergmann/phpunit/issues/6560 |
244 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [ |
| 244 | + ->withComposerBasedRule(RenameMethodRector::class, [ |
245 | 245 | new MethodCallRename( |
246 | 246 | 'PHPUnit\Framework\TestCase', |
247 | 247 | 'expectExceptionMessage', |
248 | 248 | 'expectExceptionMessageIsOrContains' |
249 | 249 | ), |
250 | | - ], 'phpunit/phpunit', '>=13.2'); |
| 250 | + ], 'phpunit/phpunit', '>=13.2') |
251 | 251 | // the staticExpects() method was removed in PHPUnit 4.0 |
252 | 252 | // @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/137 |
253 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [ |
| 253 | + ->withComposerBasedRule(RenameMethodRector::class, [ |
254 | 254 | new MethodCallRename('PHPUnit_Framework_MockObject_MockObject', 'staticExpects', 'expects'), |
255 | | - ], 'phpunit/phpunit', '>=4.0'); |
| 255 | + ], 'phpunit/phpunit', '>=4.0') |
256 | 256 |
|
257 | 257 | // the namespaced class names were introduced in PHPUnit 6.0 |
258 | 258 | // @see https://github.com/sebastianbergmann/phpunit/compare/5.7.9...6.0.0 |
259 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [ |
| 259 | + ->withComposerBasedRule(RenameMethodRector::class, [ |
260 | 260 | new MethodCallRename('PHPUnit\Framework\TestClass', 'setExpectedException', 'expectedException'), |
261 | 261 | new MethodCallRename('PHPUnit\Framework\TestClass', 'setExpectedExceptionRegExp', 'expectedException'), |
262 | 262 | new MethodCallRename('PHPUnit\Framework\TestCase', 'createMockBuilder', 'getMockBuilder'), |
263 | | - ], 'phpunit/phpunit', '>=6.0'); |
| 263 | + ], 'phpunit/phpunit', '>=6.0') |
264 | 264 |
|
265 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameClassRector::class, [ |
| 265 | + ->withComposerBasedRule(RenameClassRector::class, [ |
266 | 266 | // ref. https://github.com/sebastianbergmann/phpunit/compare/5.7.9...6.0.0 |
267 | 267 | 'PHPUnit_Framework_MockObject_Stub' => 'PHPUnit\Framework\MockObject\Stub', |
268 | 268 | 'PHPUnit_Framework_MockObject_Stub_Return' => 'PHPUnit\Framework\MockObject\Stub\ReturnStub', |
|
390 | 390 | 'PHPUnit_Util_TestSuiteIterator' => 'PHPUnit\Framework\TestSuiteIterator', |
391 | 391 | 'PHPUnit_Util_Type' => 'PHPUnit\Util\Type', |
392 | 392 | 'PHPUnit_Util_Test' => 'PHPUnit\Util\Test', |
393 | | - ], 'phpunit/phpunit', '>=6.0'); |
| 393 | + ], 'phpunit/phpunit', '>=6.0') |
394 | 394 |
|
395 | 395 | // the TestCase methods were given native types in PHPUnit 8.0 |
396 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(AddParamTypeDeclarationRector::class, [ |
| 396 | + ->withComposerBasedRule(AddParamTypeDeclarationRector::class, [ |
397 | 397 | // @see https://github.com/rectorphp/rector/issues/1024 - no type, $dataName |
398 | 398 | new AddParamTypeDeclaration('PHPUnit\Framework\TestCase', MethodName::CONSTRUCT, 2, new MixedType()), |
399 | | - ], 'phpunit/phpunit', '>=8.0'); |
| 399 | + ], 'phpunit/phpunit', '>=8.0') |
400 | 400 |
|
401 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(AddReturnTypeDeclarationRector::class, [ |
| 401 | + ->withComposerBasedRule(AddReturnTypeDeclarationRector::class, [ |
402 | 402 | new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'setUpBeforeClass', new VoidType()), |
403 | 403 | new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'setUp', new VoidType()), |
404 | 404 | new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'assertPreConditions', new VoidType()), |
405 | 405 | new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'assertPostConditions', new VoidType()), |
406 | 406 | new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'tearDown', new VoidType()), |
407 | 407 | new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'tearDownAfterClass', new VoidType()), |
408 | 408 | new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'onNotSuccessfulTest', new VoidType()), |
409 | | - ], 'phpunit/phpunit', '>=8.0'); |
| 409 | + ], 'phpunit/phpunit', '>=8.0') |
410 | 410 |
|
411 | 411 | // the expectDeprecationMessage(), expectNoticeMessage(), expectWarningMessage() and expectErrorMessage() |
412 | 412 | // methods were removed in PHPUnit 10.0 |
413 | 413 | // @see https://github.com/sebastianbergmann/phpunit/issues/5062 |
414 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [ |
| 414 | + ->withComposerBasedRule(RenameMethodRector::class, [ |
415 | 415 | new MethodCallRename('PHPUnit\Framework\TestCase', 'expectDeprecationMessage', 'expectExceptionMessage'), |
416 | 416 | new MethodCallRename( |
417 | 417 | 'PHPUnit\Framework\TestCase', |
|
436 | 436 | 'expectErrorMessageMatches', |
437 | 437 | 'expectExceptionMessageMatches' |
438 | 438 | ), |
439 | | - ], 'phpunit/phpunit', '>=10.0'); |
| 439 | + ], 'phpunit/phpunit', '>=10.0') |
440 | 440 | // the attributes replacing these annotations were all added in PHPUnit 10.0 |
441 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(AnnotationWithValueToAttributeRector::class, [ |
| 441 | + ->withComposerBasedRule(AnnotationWithValueToAttributeRector::class, [ |
442 | 442 | new AnnotationWithValueToAttribute('backupGlobals', 'PHPUnit\Framework\Attributes\BackupGlobals', [ |
443 | 443 | 'enabled' => true, |
444 | 444 | 'disabled' => false, |
|
457 | 457 | new AnnotationWithValueToAttribute('uses', 'PHPUnit\Framework\Attributes\UsesClass', [], true), |
458 | 458 | new AnnotationWithValueToAttribute('testDox', 'PHPUnit\Framework\Attributes\TestDox'), |
459 | 459 | new AnnotationWithValueToAttribute('testdox', 'PHPUnit\Framework\Attributes\TestDox'), |
460 | | - ], 'phpunit/phpunit', '>=10.0'); |
| 460 | + ], 'phpunit/phpunit', '>=10.0') |
461 | 461 |
|
462 | | - $rectorConfig->ruleWithConfigurationComposerVersionBound(AnnotationToAttributeRector::class, [ |
| 462 | + ->withComposerBasedRule(AnnotationToAttributeRector::class, [ |
463 | 463 | // @see https://github.com/sebastianbergmann/phpunit/issues/4502 |
464 | 464 | new AnnotationToAttribute('after', 'PHPUnit\Framework\Attributes\After'), |
465 | 465 | new AnnotationToAttribute('afterClass', 'PHPUnit\Framework\Attributes\AfterClass'), |
|
482 | 482 | new AnnotationToAttribute('small', 'PHPUnit\Framework\Attributes\Small'), |
483 | 483 | new AnnotationToAttribute('test', 'PHPUnit\Framework\Attributes\Test'), |
484 | 484 | ], 'phpunit/phpunit', '>=10.0'); |
485 | | -}; |
0 commit comments