Skip to content

Commit

Permalink
Update HyperlinkTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
freost committed Oct 28, 2024
1 parent 7cae961 commit 9cb1b5f
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions tests/unit/cli/output/helpers/HyperlinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,23 @@
#[Group('unit')]
class HyperlinkTest extends TestCase
{
/**
*
*/
protected function getHashAndUrl(): array
{
$url = 'https://example.org';

return [hash('xxh128', $url), $url];
}

/**
*
*/
public function testRenderWithHyperlinkSupport(): void
{
[$hash, $url] = $this->getHashAndUrl();

/** @var \mako\cli\output\Output|\Mockery\MockInterface $output */
$output = Mockery::mock(Output::class);

Expand All @@ -33,20 +45,22 @@ public function testRenderWithHyperlinkSupport(): void

$hyperlink->shouldReceive('hasHyperlinkSupport')->andReturn(true);

$link1 = $hyperlink->render('https://example.org');
$link1 = $hyperlink->render($url);

$link2 = $hyperlink->render('https://example.org', 'Example');
$link2 = $hyperlink->render($url, 'Example');

$this->assertSame("\033]8;id=a7e05a2cf451704d0710759e269cbc8a;https://example.org\033\\https://example.org\033]8;;\033\\", $link1);
$this->assertSame("\033]8;id={$hash};{$url}\033\\{$url}\033]8;;\033\\", $link1);

$this->assertSame("\033]8;id=a7e05a2cf451704d0710759e269cbc8a;https://example.org\033\\Example\033]8;;\033\\", $link2);
$this->assertSame("\033]8;id={$hash};{$url}\033\\Example\033]8;;\033\\", $link2);
}

/**
*
*/
public function testRenderWithoutHyperlinkSupport(): void
{
[, $url] = $this->getHashAndUrl();

/** @var \mako\cli\output\Output|\Mockery\MockInterface $output */
$output = Mockery::mock(Output::class);

Expand All @@ -59,26 +73,28 @@ public function testRenderWithoutHyperlinkSupport(): void

$hyperlink->shouldReceive('hasHyperlinkSupport')->andReturn(false);

$link1 = $hyperlink->render('https://example.org');
$link1 = $hyperlink->render($url);

$link2 = $hyperlink->render('https://example.org', 'Example');
$link2 = $hyperlink->render($url, 'Example');

$this->assertSame('https://example.org', $link1);
$this->assertSame($url, $link1);

$this->assertSame('Example (https://example.org)', $link2);
$this->assertSame("Example ({$url})", $link2);
}

/**
*
*/
public function testDrawWithHyperlinkSupport(): void
{
[$hash, $url] = $this->getHashAndUrl();

/** @var \mako\cli\output\Output|\Mockery\MockInterface $output */
$output = Mockery::mock(Output::class);

$output->shouldReceive('write')->once()->with("\033]8;id=a7e05a2cf451704d0710759e269cbc8a;https://example.org\033\\https://example.org\033]8;;\033\\", 1);
$output->shouldReceive('write')->once()->with("\033]8;id={$hash};{$url}\033\\{$url}\033]8;;\033\\", 1);

$output->shouldReceive('write')->once()->with("\033]8;id=a7e05a2cf451704d0710759e269cbc8a;https://example.org\033\\Example\033]8;;\033\\", 1);
$output->shouldReceive('write')->once()->with("\033]8;id={$hash};{$url}\033\\Example\033]8;;\033\\", 1);

/** @var \mako\cli\output\helpers\Hyperlink|\Mockery\MockInterface $hyperlink */
$hyperlink = Mockery::mock(Hyperlink::class, [$output]);
Expand All @@ -89,22 +105,24 @@ public function testDrawWithHyperlinkSupport(): void

$hyperlink->shouldReceive('hasHyperlinkSupport')->andReturn(true);

$hyperlink->draw('https://example.org');
$hyperlink->draw($url);

$hyperlink->draw('https://example.org', 'Example');
$hyperlink->draw($url, 'Example');
}

/**
*
*/
public function testDrawWithoutHyperlinkSupport(): void
{
[, $url] = $this->getHashAndUrl();

/** @var \mako\cli\output\Output|\Mockery\MockInterface $output */
$output = Mockery::mock(Output::class);

$output->shouldReceive('write')->once()->with('https://example.org', 1);
$output->shouldReceive('write')->once()->with($url, 1);

$output->shouldReceive('write')->once()->with('Example (https://example.org)', 1);
$output->shouldReceive('write')->once()->with("Example ({$url})", 1);

/** @var \mako\cli\output\helpers\Hyperlink|\Mockery\MockInterface $hyperlink */
$hyperlink = Mockery::mock(Hyperlink::class, [$output]);
Expand All @@ -115,8 +133,8 @@ public function testDrawWithoutHyperlinkSupport(): void

$hyperlink->shouldReceive('hasHyperlinkSupport')->andReturn(false);

$hyperlink->draw('https://example.org');
$hyperlink->draw($url);

$hyperlink->draw('https://example.org', 'Example');
$hyperlink->draw($url, 'Example');
}
}

0 comments on commit 9cb1b5f

Please sign in to comment.