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_05_method_loading.php
More file actions
115 lines (93 loc) · 4.31 KB
/
Copy pathtest_05_method_loading.php
File metadata and controls
115 lines (93 loc) · 4.31 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
<?php
declare(strict_types=1);
namespace Osm\Core\Tests;
use Osm\Core\Attributes\Regression;
use Osm\Core\Object_;
use Osm\Core\Samples\App;
use Osm\Core\Samples\Attributes\Marker;
use Osm\Core\Samples\Attributes\Repeatable;
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_05_method_loading extends TestCase
{
public function test_method_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 method,
// AND it is automatically loaded
$sqr = $compiler->app->classes[Some::class]->methods['sqr'];
// THEN its information can be found in its properties
$this->assertTrue(isset($sqr->attributes[Repeatable::class]));
$this->assertEquals('method', $sqr->attributes[Repeatable::class][0]->name);
});
}
public function test_parent_class_method() {
// 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 method,that it is automatically copied
// from the parent class
$sqr = $compiler->app->classes[Other::class]->methods['sqr'];
// THEN its information can be found in its properties
$this->assertTrue(isset($sqr->attributes[Repeatable::class]));
$this->assertEquals('method', $sqr->attributes[Repeatable::class][0]->name);
});
}
public function test_trait_method() {
// 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 method, that is automatically copied
// from the trait
$get_pi = $compiler->app->classes[Some::class]->methods['get_pi'];
// THEN their information can be found in its properties
/* @var \ReflectionNamedType $type */
$type = $get_pi->reflection->getReturnType();
$this->assertEquals('float', $type->getName());
});
}
public function test_property_getter() {
// 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 has a getter method
$pi = $compiler->app->classes[Some::class]->properties['pi'];
// THEN method's information can be found via `getter`
// property
$type = $pi->getter->reflection->getReturnType();
$this->assertEquals('float', $type->getName());
});
}
public function test_around_advice() {
// 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 method, having around advices applied to it
$get_pi = $compiler->app->classes[Some::class]->methods['get_pi'];
// THEN their information can be found in its properties
$this->assertCount(1, $get_pi->around);
});
}
#[Regression]
public function test_object_around_advice() {
// GIVEN a compiler configured to compile a sample app
// AND `\Osm\Core\Samples\Some\Traits\ObjectTrait::around_default()`
// is applicable to every class derived from Object_
$compiler = Compiler::new(['app_class_name' => App::class]);
Apps::run($compiler, function(Compiler $compiler) {
foreach ($compiler->app->classes as $class) {
if (!is_a($class->name, Object_::class, true)) {
continue;
}
// WHEN you access a default() method in a class
$default = $class->methods['default'];
// THEN it should have exactly one advice
$this->assertCount(1, $default->around);
}
});
}
}