Completed
Push — master ( 95fe89...6b0ea2 )
by Dave
19s queued 16s
created

LocationTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateFromAbsolutePath() 0 11 1
A testCreateFromRelativePath() 0 11 1
A testCreateFromRelativePathWithRelativePathToProjectRoot() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Tests\Unit\Core\Common;
6
7
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\AbsoluteFileName;
8
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\LineNumber;
9
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\Location;
10
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\ProjectRoot;
11
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\RelativeFileName;
12
use PHPUnit\Framework\TestCase;
13
14
class LocationTest extends TestCase
15
{
16
    public function testCreateFromAbsolutePath(): void
17
    {
18
        $projectRoot = ProjectRoot::fromCurrentWorkingDirectory('/sarb/root');
19
        $absoluteFileName = new AbsoluteFileName('/sarb/root/src/File.php');
20
        $lineNumber = new LineNumber(10);
21
22
        $location = Location::fromAbsoluteFileName($absoluteFileName, $projectRoot, $lineNumber);
23
24
        $this->assertSame($lineNumber, $location->getLineNumber());
25
        $this->assertSame('src/File.php', $location->getRelativeFileName()->getFileName());
26
        $this->assertSame('/sarb/root/src/File.php', $location->getAbsoluteFileName()->getFileName());
27
    }
28
29
    public function testCreateFromRelativePath(): void
30
    {
31
        $projectRoot = ProjectRoot::fromCurrentWorkingDirectory('/sarb/root');
32
        $relativeFileName = new RelativeFileName('src/File.php');
33
        $lineNumber = new LineNumber(10);
34
35
        $location = Location::fromRelativeFileName($relativeFileName, $projectRoot, $lineNumber);
36
37
        $this->assertSame($lineNumber, $location->getLineNumber());
38
        $this->assertSame('src/File.php', $location->getRelativeFileName()->getFileName());
39
        $this->assertSame('/sarb/root/src/File.php', $location->getAbsoluteFileName()->getFileName());
40
    }
41
42
    public function testCreateFromRelativePathWithRelativePathToProjectRoot(): void
43
    {
44
        $projectRoot = ProjectRoot::fromCurrentWorkingDirectory('/sarb/root');
45
        $projectRoot = $projectRoot->withRelativePath('code');
46
        $relativeFileName = new RelativeFileName('src/File.php');
47
        $lineNumber = new LineNumber(10);
48
49
        $location = Location::fromRelativeFileName($relativeFileName, $projectRoot, $lineNumber);
50
51
        $this->assertSame($lineNumber, $location->getLineNumber());
52
        $this->assertSame('src/File.php', $location->getRelativeFileName()->getFileName());
53
        $this->assertSame('/sarb/root/code/src/File.php', $location->getAbsoluteFileName()->getFileName());
54
    }
55
}
56