-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathParallelLint.lint.phpt
150 lines (120 loc) · 5.38 KB
/
ParallelLint.lint.phpt
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/**
* @testCase
*/
require __DIR__ . '/../vendor/autoload.php';
Tester\Environment::setup();
use JakubOnderka\PhpParallelLint\ParallelLint;
use Tester\Assert;
class ParallelLintLintTest extends Tester\TestCase
{
public function testSettersAndGetters()
{
$phpExecutable = $this->getPhpExecutable();
$parallelLint = new ParallelLint($phpExecutable, 10);
Assert::equal($phpExecutable, $parallelLint->getPhpExecutable());
Assert::equal(10, $parallelLint->getParallelJobs());
$phpExecutable2 = $this->getPhpExecutable();
$parallelLint->setPhpExecutable($phpExecutable2);
Assert::equal($phpExecutable2, $parallelLint->getPhpExecutable());
$parallelLint->setParallelJobs(33);
Assert::equal(33, $parallelLint->getParallelJobs());
$parallelLint->setShortTagEnabled(true);
Assert::true($parallelLint->isShortTagEnabled());
$parallelLint->setAspTagsEnabled(true);
Assert::true($parallelLint->isAspTagsEnabled());
$parallelLint->setShortTagEnabled(false);
Assert::false($parallelLint->isShortTagEnabled());
$parallelLint->setAspTagsEnabled(false);
Assert::false($parallelLint->isAspTagsEnabled());
}
public function testEmptyArray()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array());
Assert::equal(0, $result->getCheckedFilesCount());
Assert::equal(0, $result->getFilesWithSyntaxErrorCount());
Assert::false($result->hasSyntaxError());
Assert::equal(0, count($result->getErrors()));
}
public function testNotExistsFile()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array('path/for-not-found/'));
Assert::equal(0, $result->getCheckedFilesCount());
Assert::equal(0, $result->getFilesWithSyntaxErrorCount());
Assert::false($result->hasSyntaxError());
Assert::equal(1, count($result->getErrors()));
}
public function testEmptyFile()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array(__DIR__ . '/examples/example-01/empty-file'));
Assert::equal(1, $result->getCheckedFilesCount());
Assert::equal(0, $result->getFilesWithSyntaxErrorCount());
Assert::false($result->hasSyntaxError());
Assert::equal(0, count($result->getErrors()));
}
public function testValidFile()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array(__DIR__ . '/examples/example-02/example.php'));
Assert::equal(1, $result->getCheckedFilesCount());
Assert::equal(0, $result->getFilesWithSyntaxErrorCount());
Assert::equal(0, count($result->getErrors()));
}
public function testSkipShebang()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array(__DIR__ . '/examples/example-07/example.php'));
Assert::equal(0, $result->getCheckedFilesCount());
Assert::equal(0, $result->getFilesWithSyntaxErrorCount());
Assert::equal(1, $result->getSkippedFilesCount());
}
public function testInvalidFile()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array(__DIR__ . '/examples/example-03/example.php'));
Assert::equal(1, $result->getCheckedFilesCount());
Assert::equal(1, $result->getFilesWithSyntaxErrorCount());
Assert::true($result->hasSyntaxError());
Assert::equal(1, count($result->getErrors()));
}
public function testDeprecated()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array(__DIR__ . '/examples/example-05/Foo.php'));
Assert::equal(1, $result->getCheckedFilesCount());
Assert::equal(0, $result->getFilesWithSyntaxErrorCount());
Assert::false($result->hasSyntaxError());
Assert::equal(0, count($result->getErrors()));
if (PHP_VERSION_ID < 70000 || PHP_VERSION_ID >= 80000 ) {
Tester\Environment::skip('test for php version 7.0-7.4');
}
$parallelLint = new ParallelLint($this->getPhpExecutable());
$parallelLint->setShowDeprecated(true);
$result = $parallelLint->lint(array(__DIR__ . '/examples/example-05/Foo.php'));
Assert::equal(1, $result->getCheckedFilesCount());
Assert::equal(1, $result->getFilesWithSyntaxErrorCount());
Assert::true($result->hasSyntaxError());
Assert::equal(1, count($result->getErrors()));
}
public function testValidAndInvalidFiles()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array(
__DIR__ . '/examples/example-02/example.php',
__DIR__ . '/examples/example-03/example.php',
));
Assert::equal(2, $result->getCheckedFilesCount());
Assert::equal(1, $result->getFilesWithSyntaxErrorCount());
Assert::true($result->hasSyntaxError());
Assert::equal(1, count($result->getErrors()));
}
private function getPhpExecutable()
{
return \JakubOnderka\PhpParallelLint\Process\PhpExecutable::getPhpExecutable('php');
}
}
$testCase = new ParallelLintLintTest;
$testCase->run();