This repository was archived by the owner on May 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_04_property_loading.php
More file actions
121 lines (101 loc) · 5.1 KB
/
Copy pathtest_04_property_loading.php
File metadata and controls
121 lines (101 loc) · 5.1 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
declare(strict_types=1);
namespace Osm\Core\Tests;
use Osm\Core\Samples\App;
use Osm\Core\Samples\Attributes\Marker;
use Osm\Core\Samples\Attributes\Repeatable;
use Osm\Core\Samples\Some\Module;
use Osm\Core\Samples\Some\Other;
use Osm\Core\Samples\Some\Some;
use Osm\Runtime\Apps;
use Osm\Runtime\Compilation\Compiler;
use PHPUnit\Framework\TestCase;
class test_04_property_loading extends TestCase
{
public function test_doc_comment_property() {
// GIVEN a compiler configured to compile a sample app
$compiler = Compiler::new(['app_class_name' => App::class]);
Apps::run($compiler, function(Compiler $compiler) {
// WHEN you access a property,
// AND it is automatically loaded
$name = $compiler->app->classes[Some::class]->properties['name'];
// THEN its information can be found in its properties
$this->assertEquals('string', $name->type);
$this->assertNotTrue($name->array);
$this->assertFalse($name->nullable);
$this->assertTrue(isset($name->attributes[Marker::class]));
$this->assertEquals('marker', $name->attributes[Marker::class]->name);
$this->assertTrue($name->module_class_name == Module::class);
});
}
public function test_property_reflection() {
// GIVEN a compiler configured to compile a sample app
$compiler = Compiler::new(['app_class_name' => App::class]);
Apps::run($compiler, function(Compiler $compiler) {
// WHEN you access a property,
// AND it is automatically loaded
$children = $compiler->app->classes[Some::class]->properties['children'];
// THEN its information can be found in its properties
$this->assertEquals(Some::class, $children->type);
$this->assertTrue($children->array);
$this->assertFalse($children->nullable);
$this->assertTrue(isset($children->attributes[Marker::class]));
$this->assertEquals('owns', $children->attributes[Marker::class]->name);
$this->assertTrue($children->module_class_name == Module::class);
});
}
public function test_repeatable_attributes() {
// GIVEN a compiler configured to compile a sample app
$compiler = Compiler::new(['app_class_name' => App::class]);
Apps::run($compiler, function(Compiler $compiler) {
foreach (['type', 'note'] as $propertyName) {
// WHEN you access a property,
// AND it is automatically loaded
$property = $compiler->app->classes[Some::class]->properties[$propertyName];
// THEN its information can be found in its properties
$this->assertEquals('string', $property->type);
$this->assertNotTrue($property->array);
$this->assertFalse($property->nullable);
$this->assertTrue(isset($property->attributes[Repeatable::class]));
$this->assertTrue(is_array($property->attributes[Repeatable::class]));
$this->assertCount(2, $property->attributes[Repeatable::class]);
}
});
}
public function test_parent_class_property() {
// GIVEN a compiler configured to compile a sample app
$compiler = Compiler::new(['app_class_name' => App::class]);
Apps::run($compiler, function(Compiler $compiler) {
// WHEN you access a property, that is automatically copied
// from the parent class
$name = $compiler->app->classes[Other::class]->properties['name'];
// AND you access a property, that is automatically merged
// with the parent class
$children = $compiler->app->classes[Other::class]->properties['children'];
// THEN their information can be found in its properties
$this->assertEquals('string', $name->type);
$this->assertNotTrue($name->array);
$this->assertFalse($name->nullable);
$this->assertTrue(isset($name->attributes[Marker::class]));
$this->assertEquals('marker', $name->attributes[Marker::class]->name);
$this->assertEquals(Some::class, $children->type);
$this->assertTrue($children->array);
$this->assertFalse($children->nullable);
$this->assertTrue(isset($children->attributes[Marker::class]));
$this->assertEquals('owns', $children->attributes[Marker::class]->name);
});
}
public function test_trait_property() {
// GIVEN a compiler configured to compile a sample app
$compiler = Compiler::new(['app_class_name' => App::class]);
Apps::run($compiler, function(Compiler $compiler) {
// WHEN you access a property, that is automatically copied
// from the trait
$pi = $compiler->app->classes[Some::class]->properties['pi'];
// THEN their information can be found in its properties
$this->assertEquals('float', $pi->type);
$this->assertNotTrue($pi->array);
$this->assertFalse($pi->nullable);
});
}
}