Skip to content

Commit 053a6cf

Browse files
committed
[PHPunit 9] Include AssertRegExpRector in phpunit 90 set
1 parent 034f8a1 commit 053a6cf

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

config/sets/phpunit-code-quality.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertInstanceOfComparisonRector;
3838
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertIssetToSpecificMethodRector;
3939
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertNotOperatorRector;
40-
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertRegExpRector;
4140
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertSameBoolNullToSpecificMethodRector;
4241
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertSameTrueFalseToAssertTrueFalseRector;
4342
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertTrueFalseToSpecificMethodRector;
@@ -103,7 +102,6 @@
103102
AssertFalseStrposToContainsRector::class,
104103
AssertIssetToSpecificMethodRector::class,
105104
AssertInstanceOfComparisonRector::class,
106-
AssertRegExpRector::class,
107105
AssertFuncCallToPHPUnitAssertRector::class,
108106
SimplifyForeachInstanceOfRector::class,
109107
UseSpecificWillMethodRector::class,

config/sets/phpunit90.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

55
use Rector\Config\RectorConfig;
6+
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertRegExpRector;
67
use Rector\PHPUnit\PHPUnit100\Rector\StmtsAwareInterface\WithConsecutiveRector;
78
use Rector\PHPUnit\PHPUnit90\Rector\Class_\TestListenerToHooksRector;
89
use Rector\PHPUnit\PHPUnit90\Rector\MethodCall\ExplicitPhpErrorApiRector;
@@ -16,6 +17,7 @@
1617
ExplicitPhpErrorApiRector::class,
1718
SpecificAssertContainsWithoutIdentityRector::class,
1819
WithConsecutiveRector::class,
20+
AssertRegExpRector::class,
1921
]);
2022

2123
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [

rules-tests/CodeQuality/Rector/MethodCall/AssertRegExpRector/Fixture/fixture.php.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ final class MyTest extends \PHPUnit\Framework\TestCase
2323
{
2424
public function test()
2525
{
26-
$this->assertRegExp('/^Message for ".*"\.$/', $string, $message);
27-
$this->assertNotRegExp('/^Message for ".*"\.$/', $string, $message);
28-
$this->assertNotRegExp('/^Message for ".*"\.$/', $string, $message);
29-
$this->assertRegExp('/^Message for ".*"\.$/', $string, $message);
26+
$this->assertMatchesRegularExpression('/^Message for ".*"\.$/', $string, $message);
27+
$this->assertDoesNotMatchRegularExpression('/^Message for ".*"\.$/', $string, $message);
28+
$this->assertDoesNotMatchRegularExpression('/^Message for ".*"\.$/', $string, $message);
29+
$this->assertMatchesRegularExpression('/^Message for ".*"\.$/', $string, $message);
3030
}
3131
}
3232

rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public function getRuleDefinition(): RuleDefinition
5050
[
5151
new CodeSample(
5252
'$this->assertSame(1, preg_match("/^Message for ".*"\.$/", $string), $message);',
53-
'$this->assertRegExp("/^Message for ".*"\.$/", $string, $message);'
53+
'$this->assertMatchesRegularExpression("/^Message for ".*"\.$/", $string, $message);'
5454
),
5555
new CodeSample(
5656
'$this->assertEquals(false, preg_match("/^Message for ".*"\.$/", $string), $message);',
57-
'$this->assertNotRegExp("/^Message for ".*"\.$/", $string, $message);'
57+
'$this->assertDoesNotMatchRegularExpression("/^Message for ".*"\.$/", $string, $message);'
5858
),
5959
]
6060
);
@@ -163,13 +163,13 @@ private function renameMethod(MethodCall|StaticCall $node, string $oldMethodName
163163
if (in_array($oldMethodName, [self::ASSERT_SAME, self::ASSERT_EQUALS], true) && $oldCondition === 1
164164
|| in_array($oldMethodName, [self::ASSERT_NOT_SAME, self::ASSERT_NOT_EQUALS], true) && $oldCondition === 0
165165
) {
166-
$node->name = new Identifier('assertRegExp');
166+
$node->name = new Identifier('assertMatchesRegularExpression');
167167
}
168168

169169
if (in_array($oldMethodName, [self::ASSERT_SAME, self::ASSERT_EQUALS], true) && $oldCondition === 0
170170
|| in_array($oldMethodName, [self::ASSERT_NOT_SAME, self::ASSERT_NOT_EQUALS], true) && $oldCondition === 1
171171
) {
172-
$node->name = new Identifier('assertNotRegExp');
172+
$node->name = new Identifier('assertDoesNotMatchRegularExpression');
173173
}
174174
}
175175

0 commit comments

Comments
 (0)