|
|
|
@ -14,16 +14,16 @@ class RelativePathTest extends TestCase
|
|
|
|
|
public function testCreate(): void
|
|
|
|
|
{
|
|
|
|
|
// 'absolute' relative path
|
|
|
|
|
$path = RelativePath::unix('/i/am/./skipme/../test/./path');
|
|
|
|
|
self::assertEquals('/i/am/test/path', $path->toString());
|
|
|
|
|
$path = RelativePath::unix('/i/am/./skipme/../test/./relative/path');
|
|
|
|
|
self::assertEquals('/i/am/test/relative/path', $path->toString());
|
|
|
|
|
|
|
|
|
|
// relative path from the current directory
|
|
|
|
|
$path = RelativePath::unix('./i/am/./skipme/../test/./path');
|
|
|
|
|
self::assertEquals('i/am/test/path', $path->toString());
|
|
|
|
|
$path = RelativePath::unix('./i/am/./skipme/../test/./relative/path');
|
|
|
|
|
self::assertEquals('i/am/test/relative/path', $path->toString());
|
|
|
|
|
|
|
|
|
|
// relative path from the parent directory
|
|
|
|
|
$path = RelativePath::unix('.././../i/am/./skipme/../test/./path');
|
|
|
|
|
self::assertEquals('../../i/am/test/path', $path->toString());
|
|
|
|
|
$path = RelativePath::unix('.././../i/am/./skipme/../test/./relative/path');
|
|
|
|
|
self::assertEquals('../../i/am/test/relative/path', $path->toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCreateWindows(): void
|
|
|
|
@ -44,37 +44,37 @@ class RelativePathTest extends TestCase
|
|
|
|
|
public function testResolveRelative(): void
|
|
|
|
|
{
|
|
|
|
|
$paths = [
|
|
|
|
|
new RelativePath('/i/am/test/path'),
|
|
|
|
|
new RelativePath('i/am/test/path'),
|
|
|
|
|
new RelativePath('../../i/am/test/path'),
|
|
|
|
|
new RelativePath('../../../../../../../../i/am/test/path'),
|
|
|
|
|
new RelativePath('/i/am/test/relative/path'),
|
|
|
|
|
new RelativePath('i/am/test/relative/path'),
|
|
|
|
|
new RelativePath('../../i/am/test/relative/path'),
|
|
|
|
|
new RelativePath('../../../../../../../../i/am/test/relative/path'),
|
|
|
|
|
];
|
|
|
|
|
$relativePaths = $paths;
|
|
|
|
|
|
|
|
|
|
$matrix = [
|
|
|
|
|
[
|
|
|
|
|
'/i/am/test/path',
|
|
|
|
|
'/i/am/test/path/i/am/test/path',
|
|
|
|
|
'/i/am/i/am/test/path',
|
|
|
|
|
'/i/am/test/path',
|
|
|
|
|
'/i/am/test/relative/path',
|
|
|
|
|
'/i/am/test/relative/path/i/am/test/relative/path',
|
|
|
|
|
'/i/am/test/i/am/test/relative/path',
|
|
|
|
|
'/i/am/test/relative/path',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'/i/am/test/path',
|
|
|
|
|
'i/am/test/path/i/am/test/path',
|
|
|
|
|
'i/am/i/am/test/path',
|
|
|
|
|
'../../../../i/am/test/path',
|
|
|
|
|
'/i/am/test/relative/path',
|
|
|
|
|
'i/am/test/relative/path/i/am/test/relative/path',
|
|
|
|
|
'i/am/test/i/am/test/relative/path',
|
|
|
|
|
'../../../i/am/test/relative/path',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'/i/am/test/path',
|
|
|
|
|
'../../i/am/test/path/i/am/test/path',
|
|
|
|
|
'../../i/am/i/am/test/path',
|
|
|
|
|
'../../../../../../i/am/test/path',
|
|
|
|
|
'/i/am/test/relative/path',
|
|
|
|
|
'../../i/am/test/relative/path/i/am/test/relative/path',
|
|
|
|
|
'../../i/am/test/i/am/test/relative/path',
|
|
|
|
|
'../../../../../i/am/test/relative/path',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'/i/am/test/path',
|
|
|
|
|
'../../../../../../../../i/am/test/path/i/am/test/path',
|
|
|
|
|
'../../../../../../../../i/am/i/am/test/path',
|
|
|
|
|
'../../../../../../../../../../../../i/am/test/path',
|
|
|
|
|
'/i/am/test/relative/path',
|
|
|
|
|
'../../../../../../../../i/am/test/relative/path/i/am/test/relative/path',
|
|
|
|
|
'../../../../../../../../i/am/test/i/am/test/relative/path',
|
|
|
|
|
'../../../../../../../../../../../i/am/test/relative/path',
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
@ -90,37 +90,37 @@ class RelativePathTest extends TestCase
|
|
|
|
|
public function testResolveRelativeStrict(): void
|
|
|
|
|
{
|
|
|
|
|
$paths = [
|
|
|
|
|
new RelativePath('/i/am/test/path'),
|
|
|
|
|
new RelativePath('i/am/test/path'),
|
|
|
|
|
new RelativePath('../../i/am/test/path'),
|
|
|
|
|
new RelativePath('../../../../../../../../i/am/test/path'),
|
|
|
|
|
new RelativePath('/i/am/test/relative/path'),
|
|
|
|
|
new RelativePath('i/am/test/relative/path'),
|
|
|
|
|
new RelativePath('../../i/am/test/relative/path'),
|
|
|
|
|
new RelativePath('../../../../../../../../i/am/test/relative/path'),
|
|
|
|
|
];
|
|
|
|
|
$relativePaths = $paths;
|
|
|
|
|
|
|
|
|
|
$matrix = [
|
|
|
|
|
[
|
|
|
|
|
'/i/am/test/path',
|
|
|
|
|
'/i/am/test/path/i/am/test/path',
|
|
|
|
|
'/i/am/i/am/test/path',
|
|
|
|
|
'/i/am/test/relative/path',
|
|
|
|
|
'/i/am/test/relative/path/i/am/test/relative/path',
|
|
|
|
|
'/i/am/test/i/am/test/relative/path',
|
|
|
|
|
null,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'/i/am/test/path',
|
|
|
|
|
'i/am/test/path/i/am/test/path',
|
|
|
|
|
'i/am/i/am/test/path',
|
|
|
|
|
'../../../../i/am/test/path',
|
|
|
|
|
'/i/am/test/relative/path',
|
|
|
|
|
'i/am/test/relative/path/i/am/test/relative/path',
|
|
|
|
|
'i/am/test/i/am/test/relative/path',
|
|
|
|
|
'../../../i/am/test/relative/path',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'/i/am/test/path',
|
|
|
|
|
'../../i/am/test/path/i/am/test/path',
|
|
|
|
|
'../../i/am/i/am/test/path',
|
|
|
|
|
'../../../../../../i/am/test/path',
|
|
|
|
|
'/i/am/test/relative/path',
|
|
|
|
|
'../../i/am/test/relative/path/i/am/test/relative/path',
|
|
|
|
|
'../../i/am/test/i/am/test/relative/path',
|
|
|
|
|
'../../../../../i/am/test/relative/path',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'/i/am/test/path',
|
|
|
|
|
'../../../../../../../../i/am/test/path/i/am/test/path',
|
|
|
|
|
'../../../../../../../../i/am/i/am/test/path',
|
|
|
|
|
'../../../../../../../../../../../../i/am/test/path',
|
|
|
|
|
'/i/am/test/relative/path',
|
|
|
|
|
'../../../../../../../../i/am/test/relative/path/i/am/test/relative/path',
|
|
|
|
|
'../../../../../../../../i/am/test/i/am/test/relative/path',
|
|
|
|
|
'../../../../../../../../../../../i/am/test/relative/path',
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
@ -142,24 +142,29 @@ class RelativePathTest extends TestCase
|
|
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
$this->expectExceptionMessage('Relative path went beyond root');
|
|
|
|
|
|
|
|
|
|
$p = new RelativePath('/i/am/test/path');
|
|
|
|
|
$rp = new RelativePath('../../../../../../../../i/am/test/path');
|
|
|
|
|
$p = new RelativePath('/i/am/test/relative/path');
|
|
|
|
|
$rp = new RelativePath('../../../../../../../../i/am/test/relative/path');
|
|
|
|
|
|
|
|
|
|
$p->resolveRelative($rp, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testExternalRelativeImplementations(): void
|
|
|
|
|
{
|
|
|
|
|
$p = new RelativePath('i/am/test/path');
|
|
|
|
|
$p = new RelativePath('i/am/test/relative/path');
|
|
|
|
|
|
|
|
|
|
$rp1 = new class implements RelativePathInterface {
|
|
|
|
|
public function __toString(): string {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getPrefix(): string
|
|
|
|
|
{
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getComponents(): array
|
|
|
|
|
{
|
|
|
|
|
return explode('/', '../../i/am/test/path');
|
|
|
|
|
return explode('/', '../../i/am/test/relative/path');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function toString(): string
|
|
|
|
@ -179,13 +184,19 @@ class RelativePathTest extends TestCase
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$rp2 = new class implements RelativePathInterface {
|
|
|
|
|
public function __toString(): string {
|
|
|
|
|
public function __toString(): string
|
|
|
|
|
{
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getPrefix(): string
|
|
|
|
|
{
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getComponents(): array
|
|
|
|
|
{
|
|
|
|
|
return explode('/', 'i/am/test/path');
|
|
|
|
|
return explode('/', 'i/am/test/relative/path');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function toString(): string
|
|
|
|
@ -204,7 +215,7 @@ class RelativePathTest extends TestCase
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self::assertEquals('i/am/i/am/test/path', $p->resolveRelative($rp1)->toString());
|
|
|
|
|
self::assertEquals('/i/am/test/path', $p->resolveRelative($rp2)->toString());
|
|
|
|
|
self::assertEquals('i/am/test/i/am/test/relative/path', $p->resolveRelative($rp1)->toString());
|
|
|
|
|
self::assertEquals('/i/am/test/relative/path', $p->resolveRelative($rp2)->toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|