-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVirtualPropertiesTest.class.php
More file actions
executable file
·70 lines (56 loc) · 2.06 KB
/
VirtualPropertiesTest.class.php
File metadata and controls
executable file
·70 lines (56 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php namespace lang\reflection\unittest;
use lang\Reflection;
use lang\reflection\{AccessingFailed, Modifiers};
use test\{Assert, Expect, Test, Values};
class VirtualPropertiesTest {
use TypeDefinition;
/** @return iterable */
private function fixtures() {
yield [Reflection::of(VirtualProperty::class)];
$t= $this->declare('{ use WithReadonly; }');
\xp::$meta[$t->name()][0]['fixture']= [
DETAIL_RETURNS => 'string',
DETAIL_ARGUMENTS => [Modifiers::IS_PUBLIC | Modifiers::IS_READONLY]
];
yield $t;
}
#[Test, Values(from: 'fixtures')]
public function readonly_modifier_shown_in_string_representation($type) {
Assert::equals('public readonly string $fixture', $type->property('fixture')->toString());
}
#[Test, Values(from: 'fixtures')]
public function virtual_property_included_in_list($type) {
Assert::equals(
['fixture' => 'public readonly'],
array_map(fn($p) => $p->modifiers()->names(), iterator_to_array($type->properties()))
);
}
#[Test, Values(from: 'fixtures')]
public function is_virtual($type) {
Assert::true($type->properties()->named('fixture')->virtual());
}
#[Test, Values(from: 'fixtures')]
public function named_virtual($type) {
Assert::equals($type->property('fixture'), $type->properties()->named('fixture'));
}
#[Test, Values(from: 'fixtures')]
public function initializing_readonly_allowed($type) {
$property= $type->property('fixture');
$instance= $type->newInstance();
$property->set($instance, 'Test');
}
#[Test, Values(from: 'fixtures')]
public function reading_readonly($type) {
$property= $type->property('fixture');
$instance= $type->newInstance();
$property->set($instance, 'Test');
Assert::equals('Test', $property->get($instance));
}
#[Test, Expect(AccessingFailed::class), Values(from: 'fixtures')]
public function overwriting_readonly_not_allowed($type) {
$property= $type->property('fixture');
$instance= $type->newInstance();
$property->set($instance, 'Test');
$property->set($instance, 'Modified');
}
}