Skip to content

Commit 389eeab

Browse files
authored
[PHPunit 9] Move AssertRegExpRector to phpunit 90 set with refactor to use assertMatchesRegularExpression/assertDoesNotMatchRegularExpression (#667)
* [PHPunit 9] Include AssertRegExpRector in phpunit 90 set * move
1 parent 034f8a1 commit 389eeab

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
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\PHPUnit90\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/AssertRegExpRectorTest.php renamed to rules-tests/PHPUnit90/Rector/MethodCall/AssertRegExpRector/AssertRegExpRectorTest.php

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

33
declare(strict_types=1);
44

5-
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertRegExpRector;
5+
namespace Rector\PHPUnit\Tests\PHPUnit90\Rector\MethodCall\AssertRegExpRector;
66

77
use Iterator;
88
use PHPUnit\Framework\Attributes\DataProvider;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertRegExpRector\Fixture;
3+
namespace Rector\PHPUnit\Tests\PHPUnit90\Rector\MethodCall\AssertRegExpRector\Fixture;
44

55
final class MyTest extends \PHPUnit\Framework\TestCase
66
{
@@ -17,16 +17,16 @@ final class MyTest extends \PHPUnit\Framework\TestCase
1717
-----
1818
<?php
1919

20-
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertRegExpRector\Fixture;
20+
namespace Rector\PHPUnit\Tests\PHPUnit90\Rector\MethodCall\AssertRegExpRector\Fixture;
2121

2222
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-tests/CodeQuality/Rector/MethodCall/AssertRegExpRector/Fixture/skip_used_by_next_stmt.php.inc renamed to rules-tests/PHPUnit90/Rector/MethodCall/AssertRegExpRector/Fixture/skip_used_by_next_stmt.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertRegExpRector\Fixture;
3+
namespace Rector\PHPUnit\Tests\PHPUnit90\Rector\MethodCall\AssertRegExpRector\Fixture;
44

55
final class SkipUsedByNextStmt extends \PHPUnit\Framework\TestCase
66
{

rules-tests/CodeQuality/Rector/MethodCall/AssertRegExpRector/config/configured_rule.php renamed to rules-tests/PHPUnit90/Rector/MethodCall/AssertRegExpRector/config/configured_rule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
declare(strict_types=1);
44

55
use Rector\Config\RectorConfig;
6-
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertRegExpRector;
6+
use Rector\PHPUnit\PHPUnit90\Rector\MethodCall\AssertRegExpRector;
77

88
return static function (RectorConfig $rectorConfig): void {
99
$rectorConfig->rule(AssertRegExpRector::class);

rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php renamed to rules/PHPUnit90/Rector/MethodCall/AssertRegExpRector.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Rector\PHPUnit\CodeQuality\Rector\MethodCall;
5+
namespace Rector\PHPUnit\PHPUnit90\Rector\MethodCall;
66

77
use PhpParser\Node;
88
use PhpParser\Node\Expr;
@@ -24,7 +24,7 @@
2424
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
2525

2626
/**
27-
* @see \Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertRegExpRector\AssertRegExpRectorTest
27+
* @see \Rector\PHPUnit\Tests\PHPUnit90\Rector\MethodCall\AssertRegExpRector\AssertRegExpRectorTest
2828
*/
2929
final class AssertRegExpRector extends AbstractRector
3030
{
@@ -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)