66use PHPUnit \Framework \TestCase ;
77use WPHooks \Hook ;
88use WPHooks \Hooks ;
9+ use WPHooks \Tag ;
910
1011final class HooksTest extends TestCase {
1112 /**
@@ -30,26 +31,66 @@ public function testErrorThrownWhenFileDoesNotExist(): void {
3031 }
3132
3233 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 ' );
3737
3838 self ::assertTrue ( $ includes );
3939 self ::assertInstanceOf ( Hook::class, $ hook );
4040 self ::assertSame ( 'wp_tag_cloud ' , $ hook ->getName () );
4141 }
4242
4343 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 ' );
4847
4948 self ::assertFalse ( $ includes );
5049 self ::assertNull ( $ hook );
5150 }
5251
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+
5394 /**
5495 * @return array<string, array<int, string>>
5596 * @phpstan-return array{
@@ -93,4 +134,12 @@ public function dataCoreFiles(): array {
93134 ],
94135 ];
95136 }
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+ }
96145}
0 commit comments