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

LocationTest::testCreateFromRelativePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
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