Fix tests

master
Anton Smirnov 2 years ago
parent 04b521b288
commit f9c6cd5340

@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
namespace Arokettu\Path\Tests\Classes;
use Arokettu\Path\PathInterface;
use Arokettu\Path\RelativePathInterface;
class CustomRelativePathImplementation implements RelativePathInterface
{
private array $components;
private bool $isRoot;
public function __construct(array $components, bool $isRoot)
{
$this->components = $components;
$this->isRoot = $isRoot;
}
public function isAbsolute(): bool
{
return false;
}
public function isRelative(): bool
{
return true;
}
public function __toString(): string
{
return '';
}
public function getPrefix(): string
{
return '';
}
public function getComponents(): array
{
return $this->components;
}
public function toString(): string
{
throw new \BadMethodCallException('Irrelevant');
}
public function resolveRelative(RelativePathInterface $path, bool $strict = false): PathInterface
{
throw new \BadMethodCallException('Irrelevant');
}
public function isRoot(): bool
{
return $this->isRoot;
}
}

@ -184,68 +184,15 @@ class RelativePathTest extends TestCase
{
$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/relative/path');
}
public function toString(): string
{
throw new \BadMethodCallException('Irrelevant');
}
public function resolveRelative(RelativePathInterface $path, bool $strict = false): PathInterface
{
throw new \BadMethodCallException('Irrelevant');
}
public function isRoot(): bool
{
return false;
}
};
$rp2 = new class implements RelativePathInterface {
public function __toString(): string
{
return '';
}
public function getPrefix(): string
{
return '';
}
public function getComponents(): array
{
return explode('/', 'i/am/test/relative/path');
}
public function toString(): string
{
throw new \BadMethodCallException('Irrelevant');
}
public function resolveRelative(RelativePathInterface $path, bool $strict = false): PathInterface
{
throw new \BadMethodCallException('Irrelevant');
}
public function isRoot(): bool
{
return true;
}
};
$rp1 = new Classes\CustomRelativePathImplementation(
explode('/', '../../i/am/test/relative/path'),
false,
);
$rp2 = new Classes\CustomRelativePathImplementation(
explode('/', 'i/am/test/relative/path'),
true,
);
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());

Loading…
Cancel
Save