-
Notifications
You must be signed in to change notification settings - Fork 650
/
CliUtilsTest.php
136 lines (117 loc) · 4.16 KB
/
CliUtilsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
namespace Psalm\Tests\Internal;
use PHPUnit\Framework\TestCase;
use Psalm\Internal\CliUtils;
use function realpath;
use const DIRECTORY_SEPARATOR;
class CliUtilsTest extends TestCase
{
/**
* @var list<string>
*/
private $argv = [];
protected function setUp(): void
{
global $argv;
$this->argv = $argv;
}
protected function tearDown(): void
{
global $argv;
$argv = $this->argv;
}
/** @return iterable<string,array{list<string>,list<string>}> */
public function provideGetArguments(): iterable
{
$psalter = __DIR__ . '/../../psalter';
yield 'standardCallWithPsalter' => [
['--plugin=vendor/vimeo/psalm/examples/plugins/ClassUnqualifier.php', '--dry-run'],
[$psalter, '--plugin=vendor/vimeo/psalm/examples/plugins/ClassUnqualifier.php', '--dry-run'],
];
yield 'specialCaseWithBinary' => [
['--plugin=vendor/vimeo/psalm/examples/plugins/ClassUnqualifier.php', '--dry-run'],
['/bin/true', '--plugin=vendor/vimeo/psalm/examples/plugins/ClassUnqualifier.php', '--dry-run'],
];
yield 'specialCaseWhichWouldFail' => [
['--plugin=vendor/vimeo/psalm/examples/plugins/ClassUnqualifier.php', '--dry-run'],
['/directory-does-not-exist/file-does-not-exist', '--plugin=vendor/vimeo/psalm/examples/plugins/ClassUnqualifier.php', '--dry-run'],
];
}
/**
* @dataProvider provideGetArguments
* @param list<string> $expected
* @param list<string> $_input
*/
public function testGetArgumentsWillReturnExpectedValue(array $expected, array $_input): void
{
global $argv;
$argv = $_input;
$result = CliUtils::getArguments();
self::assertEquals($expected, $result);
}
/** @return iterable<string,array{list<string>|null,list<string>,fpaths?:list<string>}> */
public function provideGetPathsToCheck(): iterable
{
$psalm = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'psalm';
$dummyProjectDir = (string)realpath(
__DIR__
. DIRECTORY_SEPARATOR . '..'
. DIRECTORY_SEPARATOR. 'fixtures'
. DIRECTORY_SEPARATOR . 'DummyProject'
);
$currentDir = (string)realpath('.');
yield 'withoutPaths' => [
null,
[$psalm, '--plugin=vendor/vimeo/psalm/examples/plugins/ClassUnqualifier.php', '--dry-run'],
];
yield 'withoutPathsAndArguments' => [
null,
[$psalm],
];
yield 'withPaths' => [
[
$dummyProjectDir . DIRECTORY_SEPARATOR . 'Bar.php',
$dummyProjectDir . DIRECTORY_SEPARATOR . 'Bat.php',
],
[
$psalm,
$dummyProjectDir . DIRECTORY_SEPARATOR . 'Bar.php',
$dummyProjectDir . DIRECTORY_SEPARATOR . 'Bat.php',
],
];
yield 'withPathsAndArgumentsMixed' => [
[
$dummyProjectDir . DIRECTORY_SEPARATOR . 'Bar.php',
$dummyProjectDir . DIRECTORY_SEPARATOR . 'Bat.php',
],
[
$psalm,
'--plugin=vendor/vimeo/psalm/examples/plugins/ClassUnqualifier.php',
$dummyProjectDir . DIRECTORY_SEPARATOR . 'Bar.php',
$dummyProjectDir . DIRECTORY_SEPARATOR . 'Bat.php',
],
];
yield 'withFpathToCurrentDir' => [
[$currentDir],
[$psalm, '-f', '.'],
['.']
];
yield 'withFpathToProjectDir' => [
[$dummyProjectDir],
[$psalm, '-f', $dummyProjectDir],
[$dummyProjectDir]
];
}
/**
* @dataProvider provideGetPathsToCheck
* @param list<string>|null $expected
* @param list<string> $_input
*/
public function testGetPathsToCheckWillReturnExpectedValue(?array $expected, array $_input, array $fpaths = []): void
{
global $argv;
$argv = $_input;
$result = CliUtils::getPathsToCheck($fpaths);
self::assertEquals($expected, $result);
}
}