@@ -20,11 +20,38 @@ class FindImplementedInterfaceNamesTest extends AbstractMethodUnitTest
2020{
2121
2222
23+ /**
24+ * Test getting a `false` result when a non-existent token is passed.
25+ *
26+ * @return void
27+ */
28+ public function testNonExistentToken ()
29+ {
30+ $ result = self ::$ phpcsFile ->findImplementedInterfaceNames (100000 );
31+ $ this ->assertFalse ($ result );
32+
33+ }//end testNonExistentToken()
34+
35+
36+ /**
37+ * Test getting a `false` result when a token other than one of the supported tokens is passed.
38+ *
39+ * @return void
40+ */
41+ public function testNotAClass ()
42+ {
43+ $ token = $ this ->getTargetToken ('/* testNotAClass */ ' , [T_FUNCTION ]);
44+ $ result = self ::$ phpcsFile ->findImplementedInterfaceNames ($ token );
45+ $ this ->assertFalse ($ result );
46+
47+ }//end testNotAClass()
48+
49+
2350 /**
2451 * Test retrieving the name(s) of the interfaces being implemented by a class.
2552 *
26- * @param string $identifier Comment which precedes the test case.
27- * @param bool $expected Expected function output.
53+ * @param string $identifier Comment which precedes the test case.
54+ * @param array<string>|false $expected Expected function output.
2855 *
2956 * @dataProvider dataImplementedInterface
3057 *
@@ -44,63 +71,79 @@ public function testFindImplementedInterfaceNames($identifier, $expected)
4471 *
4572 * @see testFindImplementedInterfaceNames()
4673 *
47- * @return array
74+ * @return array<string, array<string, string|array<string>>>
4875 */
4976 public function dataImplementedInterface ()
5077 {
5178 return [
52- [
53- '/* testImplementedClass */ ' ,
54- ['testFIINInterface ' ],
79+ 'interface declaration, no implements ' => [
80+ 'identifier ' => '/* testPlainInterface */ ' ,
81+ 'expected ' => false ,
82+ ],
83+ 'class does not implement ' => [
84+ 'identifier ' => '/* testNonImplementedClass */ ' ,
85+ 'expected ' => false ,
5586 ],
56- [
57- '/* testMultiImplementedClass */ ' ,
58- [
87+ 'class implements single interface, unqualified ' => [
88+ 'identifier ' => '/* testClassImplementsSingle */ ' ,
89+ 'expected ' => ['testFIINInterface ' ],
90+ ],
91+ 'class implements multiple interfaces ' => [
92+ 'identifier ' => '/* testClassImplementsMultiple */ ' ,
93+ 'expected ' => [
5994 'testFIINInterface ' ,
6095 'testFIINInterface2 ' ,
6196 ],
6297 ],
63- [
64- '/* testNamespacedClass */ ' ,
65- ['\PHP_CodeSniffer\Tests\Core\File\testFIINInterface ' ],
66- ],
67- [
68- '/* testNonImplementedClass */ ' ,
69- false ,
98+ 'class implements single interface, fully qualified ' => [
99+ 'identifier ' => '/* testImplementsFullyQualified */ ' ,
100+ 'expected ' => ['\PHP_CodeSniffer\Tests\Core\File\testFIINInterface ' ],
70101 ],
71- [
72- '/* testInterface */ ' ,
73- false ,
102+ ' class implements single interface, partially qualified ' => [
103+ 'identifier ' => ' /* testImplementsPartiallyQualified */ ' ,
104+ ' expected ' => [ ' Core\File\RelativeInterface ' ] ,
74105 ],
75- [
76- '/* testClassThatExtendsAndImplements */ ' ,
77- [
106+ ' class extends and implements ' => [
107+ 'identifier ' => ' /* testClassThatExtendsAndImplements */ ' ,
108+ ' expected ' => [
78109 'InterfaceA ' ,
79110 '\NameSpaced\Cat\InterfaceB ' ,
80111 ],
81112 ],
82- [
83- '/* testClassThatImplementsAndExtends */ ' ,
84- [
113+ ' class implements and extends ' => [
114+ 'identifier ' => ' /* testClassThatImplementsAndExtends */ ' ,
115+ ' expected ' => [
85116 '\InterfaceA ' ,
86117 'InterfaceB ' ,
87118 ],
88119 ],
89- [
90- '/* testBackedEnumWithoutImplements */ ' ,
91- false ,
120+ ' enum does not implement ' => [
121+ 'identifier ' => ' /* testBackedEnumWithoutImplements */ ' ,
122+ ' expected ' => false ,
92123 ],
93- [
94- '/* testEnumImplements */ ' ,
95- ['Colorful ' ],
124+ ' enum implements single interface, unqualified ' => [
125+ 'identifier ' => ' /* testEnumImplementsSingle */ ' ,
126+ ' expected ' => ['Colorful ' ],
96127 ],
97- [
98- '/* testBackedEnumImplements */ ' ,
99- [
128+ ' enum implements multiple interfaces, unqualified + fully qualified ' => [
129+ 'identifier ' => ' /* testBackedEnumImplementsMulti */ ' ,
130+ ' expected ' => [
100131 'Colorful ' ,
101132 '\Deck ' ,
102133 ],
103134 ],
135+ 'anon class implements single interface, unqualified ' => [
136+ 'identifier ' => '/* testAnonClassImplementsSingle */ ' ,
137+ 'expected ' => ['testFIINInterface ' ],
138+ ],
139+ 'parse error - implements keyword, but no interface name ' => [
140+ 'identifier ' => '/* testMissingImplementsName */ ' ,
141+ 'expected ' => false ,
142+ ],
143+ 'parse error - live coding - no curly braces ' => [
144+ 'identifier ' => '/* testParseError */ ' ,
145+ 'expected ' => false ,
146+ ],
104147 ];
105148
106149 }//end dataImplementedInterface()
0 commit comments