|
20 | 20 | use Rector\PHPUnit\PHPUnit110\Rector\ClassMethod\MockObjectArgCreateStubToCreateMockRector; |
21 | 21 | use Rector\PHPUnit\PHPUnit120\Rector\CallLike\CreateStubInCoalesceArgRector; |
22 | 22 | use Rector\PHPUnit\PHPUnit120\Rector\CallLike\CreateStubOverCreateMockArgRector; |
| 23 | +use Rector\PHPUnit\PHPUnit120\Rector\Class_\AllowMockObjectsForDataProviderRector; |
| 24 | +use Rector\PHPUnit\PHPUnit120\Rector\Class_\AllowMockObjectsWhereParentClassRector; |
| 25 | +use Rector\PHPUnit\PHPUnit120\Rector\Class_\AllowMockObjectsWithoutExpectationsAttributeRector; |
23 | 26 | use Rector\PHPUnit\PHPUnit120\Rector\Class_\AssertIsTypeMethodCallRector; |
24 | 27 | use Rector\PHPUnit\PHPUnit120\Rector\Class_\PropertyCreateMockToCreateStubRector; |
| 28 | +use Rector\PHPUnit\PHPUnit120\Rector\Class_\RemoveOverrideFinalConstructTestCaseRector; |
25 | 29 | use Rector\PHPUnit\PHPUnit120\Rector\ClassMethod\ExpressionCreateMockToCreateStubRector; |
26 | 30 | use Rector\PHPUnit\PHPUnit120\Rector\Property\MockObjectVarToStubRector; |
27 | 31 | use Rector\PHPUnit\ValueObject\AnnotationWithValueToAttribute; |
| 32 | +use Rector\Renaming\Rector\MethodCall\RenameMethodRector; |
| 33 | +use Rector\Renaming\ValueObject\MethodCallRename; |
28 | 34 |
|
29 | 35 | /** |
30 | 36 | * Rules and configuration bound to the PHPUnit version installed in the analysed project, |
|
61 | 67 | // deprecated in PHPUnit 11.5 |
62 | 68 | AssertContainsOnlyMethodCallRector::class, |
63 | 69 | AssertIsTypeMethodCallRector::class, |
| 70 | + |
| 71 | + // the TestCase::__construct() is final since PHPUnit 12.0.3 |
| 72 | + RemoveOverrideFinalConstructTestCaseRector::class, |
| 73 | + |
| 74 | + // the AllowMockObjectsWithoutExpectations attribute exists since PHPUnit 12.5.2 |
| 75 | + AllowMockObjectsWhereParentClassRector::class, |
| 76 | + AllowMockObjectsForDataProviderRector::class, |
| 77 | + AllowMockObjectsWithoutExpectationsAttributeRector::class, |
64 | 78 | ]); |
65 | 79 |
|
66 | 80 | // both attributes were added in PHPUnit 10.0 |
|
87 | 101 | 'PHPUnit\Framework\Attributes\RunClassInSeparateProcess' |
88 | 102 | ), |
89 | 103 | ], 'phpunit/phpunit', '>=10.0 <13.0'); |
| 104 | + |
| 105 | + // the MockBuilder::onlyMethods() method was added in PHPUnit 8.3 |
| 106 | + // @see https://github.com/sebastianbergmann/phpunit/pull/3687 |
| 107 | + $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [ |
| 108 | + new MethodCallRename('PHPUnit\Framework\MockObject\MockBuilder', 'setMethods', 'onlyMethods'), |
| 109 | + ], 'phpunit/phpunit', '>=8.3'); |
| 110 | + |
| 111 | + // the expectExceptionMessageMatches() method was added in PHPUnit 8.4 |
| 112 | + // @see https://github.com/sebastianbergmann/phpunit/issues/3957 |
| 113 | + $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [ |
| 114 | + new MethodCallRename( |
| 115 | + 'PHPUnit\Framework\TestCase', |
| 116 | + 'expectExceptionMessageRegExp', |
| 117 | + 'expectExceptionMessageMatches' |
| 118 | + ), |
| 119 | + ], 'phpunit/phpunit', '>=8.4'); |
| 120 | + |
| 121 | + // all these assert methods were added in PHPUnit 9.1 |
| 122 | + // @see https://github.com/sebastianbergmann/phpunit/blob/9.1.0/ChangeLog-9.1.md |
| 123 | + $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [ |
| 124 | + new MethodCallRename('PHPUnit\Framework\Assert', 'assertRegExp', 'assertMatchesRegularExpression'), |
| 125 | + new MethodCallRename('PHPUnit\Framework\Assert', 'assertNotRegExp', 'assertDoesNotMatchRegularExpression'), |
| 126 | + new MethodCallRename('PHPUnit\Framework\Assert', 'assertFileNotExists', 'assertFileDoesNotExist'), |
| 127 | + new MethodCallRename('PHPUnit\Framework\Assert', 'assertFileNotIsReadable', 'assertFileIsNotReadable'), |
| 128 | + new MethodCallRename('PHPUnit\Framework\Assert', 'assertDirectoryNotExists', 'assertDirectoryDoesNotExist'), |
| 129 | + new MethodCallRename( |
| 130 | + 'PHPUnit\Framework\Assert', |
| 131 | + 'assertDirectoryNotIsReadable', |
| 132 | + 'assertDirectoryIsNotReadable' |
| 133 | + ), |
| 134 | + new MethodCallRename( |
| 135 | + 'PHPUnit\Framework\Assert', |
| 136 | + 'assertDirectoryNotIsWritable', |
| 137 | + 'assertDirectoryIsNotWritable' |
| 138 | + ), |
| 139 | + new MethodCallRename('PHPUnit\Framework\Assert', 'assertNotIsReadable', 'assertIsNotReadable'), |
| 140 | + new MethodCallRename('PHPUnit\Framework\Assert', 'assertNotIsWritable', 'assertIsNotWritable'), |
| 141 | + ], 'phpunit/phpunit', '>=9.1'); |
| 142 | + |
| 143 | + // the numberOfInvocations() method was added in PHPUnit 10.0 |
| 144 | + // @see https://github.com/sebastianbergmann/phpunit/commit/2ba8b7fded44a1a75cf5712a3b7310a8de0b6bb8 |
| 145 | + $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [ |
| 146 | + new MethodCallRename( |
| 147 | + 'PHPUnit\Framework\MockObject\Rule\InvocationOrder', |
| 148 | + 'getInvocationCount', |
| 149 | + 'numberOfInvocations' |
| 150 | + ), |
| 151 | + ], 'phpunit/phpunit', '>=10.0'); |
| 152 | + |
| 153 | + // the assertObjectHasProperty() and assertObjectNotHasProperty() methods were added in PHPUnit 10.1 |
| 154 | + // @see https://github.com/sebastianbergmann/phpunit/issues/5220 |
| 155 | + $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [ |
| 156 | + new MethodCallRename('PHPUnit\Framework\Assert', 'assertObjectHasAttribute', 'assertObjectHasProperty'), |
| 157 | + new MethodCallRename('PHPUnit\Framework\Assert', 'assertObjectNotHasAttribute', 'assertObjectNotHasProperty'), |
| 158 | + ], 'phpunit/phpunit', '>=10.1'); |
| 159 | + |
| 160 | + // the expectExceptionMessageIsOrContains() method was added in PHPUnit 13.2 |
| 161 | + // @see https://github.com/sebastianbergmann/phpunit/issues/6560 |
| 162 | + $rectorConfig->ruleWithConfigurationComposerVersionBound(RenameMethodRector::class, [ |
| 163 | + new MethodCallRename( |
| 164 | + 'PHPUnit\Framework\TestCase', |
| 165 | + 'expectExceptionMessage', |
| 166 | + 'expectExceptionMessageIsOrContains' |
| 167 | + ), |
| 168 | + ], 'phpunit/phpunit', '>=13.2'); |
90 | 169 | }; |
0 commit comments