1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace UsageFinder\Tests; |
||
6 | |||
7 | use InvalidArgumentException; |
||
8 | use UsageFinder\ClassMethodReference; |
||
9 | |||
10 | final class ClassMethodReferenceTest extends TestCase |
||
11 | { |
||
12 | public function testGetName() : void |
||
13 | { |
||
14 | self::assertSame( |
||
15 | 'Doctrine\Common\Collections\Collection::slice', |
||
16 | (new ClassMethodReference('Doctrine\Common\Collections\Collection::slice'))->getName() |
||
17 | ); |
||
18 | } |
||
19 | |||
20 | public function testGetClassName() : void |
||
21 | { |
||
22 | self::assertSame( |
||
23 | 'Doctrine\Common\Collections\Collection', |
||
24 | (new ClassMethodReference('Doctrine\Common\Collections\Collection::slice'))->getClassName() |
||
25 | ); |
||
26 | } |
||
27 | |||
28 | public function testGetMethodName() : void |
||
29 | { |
||
30 | self::assertSame( |
||
31 | 'slice', |
||
32 | (new ClassMethodReference('Doctrine\Common\Collections\Collection::slice'))->getMethodName() |
||
33 | ); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @dataProvider provideForTestInvalidClassMethodReference |
||
38 | */ |
||
39 | public function testInvalidClassMethodReference(string $input, string $message) : void |
||
40 | { |
||
41 | self::expectException(InvalidArgumentException::class); |
||
42 | self::expectExceptionMessage($message); |
||
0 ignored issues
–
show
|
|||
43 | |||
44 | new ClassMethodReference($input); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @return array<int, array<int, string>> |
||
49 | */ |
||
50 | public function provideForTestInvalidClassMethodReference() : array |
||
51 | { |
||
52 | return [ |
||
53 | [ |
||
54 | '', |
||
55 | 'Invalid ClassMethodReference, empty string given. Format must be ClassName::methodName.', |
||
56 | ], |
||
57 | [ |
||
58 | 'Doctrine\Common\Collections\Collection::', |
||
59 | 'You must specify a method name to find. "Doctrine\Common\Collections\Collection::" given.', |
||
60 | ], |
||
61 | [ |
||
62 | 'Doctrine\Common\Collections\Collection:: ', |
||
63 | 'You must specify a method name to find. "Doctrine\Common\Collections\Collection:: " given.', |
||
64 | ], |
||
65 | [ |
||
66 | 'Doctrine\Common\Collections\Collection', |
||
67 | 'Invalid ClassMethodReference, "Doctrine\Common\Collections\Collection" given. Format must be ClassName::methodName.', |
||
68 | ], |
||
69 | ]; |
||
70 | } |
||
71 | } |
||
72 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.