| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- /**
- * Test: Nette\SmartObject properties.
- */
- declare(strict_types=1);
- use Tester\Assert;
- require __DIR__ . '/../bootstrap.php';
- class TestClass
- {
- use Nette\SmartObject;
- public $foo;
- }
- test('', function () {
- $obj = new TestClass;
- unset($obj->foo);
- Assert::false(isset($obj->foo));
- // re-set
- $obj->foo = 'hello';
- Assert::same('hello', $obj->foo);
- });
- test('double unset', function () {
- $obj = new TestClass;
- unset($obj->foo, $obj->foo);
- });
- test('reading of unset property', function () {
- Assert::exception(function () {
- $obj = new TestClass;
- unset($obj->foo);
- $val = $obj->foo;
- }, Nette\MemberAccessException::class, 'Cannot read an undeclared property TestClass::$foo.');
- });
|