|
|
|
@ -6,6 +6,7 @@ namespace Arokettu\Path\Tests;
|
|
|
|
|
|
|
|
|
|
use Arokettu\Path\RelativePath;
|
|
|
|
|
use Arokettu\Path\UnixPath;
|
|
|
|
|
use Arokettu\Path\WindowsPath;
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
|
|
class UnixPathTest extends TestCase
|
|
|
|
@ -123,4 +124,57 @@ class UnixPathTest extends TestCase
|
|
|
|
|
$rp4 = new RelativePath('../../../../../../../../i/am/test/relative/path');
|
|
|
|
|
$path->resolveRelative($rp4, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testMakeRelative(): void
|
|
|
|
|
{
|
|
|
|
|
$paths = [
|
|
|
|
|
UnixPath::parse('/i/am/test/unix/path'),
|
|
|
|
|
UnixPath::parse('/i/am/another/unix/test/path'),
|
|
|
|
|
UnixPath::parse('/i/am'),
|
|
|
|
|
UnixPath::parse('/i/am/test/unix/path'), // different instance, same path
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$matrix = [
|
|
|
|
|
[
|
|
|
|
|
'.',
|
|
|
|
|
'../../../another/unix/test/path',
|
|
|
|
|
'../../..',
|
|
|
|
|
'.',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'../../../../test/unix/path',
|
|
|
|
|
'.',
|
|
|
|
|
'../../../..',
|
|
|
|
|
'../../../../test/unix/path',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'test/unix/path',
|
|
|
|
|
'another/unix/test/path',
|
|
|
|
|
'.',
|
|
|
|
|
'test/unix/path',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'.',
|
|
|
|
|
'../../../another/unix/test/path',
|
|
|
|
|
'../../..',
|
|
|
|
|
'.',
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach ($paths as $bpi => $bp) {
|
|
|
|
|
foreach ($paths as $tpi => $tp) {
|
|
|
|
|
$result = $matrix[$bpi][$tpi];
|
|
|
|
|
|
|
|
|
|
self::assertEquals($result, $bp->makeRelative($tp));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testMakeRelativeWrongType(): void
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
$this->expectExceptionMessage('You can only make relative path from paths of same type and same prefix');
|
|
|
|
|
|
|
|
|
|
UnixPath::parse('/i/am/test/unix/path')->makeRelative(WindowsPath::parse('C:\\Windows'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|