diff --git a/config/sets/phpunit-code-quality.php b/config/sets/phpunit-code-quality.php index 6cae5e18..70e4b5aa 100644 --- a/config/sets/phpunit-code-quality.php +++ b/config/sets/phpunit-code-quality.php @@ -37,7 +37,6 @@ use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertInstanceOfComparisonRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertIssetToSpecificMethodRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertNotOperatorRector; -use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertRegExpRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertSameBoolNullToSpecificMethodRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertSameTrueFalseToAssertTrueFalseRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertTrueFalseToSpecificMethodRector; @@ -103,7 +102,6 @@ AssertFalseStrposToContainsRector::class, AssertIssetToSpecificMethodRector::class, AssertInstanceOfComparisonRector::class, - AssertRegExpRector::class, AssertFuncCallToPHPUnitAssertRector::class, SimplifyForeachInstanceOfRector::class, UseSpecificWillMethodRector::class, diff --git a/config/sets/phpunit90.php b/config/sets/phpunit90.php index 96f1f45e..34e15137 100644 --- a/config/sets/phpunit90.php +++ b/config/sets/phpunit90.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Rector\Config\RectorConfig; +use Rector\PHPUnit\PHPUnit90\Rector\MethodCall\AssertRegExpRector; use Rector\PHPUnit\PHPUnit100\Rector\StmtsAwareInterface\WithConsecutiveRector; use Rector\PHPUnit\PHPUnit90\Rector\Class_\TestListenerToHooksRector; use Rector\PHPUnit\PHPUnit90\Rector\MethodCall\ExplicitPhpErrorApiRector; @@ -16,6 +17,7 @@ ExplicitPhpErrorApiRector::class, SpecificAssertContainsWithoutIdentityRector::class, WithConsecutiveRector::class, + AssertRegExpRector::class, ]); $rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [ diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertRegExpRector/AssertRegExpRectorTest.php b/rules-tests/PHPUnit90/Rector/MethodCall/AssertRegExpRector/AssertRegExpRectorTest.php similarity index 88% rename from rules-tests/CodeQuality/Rector/MethodCall/AssertRegExpRector/AssertRegExpRectorTest.php rename to rules-tests/PHPUnit90/Rector/MethodCall/AssertRegExpRector/AssertRegExpRectorTest.php index 102ba104..f16d1210 100644 --- a/rules-tests/CodeQuality/Rector/MethodCall/AssertRegExpRector/AssertRegExpRectorTest.php +++ b/rules-tests/PHPUnit90/Rector/MethodCall/AssertRegExpRector/AssertRegExpRectorTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertRegExpRector; +namespace Rector\PHPUnit\Tests\PHPUnit90\Rector\MethodCall\AssertRegExpRector; use Iterator; use PHPUnit\Framework\Attributes\DataProvider; diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertRegExpRector/Fixture/fixture.php.inc b/rules-tests/PHPUnit90/Rector/MethodCall/AssertRegExpRector/Fixture/fixture.php.inc similarity index 52% rename from rules-tests/CodeQuality/Rector/MethodCall/AssertRegExpRector/Fixture/fixture.php.inc rename to rules-tests/PHPUnit90/Rector/MethodCall/AssertRegExpRector/Fixture/fixture.php.inc index d7da230b..0924c974 100644 --- a/rules-tests/CodeQuality/Rector/MethodCall/AssertRegExpRector/Fixture/fixture.php.inc +++ b/rules-tests/PHPUnit90/Rector/MethodCall/AssertRegExpRector/Fixture/fixture.php.inc @@ -1,6 +1,6 @@ assertRegExp('/^Message for ".*"\.$/', $string, $message); - $this->assertNotRegExp('/^Message for ".*"\.$/', $string, $message); - $this->assertNotRegExp('/^Message for ".*"\.$/', $string, $message); - $this->assertRegExp('/^Message for ".*"\.$/', $string, $message); + $this->assertMatchesRegularExpression('/^Message for ".*"\.$/', $string, $message); + $this->assertDoesNotMatchRegularExpression('/^Message for ".*"\.$/', $string, $message); + $this->assertDoesNotMatchRegularExpression('/^Message for ".*"\.$/', $string, $message); + $this->assertMatchesRegularExpression('/^Message for ".*"\.$/', $string, $message); } } diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertRegExpRector/Fixture/skip_used_by_next_stmt.php.inc b/rules-tests/PHPUnit90/Rector/MethodCall/AssertRegExpRector/Fixture/skip_used_by_next_stmt.php.inc similarity index 77% rename from rules-tests/CodeQuality/Rector/MethodCall/AssertRegExpRector/Fixture/skip_used_by_next_stmt.php.inc rename to rules-tests/PHPUnit90/Rector/MethodCall/AssertRegExpRector/Fixture/skip_used_by_next_stmt.php.inc index 21c6bdd5..f33c2fe4 100644 --- a/rules-tests/CodeQuality/Rector/MethodCall/AssertRegExpRector/Fixture/skip_used_by_next_stmt.php.inc +++ b/rules-tests/PHPUnit90/Rector/MethodCall/AssertRegExpRector/Fixture/skip_used_by_next_stmt.php.inc @@ -1,6 +1,6 @@ rule(AssertRegExpRector::class); diff --git a/rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php b/rules/PHPUnit90/Rector/MethodCall/AssertRegExpRector.php similarity index 91% rename from rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php rename to rules/PHPUnit90/Rector/MethodCall/AssertRegExpRector.php index 23bbf683..65d4f1dc 100644 --- a/rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php +++ b/rules/PHPUnit90/Rector/MethodCall/AssertRegExpRector.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\PHPUnit\CodeQuality\Rector\MethodCall; +namespace Rector\PHPUnit\PHPUnit90\Rector\MethodCall; use PhpParser\Node; use PhpParser\Node\Expr; @@ -24,7 +24,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * @see \Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertRegExpRector\AssertRegExpRectorTest + * @see \Rector\PHPUnit\Tests\PHPUnit90\Rector\MethodCall\AssertRegExpRector\AssertRegExpRectorTest */ final class AssertRegExpRector extends AbstractRector { @@ -50,11 +50,11 @@ public function getRuleDefinition(): RuleDefinition [ new CodeSample( '$this->assertSame(1, preg_match("/^Message for ".*"\.$/", $string), $message);', - '$this->assertRegExp("/^Message for ".*"\.$/", $string, $message);' + '$this->assertMatchesRegularExpression("/^Message for ".*"\.$/", $string, $message);' ), new CodeSample( '$this->assertEquals(false, preg_match("/^Message for ".*"\.$/", $string), $message);', - '$this->assertNotRegExp("/^Message for ".*"\.$/", $string, $message);' + '$this->assertDoesNotMatchRegularExpression("/^Message for ".*"\.$/", $string, $message);' ), ] ); @@ -163,13 +163,13 @@ private function renameMethod(MethodCall|StaticCall $node, string $oldMethodName if (in_array($oldMethodName, [self::ASSERT_SAME, self::ASSERT_EQUALS], true) && $oldCondition === 1 || in_array($oldMethodName, [self::ASSERT_NOT_SAME, self::ASSERT_NOT_EQUALS], true) && $oldCondition === 0 ) { - $node->name = new Identifier('assertRegExp'); + $node->name = new Identifier('assertMatchesRegularExpression'); } if (in_array($oldMethodName, [self::ASSERT_SAME, self::ASSERT_EQUALS], true) && $oldCondition === 0 || in_array($oldMethodName, [self::ASSERT_NOT_SAME, self::ASSERT_NOT_EQUALS], true) && $oldCondition === 1 ) { - $node->name = new Identifier('assertNotRegExp'); + $node->name = new Identifier('assertDoesNotMatchRegularExpression'); } }