1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace UsageFinder\Tests; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\Console\Application; |
8
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
9
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
10
|
|
|
use Symfony\Component\Process\Process; |
11
|
|
|
use UsageFinder\Command\FindClassMethodUsagesCommand; |
12
|
|
|
|
13
|
|
|
final class ConsoleTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
public function testCommand() : void |
16
|
|
|
{ |
17
|
|
|
$application = new Application(); |
18
|
|
|
$application->setAutoExit(false); |
19
|
|
|
|
20
|
|
|
$input = new ArrayInput([ |
21
|
|
|
'command' => 'find', |
22
|
|
|
'path' => 'tests/example', |
23
|
|
|
'find' => 'Doctrine\Common\Collections\Collection::slice', |
24
|
|
|
]); |
25
|
|
|
|
26
|
|
|
$output = new BufferedOutput(); |
27
|
|
|
|
28
|
|
|
$application->add(new FindClassMethodUsagesCommand()); |
29
|
|
|
|
30
|
|
|
$application->run($input, $output); |
31
|
|
|
|
32
|
|
|
self::assertProcessOutput($output->fetch()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testBin() : void |
36
|
|
|
{ |
37
|
|
|
$process = new Process([ |
38
|
|
|
'bin/usage-finder', |
39
|
|
|
'find', |
40
|
|
|
'tests/example', |
41
|
|
|
'Doctrine\Common\Collections\Collection::slice', |
42
|
|
|
], __DIR__ . '/..'); |
43
|
|
|
|
44
|
|
|
$process->mustRun(); |
45
|
|
|
|
46
|
|
|
$output = $process->getOutput(); |
47
|
|
|
|
48
|
|
|
self::assertProcessOutput($output); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
private static function assertProcessOutput(string $output) : void |
52
|
|
|
{ |
53
|
|
|
self::assertStringContainsString( |
|
|
|
|
54
|
|
|
'Searching for Doctrine\Common\Collections\Collection::slice in tests/example.', |
55
|
|
|
$output |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
self::assertStringContainsString( |
59
|
|
|
'Found usage in src/AppCode.php on line 14.', |
60
|
|
|
$output |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
self::assertStringContainsString( |
64
|
|
|
'->slice(0, 1);', |
65
|
|
|
$output |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
self::assertStringContainsString( |
69
|
|
|
'Found usage in src/AppCode.php on line 17.', |
70
|
|
|
$output |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
self::assertStringContainsString( |
74
|
|
|
'->slice(0, 2);', |
75
|
|
|
$output |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
self::assertStringContainsString( |
79
|
|
|
'Found usage in src/AppCode.php on line 20.', |
80
|
|
|
$output |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
self::assertStringContainsString( |
84
|
|
|
'->slice(0, 3);', |
85
|
|
|
$output |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
self::assertRegExp('/Finished in (.*)ms/', $output); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
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.