diff --git a/src/BaseActiveRecordTrait.php b/src/BaseActiveRecordTrait.php index c5061b1ac..f37b437f3 100644 --- a/src/BaseActiveRecordTrait.php +++ b/src/BaseActiveRecordTrait.php @@ -156,7 +156,7 @@ public function __isset(string $name): bool { try { return $this->__get($name) !== null; - } catch (Throwable) { + } catch (InvalidCallException|UnknownPropertyException) { return false; } } diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php index 4d054d29e..0a45abf33 100644 --- a/tests/ActiveRecordTest.php +++ b/tests/ActiveRecordTest.php @@ -4,6 +4,7 @@ namespace Yiisoft\ActiveRecord\Tests; +use DivisionByZeroError; use ReflectionException; use Yiisoft\ActiveRecord\ActiveQuery; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Animal; @@ -390,7 +391,8 @@ public function testIssetException(): void $cat = new Cat($this->db); - $this->assertFalse(isset($cat->exception)); + $this->expectException(Exception::class); + isset($cat->exception); } public function testIssetThrowable(): void @@ -399,7 +401,18 @@ public function testIssetThrowable(): void $cat = new Cat($this->db); - $this->assertFalse(isset($cat->throwable)); + $this->expectException(DivisionByZeroError::class); + isset($cat->throwable); + } + + public function testIssetNonExisting(): void + { + $this->checkFixture($this->db, 'cat'); + + $cat = new Cat($this->db); + + $this->assertFalse(isset($cat->non_existing)); + $this->assertFalse(isset($cat->non_existing_property)); } public function testSetAttributes(): void diff --git a/tests/Stubs/ActiveRecord/Cat.php b/tests/Stubs/ActiveRecord/Cat.php index 5a722ee74..dc9a402d3 100644 --- a/tests/Stubs/ActiveRecord/Cat.php +++ b/tests/Stubs/ActiveRecord/Cat.php @@ -29,4 +29,8 @@ public function getThrowable(): float|int { return 5/0; } + + public function setNonExistingProperty(string $value): void + { + } }