Skip to content

Commit

Permalink
!!![TASK] Remove unused UrlGeneratorInterface::generateUrl
Browse files Browse the repository at this point in the history
It didnt do anything but leave each URL unchanged in a complicated way and was not used anymore
  • Loading branch information
linawolf committed Oct 1, 2023
1 parent c3e67f4 commit 87c803b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 23 deletions.
15 changes: 0 additions & 15 deletions packages/guides/src/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace phpDocumentor\Guides;

use InvalidArgumentException;
use League\Uri\UriInfo;

use function array_pop;
Expand All @@ -24,20 +23,6 @@

final class UrlGenerator implements UrlGeneratorInterface
{
public function generateUrl(string $path): string
{
try {
$uri = UriFactory::createUri($path);
if (UriInfo::isAbsolutePath($uri)) {
return $path;
}

return $this->relativeUrl($path);
} catch (InvalidArgumentException) {
return $path;
}
}

/**
* Returns the absolute path, including prefixing '/'.
*
Expand Down
2 changes: 0 additions & 2 deletions packages/guides/src/UrlGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

interface UrlGeneratorInterface
{
public function generateUrl(string $path): string;

/**
* Returns the absolute path, including prefixing '/'.
*
Expand Down
57 changes: 51 additions & 6 deletions packages/guides/tests/unit/UrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,57 @@

final class UrlGeneratorTest extends TestCase
{
#[DataProvider('fileUrlProvider')]
public function testCreateFileUrl(string $expected, string $filename, string $outputFormat = 'html', string|null $anchor = null, string $skip = ''): void
{
if ($skip !== '') {
self::markTestSkipped($skip);
}

$urlGenerator = new UrlGenerator();
self::assertSame($expected, $urlGenerator->createFileUrl($filename, $outputFormat, $anchor));
}

/** @return array<string, array<string, string|null>> */
public static function fileUrlProvider(): array
{
return [
'Simple Filename' => [
'expected' => 'file.html',
'filename' => 'file',
],
'Complex Filename' => [
'expected' => 'file-something.html',
'filename' => 'file-something',
],
'Output Format' => [
'expected' => 'texfile.tex',
'filename' => 'texfile',
'outputFormat' => 'tex',
],
'File with anchor' => [
'expected' => 'file.html#anchor',
'filename' => 'file',
'outputFormat' => 'html',
'anchor' => 'anchor',
],
'Empty File with anchor' => [
'expected' => '#anchor',
'filename' => '',
'outputFormat' => 'html',
'anchor' => 'anchor',
'skip' => 'Empty filenames are not supported',
],
'Empty File with empty anchor' => [
'expected' => '#',
'filename' => '',
'outputFormat' => 'html',
'anchor' => null,
'skip' => 'Empty filenames are not supported',
],
];
}

#[DataProvider('canonicalUrlProvider')]
public function testCanonicalUrl(string $basePath, string $url, string $result): void
{
Expand Down Expand Up @@ -86,10 +137,4 @@ public static function abstractUrlProvider(): array
],
];
}

public function testUrlGenerationOfInvalidUrlReturnsInput(): void
{
$urlGenerator = new UrlGenerator();
self::assertSame('tcp://hostname:port', $urlGenerator->generateUrl('tcp://hostname:port'));
}
}

0 comments on commit 87c803b

Please sign in to comment.