@@ -20,6 +20,33 @@ 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 *
@@ -49,6 +76,14 @@ public function testFindImplementedInterfaceNames($identifier, $expected)
4976 public function dataImplementedInterface ()
5077 {
5178 return [
79+ 'interface declaration, no implements ' => [
80+ 'identifier ' => '/* testPlainInterface */ ' ,
81+ 'expected ' => false ,
82+ ],
83+ 'class does not implement ' => [
84+ 'identifier ' => '/* testNonImplementedClass */ ' ,
85+ 'expected ' => false ,
86+ ],
5287 'class implements single interface, unqualified ' => [
5388 'identifier ' => '/* testClassImplementsSingle */ ' ,
5489 'expected ' => ['testFIINInterface ' ],
@@ -64,13 +99,9 @@ public function dataImplementedInterface()
6499 'identifier ' => '/* testImplementsFullyQualified */ ' ,
65100 'expected ' => ['\PHP_CodeSniffer\Tests\Core\File\testFIINInterface ' ],
66101 ],
67- 'class does not implement ' => [
68- 'identifier ' => '/* testNonImplementedClass */ ' ,
69- 'expected ' => false ,
70- ],
71- 'interface declaration, no implements ' => [
72- 'identifier ' => '/* testPlainInterface */ ' ,
73- 'expected ' => false ,
102+ 'class implements single interface, partially qualified ' => [
103+ 'identifier ' => '/* testImplementsPartiallyQualified */ ' ,
104+ 'expected ' => ['Core\File\RelativeInterface ' ],
74105 ],
75106 'class extends and implements ' => [
76107 'identifier ' => '/* testClassThatExtendsAndImplements */ ' ,
@@ -101,6 +132,18 @@ public function dataImplementedInterface()
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