-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend by the Code Climate output format
The Code Climate format is used in the GitLab CI/CD to show errors in the merge request page. The simple JSON format is not sufficient for this.
- Loading branch information
Showing
7 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
/** | ||
* @testCase | ||
*/ | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
use JakubOnderka\PhpParallelLint\ErrorFormatter; | ||
use JakubOnderka\PhpParallelLint\GitLabOutput; | ||
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()); | ||
|
||
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 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters