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
|
|
|
|
14
|
|
|
final class InvalidPhpmdFileFormatTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
use ResourceLoaderTrait; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @return array<int,array{string}> |
|
|
|
|
20
|
|
|
*/ |
21
|
|
|
public function filenameDataProvider(): array |
22
|
|
|
{ |
23
|
|
|
return [ |
24
|
|
|
[ |
25
|
|
|
'phpmd_missing_file.json', |
26
|
|
|
], |
27
|
|
|
[ |
28
|
|
|
'phpmd_missing_files.json', |
29
|
|
|
], |
30
|
|
|
[ |
31
|
|
|
'phpmd_missing_violations.json', |
32
|
|
|
], |
33
|
|
|
[ |
34
|
|
|
'phpmd_invalid_violation.json', |
35
|
|
|
], |
36
|
|
|
]; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @dataProvider filenameDataProvider |
41
|
|
|
*/ |
42
|
|
|
public function testInvalidFileFormat(string $fileName): void |
43
|
|
|
{ |
44
|
|
|
$this->assertExceptionThrown(ParseAtLocationException::class, $fileName); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testNotJsonFileSupplied(): void |
48
|
|
|
{ |
49
|
|
|
$this->assertExceptionThrown(InvalidContentTypeException::class, 'not.json'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param class-string<\Throwable> $exceptionType |
|
|
|
|
54
|
|
|
*/ |
55
|
|
|
private function assertExceptionThrown(string $exceptionType, string $fileName): void |
56
|
|
|
{ |
57
|
|
|
$fileContents = $this->getResource("phpmd/$fileName"); |
58
|
|
|
$projectRoot = ProjectRoot::fromProjectRoot('/vagrant/static-analysis-baseliner', '/home'); |
59
|
|
|
$phpmdResultsParser = new PhpmdJsonResultsParser(); |
60
|
|
|
|
61
|
|
|
$this->expectException($exceptionType); |
62
|
|
|
$phpmdResultsParser->convertFromString($fileContents, $projectRoot); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|