6
6
use PHPUnit \Framework \TestCase ;
7
7
use WPHooks \Hook ;
8
8
use WPHooks \Hooks ;
9
+ use WPHooks \Tag ;
9
10
10
11
final class HooksTest extends TestCase {
11
12
/**
@@ -30,26 +31,66 @@ public function testErrorThrownWhenFileDoesNotExist(): void {
30
31
}
31
32
32
33
public function testCanFindByName (): void {
33
- $ file = $ this ->dataCoreFiles ()['filters ' ][0 ];
34
- $ filters = Hooks::fromFile ( $ file );
35
- $ hook = $ filters ->find ( 'wp_tag_cloud ' );
36
- $ includes = $ filters ->includes ( 'wp_tag_cloud ' );
34
+ $ hooks = $ this ->getFilters ();
35
+ $ hook = $ hooks ->find ( 'wp_tag_cloud ' );
36
+ $ includes = $ hooks ->includes ( 'wp_tag_cloud ' );
37
37
38
38
self ::assertTrue ( $ includes );
39
39
self ::assertInstanceOf ( Hook::class, $ hook );
40
40
self ::assertSame ( 'wp_tag_cloud ' , $ hook ->getName () );
41
41
}
42
42
43
43
public function testFindByUnknownNameReturnsNull (): void {
44
- $ file = $ this ->dataCoreFiles ()['filters ' ][0 ];
45
- $ filters = Hooks::fromFile ( $ file );
46
- $ hook = $ filters ->find ( 'this_does_not_exist ' );
47
- $ includes = $ filters ->includes ( 'this_does_not_exist ' );
44
+ $ hooks = $ this ->getFilters ();
45
+ $ hook = $ hooks ->find ( 'this_does_not_exist ' );
46
+ $ includes = $ hooks ->includes ( 'this_does_not_exist ' );
48
47
49
48
self ::assertFalse ( $ includes );
50
49
self ::assertNull ( $ hook );
51
50
}
52
51
52
+ public function testCanGetReturnTypes (): void {
53
+ $ hooks = $ this ->getFilters ();
54
+ $ hook = $ hooks ->find ( 'wp_tag_cloud ' );
55
+
56
+ $ returnTypes = $ hook ->getDoc ()->getReturnTypes ();
57
+ $ expected = [
58
+ 'string ' ,
59
+ 'string[] ' ,
60
+ ];
61
+
62
+ self ::assertSame ( $ expected , $ returnTypes );
63
+ }
64
+
65
+ public function testCanGetReturnTypeString (): void {
66
+ $ hooks = $ this ->getFilters ();
67
+ $ hook = $ hooks ->find ( 'wp_tag_cloud ' );
68
+
69
+ $ returnType = $ hook ->getDoc ()->getReturnTypeString ();
70
+
71
+ self ::assertSame ( 'string|string[] ' , $ returnType );
72
+ }
73
+
74
+ public function testCanGetParams (): void {
75
+ $ hooks = $ this ->getFilters ();
76
+ $ hook = $ hooks ->find ( 'wp_tag_cloud ' );
77
+
78
+ $ params = $ hook ->getDoc ()->getParams ();
79
+
80
+ self ::assertCount ( 2 , $ params );
81
+ self ::assertInstanceOf ( Tag::class, $ params [0 ] );
82
+ self ::assertInstanceOf ( Tag::class, $ params [1 ] );
83
+ }
84
+
85
+ public function testCanCountParams (): void {
86
+ $ hooks = $ this ->getFilters ();
87
+ $ hook = $ hooks ->find ( 'wp_tag_cloud ' );
88
+
89
+ $ count = $ hook ->getDoc ()->countParams ();
90
+
91
+ self ::assertSame ( 2 , $ count );
92
+ }
93
+
53
94
/**
54
95
* @return array<string, array<int, string>>
55
96
* @phpstan-return array{
@@ -93,4 +134,12 @@ public function dataCoreFiles(): array {
93
134
],
94
135
];
95
136
}
137
+
138
+ private function getFilters (): Hooks {
139
+ return Hooks::fromFile ( $ this ->dataCoreFiles ()['filters ' ][0 ] );
140
+ }
141
+
142
+ private function getActions (): Hooks {
143
+ return Hooks::fromFile ( $ this ->dataCoreFiles ()['actions ' ][0 ] );
144
+ }
96
145
}
0 commit comments