From 7b389927a329e2be4502a7bdd0ec711d7a802fff Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 10 Nov 2024 11:59:43 +0700 Subject: [PATCH] [PHPUnit 10] Remove AssertIssetToAssertObjectHasPropertyRector --- config/sets/phpunit100.php | 2 - ...setToAssertObjectHasPropertyRectorTest.php | 28 ---- .../Fixture/skip_magic_isset.php.inc | 19 --- .../Fixture/skip_with_magic_get.php.inc | 16 -- .../Fixture/some_isset_to_property.php.inc | 33 ---- .../Source/WithMagicGet.php | 38 ----- .../config/configured_rule.php | 9 - ...rtIssetToAssertObjectHasPropertyRector.php | 157 ------------------ 8 files changed, 302 deletions(-) delete mode 100644 rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/AssertIssetToAssertObjectHasPropertyRectorTest.php delete mode 100644 rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Fixture/skip_magic_isset.php.inc delete mode 100644 rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Fixture/skip_with_magic_get.php.inc delete mode 100644 rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Fixture/some_isset_to_property.php.inc delete mode 100644 rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Source/WithMagicGet.php delete mode 100644 rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/config/configured_rule.php delete mode 100644 rules/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector.php diff --git a/config/sets/phpunit100.php b/config/sets/phpunit100.php index f805a695..9a06e0ca 100644 --- a/config/sets/phpunit100.php +++ b/config/sets/phpunit100.php @@ -6,7 +6,6 @@ use Rector\PHPUnit\PHPUnit100\Rector\Class_\AddProphecyTraitRector; use Rector\PHPUnit\PHPUnit100\Rector\Class_\PublicDataProviderClassMethodRector; use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector; -use Rector\PHPUnit\PHPUnit100\Rector\MethodCall\AssertIssetToAssertObjectHasPropertyRector; use Rector\PHPUnit\PHPUnit100\Rector\MethodCall\RemoveSetMethodsMethodCallRector; use Rector\PHPUnit\PHPUnit100\Rector\StmtsAwareInterface\WithConsecutiveRector; use Rector\PHPUnit\Set\PHPUnitSetList; @@ -17,7 +16,6 @@ $rectorConfig->sets([PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES]); $rectorConfig->rules([ - AssertIssetToAssertObjectHasPropertyRector::class, StaticDataProviderClassMethodRector::class, PublicDataProviderClassMethodRector::class, AddProphecyTraitRector::class, diff --git a/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/AssertIssetToAssertObjectHasPropertyRectorTest.php b/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/AssertIssetToAssertObjectHasPropertyRectorTest.php deleted file mode 100644 index c86b9d73..00000000 --- a/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/AssertIssetToAssertObjectHasPropertyRectorTest.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/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Fixture/skip_magic_isset.php.inc b/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Fixture/skip_magic_isset.php.inc deleted file mode 100644 index 14b0f1a3..00000000 --- a/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Fixture/skip_magic_isset.php.inc +++ /dev/null @@ -1,19 +0,0 @@ -assertTrue(isset($foo->bar)); - } -} diff --git a/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Fixture/skip_with_magic_get.php.inc b/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Fixture/skip_with_magic_get.php.inc deleted file mode 100644 index 24ede6c1..00000000 --- a/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Fixture/skip_with_magic_get.php.inc +++ /dev/null @@ -1,16 +0,0 @@ -assertTrue(isset($object->one)); - } -} diff --git a/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Fixture/some_isset_to_property.php.inc b/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Fixture/some_isset_to_property.php.inc deleted file mode 100644 index 079ce475..00000000 --- a/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Fixture/some_isset_to_property.php.inc +++ /dev/null @@ -1,33 +0,0 @@ -assertTrue(isset($object->someProperty)); - } -} - -?> ------ -assertObjectHasProperty('someProperty', $object); - } -} - -?> diff --git a/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Source/WithMagicGet.php b/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Source/WithMagicGet.php deleted file mode 100644 index dbf65bf5..00000000 --- a/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/Source/WithMagicGet.php +++ /dev/null @@ -1,38 +0,0 @@ - 1, - "two" => 2, - "three" => 3, - ]; - - public function offsetSet($offset, $value): void { - if (is_null($offset)) { - $this->container[] = $value; - } else { - $this->container[$offset] = $value; - } - } - - public function offsetExists($offset): bool { - return isset($this->container[$offset]); - } - - public function offsetUnset($offset): void { - unset($this->container[$offset]); - } - - public function offsetGet($offset): mixed { - return isset($this->container[$offset]) ? $this->container[$offset] : null; - } - - public function __get(string $name): mixed - { - return $this->offsetGet($name); - } -} diff --git a/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/config/configured_rule.php b/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/config/configured_rule.php deleted file mode 100644 index dae2a100..00000000 --- a/rules-tests/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector/config/configured_rule.php +++ /dev/null @@ -1,9 +0,0 @@ -withRules([AssertIssetToAssertObjectHasPropertyRector::class]); diff --git a/rules/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector.php b/rules/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector.php deleted file mode 100644 index f6ba7356..00000000 --- a/rules/PHPUnit100/Rector/MethodCall/AssertIssetToAssertObjectHasPropertyRector.php +++ /dev/null @@ -1,157 +0,0 @@ -assertTrue(isset($object->someProperty)); - } -} -CODE_SAMPLE - - , - <<<'CODE_SAMPLE' -use PHPUnit\Framework\TestCase; - -final class SomeTest extends TestCase -{ - public function test() - { - $object = new stdClass(); - $this->assertObjectHasProperty('someProperty', $object); - } -} -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, - [AssertMethod::ASSERT_TRUE, AssertMethod::ASSERT_FALSE] - )) { - return null; - } - - if ($node->isFirstClassCallable()) { - return null; - } - - $firstArg = $node->getArgs()[0]; - $firstArgValue = $firstArg->value; - if (! $firstArgValue instanceof Isset_) { - return null; - } - - $issetExpr = $firstArgValue->vars[0]; - if (! $issetExpr instanceof PropertyFetch) { - return null; - } - - if ($this->hasMagicIsset($issetExpr->var)) { - return null; - } - - $name = $this->getName($issetExpr); - if ($name === null) { - return null; - } - - $this->identifierManipulator->renameNodeWithMap($node, [ - AssertMethod::ASSERT_TRUE => 'assertObjectHasProperty', - AssertMethod::ASSERT_FALSE => 'assertObjectNotHasProperty', - ]); - - $oldArgs = $node->getArgs(); - unset($oldArgs[0]); - - $newArgs = $this->nodeFactory->createArgs([new String_($name), $issetExpr->var]); - $node->args = [...$newArgs, ...$oldArgs]; - return $node; - } - - private function hasMagicIsset(Expr $expr): bool - { - $type = $this->nodeTypeResolver->getType($expr); - if (! $type instanceof TypeWithClassName) { - // object not found, skip - return $type instanceof ObjectWithoutClassType; - } - - $classReflection = $type->getClassReflection(); - if (! $classReflection instanceof ClassReflection) { - return false; - } - - if ($classReflection->hasMethod('__isset')) { - return true; - } - - if ($classReflection->hasMethod('__get')) { - return true; - } - - if (! $classReflection->isClass()) { - return false; - } - - return $this->classReflectionAnalyzer->resolveParentClassName($classReflection) !== null; - } -}