Skip to content

Commit e35f83c

Browse files
committed
refactor: added readonly lazy loading test
1 parent 3bcd008 commit e35f83c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Zend/tests/property_hooks/readonly_lazy.phpt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Hooks work on backed readonly properties
2+
Readonly hooks may be lazy loaded
33
--FILE--
44
<?php
55

@@ -45,16 +45,24 @@ $categoryId->setValue($product, '42');
4545
$category1 = $product->category;
4646
echo $category1->name . "\n";
4747

48-
// cached value
48+
// cached category returned
4949
$category2 = $product->category;
5050
echo $category2->name . "\n";
5151

52-
// Verify same instance is returned (backing field caching works)
52+
// same category instance returned
5353
var_dump($category1 === $category2);
5454

55+
// cannot set twice
56+
try {
57+
$categoryId->setValue($product, '420');
58+
} catch (Error $e) {
59+
echo $e->getMessage(), "\n";
60+
}
61+
5562
?>
5663
--EXPECT--
5764
hit database
5865
Category 42
5966
Category 42
6067
bool(true)
68+
Cannot modify readonly property LazyProduct::$categoryId

0 commit comments

Comments
 (0)