-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for PHP 8.4 property hooks
- Loading branch information
Showing
3 changed files
with
75 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/test/php/lang/reflection/unittest/PropertyHooksTest.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php namespace lang\reflection\unittest; | ||
|
||
use ReflectionProperty; | ||
use lang\reflection\AccessingFailed; | ||
use test\verify\Condition; | ||
use test\{Assert, Expect, Test}; | ||
|
||
#[Condition(assert: 'method_exists(ReflectionProperty::class, "getHooks")')] | ||
class PropertyHooksTest { | ||
use TypeDefinition; | ||
|
||
#[Test] | ||
public function is_virtual() { | ||
$type= $this->declare('{ public string $fixture { get => "test"; } }'); | ||
Assert::true($type->properties()->named('fixture')->virtual()); | ||
} | ||
|
||
#[Test] | ||
public function get() { | ||
$type= $this->declare('{ public string $fixture { get => "test"; } }'); | ||
$instance= $type->newInstance(); | ||
|
||
Assert::equals('test', $type->properties()->named('fixture')->get($instance)); | ||
} | ||
|
||
#[Test] | ||
public function set() { | ||
$type= $this->declare('{ public string $fixture { set => ucfirst($value); } }'); | ||
$instance= $type->newInstance(); | ||
$type->properties()->named('fixture')->set($instance, 'test'); | ||
|
||
Assert::equals('Test', $instance->fixture); | ||
} | ||
|
||
#[Test] | ||
public function set_with_parameter() { | ||
$type= $this->declare('{ public string $fixture { set(string $arg) => ucfirst($arg); } }'); | ||
$instance= $type->newInstance(); | ||
$type->properties()->named('fixture')->set($instance, 'test'); | ||
|
||
Assert::equals('Test', $instance->fixture); | ||
} | ||
|
||
#[Test, Expect(AccessingFailed::class)] | ||
public function get_set_only_raises() { | ||
$type= $this->declare('{ public string $fixture { set => ucfirst($value); } }'); | ||
$instance= $type->newInstance(); | ||
|
||
$type->properties()->named('fixture')->get($instance); | ||
} | ||
|
||
#[Test, Expect(AccessingFailed::class)] | ||
public function set_get_only_raises() { | ||
$type= $this->declare('{ public string $fixture { get => "test"; } }'); | ||
$instance= $type->newInstance(); | ||
|
||
$type->properties()->named('fixture')->set($instance, 'test'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters