Skip to content

Commit

Permalink
Throw UnknownPropertyException when setting unknown property (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored Dec 16, 2023
1 parent cdcca08 commit 813da82
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/BaseActiveRecordTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ public function __set(string $name, mixed $value): void
if (method_exists($this, 'get' . ucfirst($name))) {
throw new InvalidCallException('Setting read-only property: ' . static::class . '::' . $name);

Check warning on line 207 in src/BaseActiveRecordTrait.php

View workflow job for this annotation

GitHub Actions / PHP 8-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ return; } if (method_exists($this, 'get' . ucfirst($name))) { - throw new InvalidCallException('Setting read-only property: ' . static::class . '::' . $name); + throw new InvalidCallException('Setting read-only property: ' . static::class . '::'); } throw new UnknownPropertyException('Setting unknown property: ' . static::class . '::' . $name); }
}

throw new UnknownPropertyException('Setting unknown property: ' . static::class . '::' . $name);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/ActiveRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Yiisoft\Db\Exception\InvalidArgumentException;
use Yiisoft\Db\Exception\InvalidCallException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\UnknownPropertyException;
use Yiisoft\Db\Query\Query;

abstract class ActiveRecordTest extends TestCase
Expand Down Expand Up @@ -596,6 +597,10 @@ public function testAttributeAccess(): void
$this->assertSame([], $customer->orderItems);
$this->assertFalse($customer->canGetProperty('non_existing_property'));
$this->assertFalse($customer->canSetProperty('non_existing_property'));

$this->expectException(UnknownPropertyException::class);
$this->expectExceptionMessage('Setting unknown property: ' . Customer::class . '::non_existing_property');
$customer->non_existing_property = null;
}

public function testHasAttribute(): void
Expand Down

0 comments on commit 813da82

Please sign in to comment.