diff --git a/config/sets/phpunit-code-quality.php b/config/sets/phpunit-code-quality.php index 9d9dec95..ccc90e79 100644 --- a/config/sets/phpunit-code-quality.php +++ b/config/sets/phpunit-code-quality.php @@ -31,7 +31,6 @@ use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertSameTrueFalseToAssertTrueFalseRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertTrueFalseToSpecificMethodRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\FlipAssertRector; -use Rector\PHPUnit\CodeQuality\Rector\MethodCall\MatchAssertEqualsExpectedTypeRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\NarrowIdenticalWithConsecutiveRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\NarrowSingleWillReturnCallbackRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\RemoveExpectAnyFromMockRector; @@ -46,7 +45,6 @@ ConstructClassMethodToSetUpTestCaseRector::class, AssertSameTrueFalseToAssertTrueFalseRector::class, - MatchAssertEqualsExpectedTypeRector::class, AssertEqualsToSameRector::class, PreferPHPUnitThisCallRector::class, diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_assert_type.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_assert_type.php.inc deleted file mode 100644 index 0ad61056..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_assert_type.php.inc +++ /dev/null @@ -1,41 +0,0 @@ -assertEquals('123', $this->getOrderId()); - } - - private function getOrderId(): int - { - return 123; - } -} - -?> ------ -assertEquals(123, $this->getOrderId()); - } - - private function getOrderId(): int - { - return 123; - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_integer_to_string.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_integer_to_string.php.inc deleted file mode 100644 index 7ffa0666..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_integer_to_string.php.inc +++ /dev/null @@ -1,41 +0,0 @@ -assertEquals(123, $this->getOrderId()); - } - - private function getOrderId(): string - { - return '123'; - } -} - -?> ------ -assertEquals('123', $this->getOrderId()); - } - - private function getOrderId(): string - { - return '123'; - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/nullable_match_assert_type.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/nullable_match_assert_type.php.inc deleted file mode 100644 index 3a4718d1..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/nullable_match_assert_type.php.inc +++ /dev/null @@ -1,41 +0,0 @@ -assertEquals('123', $this->getOrderId()); - } - - private function getOrderId(): ?int - { - return 123; - } -} - -?> ------ -assertEquals(123, $this->getOrderId()); - } - - private function getOrderId(): ?int - { - return 123; - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_argument_less.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_argument_less.php.inc deleted file mode 100644 index a468892d..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_argument_less.php.inc +++ /dev/null @@ -1,13 +0,0 @@ -assertSame(1); - } -} diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_docblock_type.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_docblock_type.php.inc deleted file mode 100644 index 24b7a7eb..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_docblock_type.php.inc +++ /dev/null @@ -1,21 +0,0 @@ -assertSame('123', $this->getOrderId()); - } - - /** - * @return int - */ - private function getOrderId() - { - return '123'; - } -} diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_first_class_callable.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_first_class_callable.php.inc deleted file mode 100644 index e623f13e..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_first_class_callable.php.inc +++ /dev/null @@ -1,13 +0,0 @@ -assertSame(...); - } -} diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/MatchAssertEqualsExpectedTypeRectorTest.php b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/MatchAssertEqualsExpectedTypeRectorTest.php deleted file mode 100644 index 6ab2c505..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/MatchAssertEqualsExpectedTypeRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/config/configured_rule.php b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/config/configured_rule.php deleted file mode 100644 index fa18b840..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/config/configured_rule.php +++ /dev/null @@ -1,10 +0,0 @@ -rule(MatchAssertEqualsExpectedTypeRector::class); -}; diff --git a/rules/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector.php b/rules/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector.php deleted file mode 100644 index 2807ee3f..00000000 --- a/rules/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector.php +++ /dev/null @@ -1,126 +0,0 @@ -assertEquals('123', $this->getOrderId()); - } - - private function getOrderId(): int - { - return 123; - } -} -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -use PHPUnit\Framework\TestCase; - -class SomeTest extends TestCase -{ - public function run() - { - $this->assertEquals(123, $this->getOrderId()); - } - - private function getOrderId(): int - { - return 123; - } -} -CODE_SAMPLE - ), - ] - ); - } - - /** - * @return array> - */ - public function getNodeTypes(): array - { - return [MethodCall::class, StaticCall::class]; - } - - /** - * @param MethodCall|StaticCall $node - */ - public function refactor(Node $node): ?Node - { - if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, ['assertEquals'])) { - return null; - } - - if ($node->isFirstClassCallable()) { - return null; - } - - if (count($node->getArgs()) < 2) { - return null; - } - - $expectedArg = $node->getArgs()[0]; - if (! $expectedArg->value instanceof String_ && ! $expectedArg->value instanceof Int_) { - return null; - } - - $expectedType = $this->getType($expectedArg->value); - - $variableExpr = $node->getArgs()[1] - ->value; - $variableType = $this->nodeTypeResolver->getNativeType($variableExpr); - - $directVariableType = TypeCombinator::removeNull($variableType); - - if ($expectedType->isLiteralString()->yes() && $directVariableType->isInteger()->yes()) { - // update expected type to provided type - $expectedArg->value = new Int_((int) $expectedArg->value->value); - - return $node; - } - - if ($expectedType->isInteger()->yes() && $directVariableType->isString()->yes()) { - // update expected type to provided type - $expectedArg->value = new String_((string) $expectedArg->value->value); - - return $node; - } - - return null; - } -}