Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions config/sets/phpunit-code-quality.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,7 +102,6 @@
AssertFalseStrposToContainsRector::class,
AssertIssetToSpecificMethodRector::class,
AssertInstanceOfComparisonRector::class,
AssertRegExpRector::class,
AssertFuncCallToPHPUnitAssertRector::class,
SimplifyForeachInstanceOfRector::class,
UseSpecificWillMethodRector::class,
Expand Down
2 changes: 2 additions & 0 deletions config/sets/phpunit90.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,6 +17,7 @@
ExplicitPhpErrorApiRector::class,
SpecificAssertContainsWithoutIdentityRector::class,
WithConsecutiveRector::class,
AssertRegExpRector::class,
]);

$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertRegExpRector\Fixture;
namespace Rector\PHPUnit\Tests\PHPUnit90\Rector\MethodCall\AssertRegExpRector\Fixture;

final class MyTest extends \PHPUnit\Framework\TestCase
{
Expand All @@ -17,16 +17,16 @@ final class MyTest extends \PHPUnit\Framework\TestCase
-----
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertRegExpRector\Fixture;
namespace Rector\PHPUnit\Tests\PHPUnit90\Rector\MethodCall\AssertRegExpRector\Fixture;

final class MyTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
$this->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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertRegExpRector\Fixture;
namespace Rector\PHPUnit\Tests\PHPUnit90\Rector\MethodCall\AssertRegExpRector\Fixture;

final class SkipUsedByNextStmt extends \PHPUnit\Framework\TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertRegExpRector;
use Rector\PHPUnit\PHPUnit90\Rector\MethodCall\AssertRegExpRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(AssertRegExpRector::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -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);'
),
]
);
Expand Down Expand Up @@ -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');
}
}

Expand Down
Loading