-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathOutput.phpt
122 lines (104 loc) · 3.66 KB
/
Output.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
<?php
/**
* @testCase
*/
require __DIR__ . '/../vendor/autoload.php';
Tester\Environment::setup();
use JakubOnderka\PhpParallelLint\ErrorFormatter;
use JakubOnderka\PhpParallelLint\GitLabOutput;
use JakubOnderka\PhpParallelLint\CheckstyleOutput;
use JakubOnderka\PhpParallelLint\IWriter;
use JakubOnderka\PhpParallelLint\Result;
use JakubOnderka\PhpParallelLint\SyntaxError;
use Tester\Assert;
class OutputTest extends Tester\TestCase
{
/**
* @dataProvider getGitLabOutputData
*/
public function testGitLabOutput($errors)
{
$result = new Result($errors, array(), array(), 0);
$writer = new TestWriter();
$output = new GitLabOutput($writer);
$output->writeResult($result, new ErrorFormatter(), true);
$result = (array) json_decode($writer->getLogs());
Assert::equal(count($errors), count($result));
for ($i = 0; $i < count($result) && $i < count($errors); $i++) {
$message = $errors[$i]->getMessage();
$filePath = $errors[$i]->getFilePath();
$line = 1;
if ($errors[$i] instanceof SyntaxError) {
$line = $errors[$i]->getLine();
}
Assert::equal($result[$i]->type, 'issue');
Assert::equal($result[$i]->check_name, 'Parse error');
Assert::equal($result[$i]->categories, 'Style');
Assert::equal($result[$i]->severity, 'minor');
Assert::equal($result[$i]->description, $message);
Assert::equal($result[$i]->fingerprint, md5($filePath . $message . $line));
Assert::equal($result[$i]->location->path, $filePath);
Assert::equal($result[$i]->location->lines->begin, $line);
}
}
public function testCheckstyleOutput()
{
$errors = array(
new JakubOnderka\PhpParallelLint\SyntaxError(
'sample.php',
'Parse error: syntax error, unexpected \'"\' in ./sample.php on line 3'
),
);
$result = new Result($errors, array(), array(), 0);
$writer = new TestWriter();
$output = new CheckstyleOutput($writer);
$output->writeResult($result, new ErrorFormatter(), true);
$xml = $writer->getLogs();
// phpcs:ignore Generic.PHP.NoSilencedErrors -- Test only code, this is okay.
$parsed = @simplexml_load_string($xml);
Assert::contains("unexpected '"'", $xml);
Assert::type('SimpleXMLElement', $parsed);
}
public function getGitLabOutputData()
{
return array(
array(
'errors' => array()
),
array(
'errors' => array(
new SyntaxError('foo/bar.php', "Parse error: syntax error, unexpected in foo/bar.php on line 52")
)
),
array(
'errors' => array(
new JakubOnderka\PhpParallelLint\Error('foo/bar.php', "PHP Parse error: syntax error, unexpected ';'")
)
),
array(
'errors' => array(
new SyntaxError('foo/bar.php', "Parse error: syntax error, unexpected in foo/bar.php on line 52"),
new JakubOnderka\PhpParallelLint\Error('foo/bar.php', "PHP Parse error: syntax error, unexpected ';'")
)
),
);
}
}
class TestWriter implements IWriter
{
/** @var string */
protected $logs = "";
/**
* @param string $string
*/
public function write($string)
{
$this->logs .= $string;
}
public function getLogs()
{
return $this->logs;
}
}
$testCase = new OutputTest;
$testCase->run();