Skip to content

Commit

Permalink
Do not catch an Exception in isset() of magic properties (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored Dec 16, 2023
1 parent 813da82 commit c78469c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/BaseActiveRecordTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function __isset(string $name): bool
{
try {
return $this->__get($name) !== null;
} catch (Throwable) {
} catch (InvalidCallException|UnknownPropertyException) {
return false;
}
}
Expand Down
17 changes: 15 additions & 2 deletions tests/ActiveRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Yiisoft\ActiveRecord\Tests;

use DivisionByZeroError;
use ReflectionException;
use Yiisoft\ActiveRecord\ActiveQuery;
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Animal;
Expand Down Expand Up @@ -392,7 +393,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
Expand All @@ -401,7 +403,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
Expand Down
4 changes: 4 additions & 0 deletions tests/Stubs/ActiveRecord/Cat.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ public function getThrowable(): float|int
{
return 5/0;
}

public function setNonExistingProperty(string $value): void
{
}
}

0 comments on commit c78469c

Please sign in to comment.