Skip to content

Commit

Permalink
[PHPUnit 10] Skip with Magic __get() on AssertIssetToAssertObjectHasP…
Browse files Browse the repository at this point in the history
…ropertyRector (#403)

* [PHPUnit 10] Skip with Magic __get() on AssertIssetToAssertObjectHasPropertyRector

* fixture

* Fix
  • Loading branch information
samsonasik authored Nov 8, 2024
1 parent f9a8848 commit 38bdce4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit100\Rector\MethodCall\AssertIssetToAssertObjectHasPropertyRector\Fixture;

use ArrayAccess;
use PHPUnit\Framework\TestCase;
use Rector\PHPUnit\Tests\PHPUnit100\Rector\MethodCall\AssertIssetToAssertObjectHasPropertyRector\Source\WithMagicGet;

final class SkipWithMagicGet extends TestCase
{
public function test()
{
$object = new WithMagicGet();
$this->assertTrue(isset($object->one));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit100\Rector\MethodCall\AssertIssetToAssertObjectHasPropertyRector\Source;

use ArrayAccess;

class WithMagicGet implements ArrayAccess {
public $container = [
"one" => 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ private function hasMagicIsset(Expr $expr): bool
return true;
}

if ($classReflection->hasMethod('__get')) {
return true;
}

if (! $classReflection->isClass()) {
return false;
}
Expand Down

0 comments on commit 38bdce4

Please sign in to comment.