|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Zend property-hook placement rules for class/trait properties: no |
| 5 | + * hooks on static or readonly properties, abstract hooked properties |
| 6 | + * only in abstract containers with at least one bodiless hook, and a |
| 7 | + * mandatory body on every non-abstract hook. |
| 8 | + */ |
| 9 | +class PropertyHookPlacementTest extends BaseTest |
| 10 | +{ |
| 11 | + public function testHooksOnStaticPropertyAreRejected(): void |
| 12 | + { |
| 13 | + $this->exec('Cannot declare hooks for static property', 'hook_rule_static.php'); |
| 14 | + } |
| 15 | + |
| 16 | + public function testHooksOnReadonlyPropertyAreRejected(): void |
| 17 | + { |
| 18 | + $this->exec('Hooked properties cannot be readonly', 'hook_rule_readonly.php'); |
| 19 | + } |
| 20 | + |
| 21 | + public function testHooksInReadonlyClassAreRejected(): void |
| 22 | + { |
| 23 | + $this->exec('Hooked properties cannot be readonly', 'hook_rule_readonly_class.php'); |
| 24 | + } |
| 25 | + |
| 26 | + public function testAbstractHookedPropertyRequiresAbstractClass(): void |
| 27 | + { |
| 28 | + $this->exec('Non-abstract class `Box` contains abstract hooked property `$x`', 'hook_rule_abstract_nonabstract_class.php'); |
| 29 | + } |
| 30 | + |
| 31 | + public function testAbstractPropertyNeedsAtLeastOneAbstractHook(): void |
| 32 | + { |
| 33 | + $this->exec('Abstract property `Box::$x` must specify at least one abstract hook', 'hook_rule_abstract_all_bodies.php'); |
| 34 | + } |
| 35 | + |
| 36 | + public function testOnlyHookedPropertiesMayBeAbstract(): void |
| 37 | + { |
| 38 | + $this->exec('Only hooked properties may be declared abstract', 'hook_rule_abstract_no_hooks.php'); |
| 39 | + } |
| 40 | + |
| 41 | + public function testNonAbstractHookMustHaveBody(): void |
| 42 | + { |
| 43 | + $this->exec('Non-abstract property hook must have a body', 'hook_rule_bodyless.php'); |
| 44 | + } |
| 45 | + |
| 46 | + public function testWellFormedHooksStillCompile(): void |
| 47 | + { |
| 48 | + $this->compile('hook_rule_valid.php'); |
| 49 | + } |
| 50 | +} |
0 commit comments