1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Tests\Unit\Plugins\ResultsParsers\PhpmdJsonResultsParser; |
6
|
|
|
|
7
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\ProjectRoot; |
8
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\File\InvalidContentTypeException; |
9
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Utils\ParseAtLocationException; |
10
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Plugins\ResultsParsers\PhpmdJsonResultsParser\PhpmdJsonResultsParser; |
11
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Tests\Helpers\ResourceLoaderTrait; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use Throwable; |
14
|
|
|
|
15
|
|
|
class InvalidPhpmdFileFormatTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
use ResourceLoaderTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @psalm-return array<int,array{string}> |
21
|
|
|
*/ |
22
|
|
|
public function filenameDataProvider(): array |
23
|
|
|
{ |
24
|
|
|
return [ |
25
|
|
|
[ |
26
|
|
|
'phpmd_missing_file.json', |
27
|
|
|
], |
28
|
|
|
[ |
29
|
|
|
'phpmd_missing_files.json', |
30
|
|
|
], |
31
|
|
|
[ |
32
|
|
|
'phpmd_missing_violations.json', |
33
|
|
|
], |
34
|
|
|
[ |
35
|
|
|
'phpmd_invalid_violation.json', |
36
|
|
|
], |
37
|
|
|
]; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @dataProvider filenameDataProvider |
42
|
|
|
*/ |
43
|
|
|
public function testInvalidFileFormat(string $fileName): void |
44
|
|
|
{ |
45
|
|
|
$this->assertExceptionThrown(ParseAtLocationException::class, $fileName); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testNotJsonFileSupplied(): void |
49
|
|
|
{ |
50
|
|
|
$this->assertExceptionThrown(InvalidContentTypeException::class, 'not.json'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @psalm-param class-string<Throwable> $exceptionType |
55
|
|
|
*/ |
56
|
|
|
private function assertExceptionThrown(string $exceptionType, string $fileName): void |
57
|
|
|
{ |
58
|
|
|
$fileContents = $this->getResource("phpmd/$fileName"); |
59
|
|
|
$projectRoot = ProjectRoot::fromProjectRoot('/vagrant/static-analysis-baseliner', '/home'); |
60
|
|
|
$phpmdResultsParser = new PhpmdJsonResultsParser(); |
61
|
|
|
|
62
|
|
|
$this->expectException($exceptionType); |
63
|
|
|
$phpmdResultsParser->convertFromString($fileContents, $projectRoot); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|