diff --git a/composer.json b/composer.json index 4d97909f..5132248e 100644 --- a/composer.json +++ b/composer.json @@ -74,6 +74,8 @@ "cs:fix": "php-cs-fixer fix -v", "psalm": "psalm", "psalm:baseline": "psalm --set-baseline=psalm-baseline.xml", - "test": "phpunit --color=always" + "test": "phpunit --color=always", + "test:unit": "phpunit --exclude-group driver --colors=always", + "test:sqlite": "phpunit --group driver-sqlite --colors=always" } } diff --git a/src/Mapper/Proxy/EntityProxyTrait.php b/src/Mapper/Proxy/EntityProxyTrait.php index 31f8e44d..095707f0 100644 --- a/src/Mapper/Proxy/EntityProxyTrait.php +++ b/src/Mapper/Proxy/EntityProxyTrait.php @@ -57,9 +57,15 @@ public function __unset(string $name): void public function __set(string $name, $value): void { if (!\array_key_exists($name, $this->__cycle_orm_rel_map->getRelations())) { - if (\method_exists(parent::class, '__set')) { - parent::__set($name, $value); + if (!\method_exists(parent::class, '__set')) { + throw new \Error(\sprintf( + 'Cannot access non-public property %s::$%s', + \get_parent_class(static::class), + $name, + )); } + + parent::__set($name, $value); return; } diff --git a/tests/ORM/Functional/Driver/Common/Integration/Case6/CaseTest.php b/tests/ORM/Functional/Driver/Common/Integration/Case6/CaseTest.php new file mode 100644 index 00000000..951643fe --- /dev/null +++ b/tests/ORM/Functional/Driver/Common/Integration/Case6/CaseTest.php @@ -0,0 +1,52 @@ +makeTable('users', [ + 'id' => 'int,primary', + 'login' => 'string', + ]); + + $this->loadSchema(__DIR__ . '/schema.php'); + + $this->getDatabase()->table('users')->insertMultiple( + ['id', 'login'], + [ + [1, 'foo'], + ], + ); + } + + public function testSelect(): void + { + /** @var User $model */ + $model = (new Select($this->orm,User::class)) + ->wherePK(1) + ->fetchOne(); + + $this->assertSame('foo', $model->getLogin()); + $this->expectException(\Error::class); + $this->expectExceptionMessage('Cannot access non-public property ' . User::class . '::$login'); + + $model->login = 'new login'; + } +} diff --git a/tests/ORM/Functional/Driver/Common/Integration/Case6/Entity/User.php b/tests/ORM/Functional/Driver/Common/Integration/Case6/Entity/User.php new file mode 100644 index 00000000..44095601 --- /dev/null +++ b/tests/ORM/Functional/Driver/Common/Integration/Case6/Entity/User.php @@ -0,0 +1,26 @@ +login = $login; + } + + public function getId(): ?string + { + return $this->id === null ? null : (string)$this->id; + } + + public function getLogin(): string + { + return $this->login; + } +} diff --git a/tests/ORM/Functional/Driver/Common/Integration/Case6/schema.php b/tests/ORM/Functional/Driver/Common/Integration/Case6/schema.php new file mode 100644 index 00000000..cc0dd8c8 --- /dev/null +++ b/tests/ORM/Functional/Driver/Common/Integration/Case6/schema.php @@ -0,0 +1,31 @@ + [ + Schema::ENTITY => User::class, + Schema::MAPPER => Mapper::class, + Schema::SOURCE => Source::class, + Schema::REPOSITORY => Repository::class, + Schema::DATABASE => 'default', + Schema::TABLE => 'users', + Schema::PRIMARY_KEY => ['id'], + Schema::FIND_BY_KEYS => ['id'], + Schema::COLUMNS => [ + 'id' => 'id', + 'login' => 'login', + ], + Schema::RELATIONS => [], + Schema::TYPECAST => [ + 'id' => 'int', + 'login' => 'string', + ], + ], +]; diff --git a/tests/ORM/Functional/Driver/MySQL/Integration/Case6/CaseTest.php b/tests/ORM/Functional/Driver/MySQL/Integration/Case6/CaseTest.php new file mode 100644 index 00000000..f96d12bc --- /dev/null +++ b/tests/ORM/Functional/Driver/MySQL/Integration/Case6/CaseTest.php @@ -0,0 +1,17 @@ +