-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathParallelLintLintTest.php
142 lines (115 loc) · 5.55 KB
/
ParallelLintLintTest.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
137
138
139
140
141
142
<?php
namespace PHP_Parallel_Lint\PhpParallelLint\Tests\Unit;
use PHP_Parallel_Lint\PhpParallelLint\ParallelLint;
use PHP_Parallel_Lint\PhpParallelLint\Process\PhpExecutable;
use PHP_Parallel_Lint\PhpParallelLint\Tests\UnitTestCase;
class ParallelLintLintTest extends UnitTestCase
{
public function testSettersAndGetters()
{
$phpExecutable = $this->getPhpExecutable();
$parallelLint = new ParallelLint($phpExecutable, 10);
$this->assertSame($phpExecutable, $parallelLint->getPhpExecutable());
$this->assertSame(10, $parallelLint->getParallelJobs());
$phpExecutable2 = $this->getPhpExecutable();
$parallelLint->setPhpExecutable($phpExecutable2);
$this->assertSame($phpExecutable2, $parallelLint->getPhpExecutable());
$parallelLint->setParallelJobs(33);
$this->assertSame(33, $parallelLint->getParallelJobs());
$parallelLint->setShortTagEnabled(true);
$this->assertTrue($parallelLint->isShortTagEnabled());
$parallelLint->setAspTagsEnabled(true);
$this->assertTrue($parallelLint->isAspTagsEnabled());
$parallelLint->setShortTagEnabled(false);
$this->assertFalse($parallelLint->isShortTagEnabled());
$parallelLint->setAspTagsEnabled(false);
$this->assertFalse($parallelLint->isAspTagsEnabled());
}
public function testEmptyArray()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array());
$this->assertSame(0, $result->getCheckedFilesCount());
$this->assertSame(0, $result->getFilesWithSyntaxErrorCount());
$this->assertFalse($result->hasSyntaxError());
$this->assertSame(0, count($result->getErrors()));
}
public function testNotExistsFile()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array('path/for-not-found/'));
$this->assertSame(0, $result->getCheckedFilesCount());
$this->assertSame(0, $result->getFilesWithSyntaxErrorCount());
$this->assertFalse($result->hasSyntaxError());
$this->assertSame(1, count($result->getErrors()));
}
public function testEmptyFile()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array(PL_TESTROOT . '/fixtures/fixture-01/empty-file'));
$this->assertSame(1, $result->getCheckedFilesCount());
$this->assertSame(0, $result->getFilesWithSyntaxErrorCount());
$this->assertFalse($result->hasSyntaxError());
$this->assertSame(0, count($result->getErrors()));
}
public function testValidFile()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array(PL_TESTROOT . '/fixtures/fixture-02/example.php'));
$this->assertSame(1, $result->getCheckedFilesCount());
$this->assertSame(0, $result->getFilesWithSyntaxErrorCount());
$this->assertSame(0, count($result->getErrors()));
}
public function testSkipShebang()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array(PL_TESTROOT . '/fixtures/fixture-07/example.php'));
$this->assertSame(0, $result->getCheckedFilesCount());
$this->assertSame(0, $result->getFilesWithSyntaxErrorCount());
$this->assertSame(1, $result->getSkippedFilesCount());
}
public function testInvalidFile()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array(PL_TESTROOT . '/fixtures/fixture-03/example.php'));
$this->assertSame(1, $result->getCheckedFilesCount());
$this->assertSame(1, $result->getFilesWithSyntaxErrorCount());
$this->assertTrue($result->hasSyntaxError());
$this->assertSame(1, count($result->getErrors()));
}
public function testDeprecated()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array(PL_TESTROOT . '/fixtures/fixture-05/Foo.php'));
$this->assertSame(1, $result->getCheckedFilesCount());
$this->assertSame(0, $result->getFilesWithSyntaxErrorCount());
$this->assertFalse($result->hasSyntaxError());
$this->assertSame(0, count($result->getErrors()));
if (PHP_VERSION_ID < 70000 || PHP_VERSION_ID >= 80000) {
$this->markTestSkipped('Test for php version 7.0-7.4');
}
$parallelLint = new ParallelLint($this->getPhpExecutable());
$parallelLint->setShowDeprecated(true);
$result = $parallelLint->lint(array(PL_TESTROOT . '/fixtures/fixture-05/Foo.php'));
$this->assertSame(1, $result->getCheckedFilesCount());
$this->assertSame(1, $result->getFilesWithSyntaxErrorCount());
$this->assertTrue($result->hasSyntaxError());
$this->assertSame(1, count($result->getErrors()));
}
public function testValidAndInvalidFiles()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array(
PL_TESTROOT . '/fixtures/fixture-02/example.php',
PL_TESTROOT . '/fixtures/fixture-03/example.php',
));
$this->assertSame(2, $result->getCheckedFilesCount());
$this->assertSame(1, $result->getFilesWithSyntaxErrorCount());
$this->assertTrue($result->hasSyntaxError());
$this->assertSame(1, count($result->getErrors()));
}
private function getPhpExecutable()
{
return PhpExecutable::getPhpExecutable('php');
}
}