Skip to content

Commit

Permalink
GTA-463 add easy fake for permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
speckmaier committed Aug 26, 2024
1 parent 2e02adf commit 3a3ce30
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Permalink/Permalink.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public static function fake(PermalinkResolver $permalinkResolver)
self::$permalinkResolver = $permalinkResolver;
}

public static function fakePassthrough()
{
self::$permalinkResolver = new PermalinkPassthroughResolver();
}

public static function fromPostId(int $postId): self
{
$permalink = new static();
Expand Down
13 changes: 13 additions & 0 deletions src/Permalink/PermalinkPassthroughResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace VAF\WP\Framework\Permalink;

class PermalinkPassthroughResolver extends PermalinkResolver
{

public function permalinkForPostId(string $postId): string
{
return "permalink_for_${postId}";
}

}
16 changes: 14 additions & 2 deletions tests/Unit/PermalinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PermalinkTest extends TestCase
/**
* @test
*/
public function should_be_able_to_fake_permalink_before_creating_permalinnk()
public function should_be_able_to_fake_permalink_before_creating_permalink()
{
$resolver = \Mockery::mock(PermalinkResolver::class);
$resolver->shouldReceive('permalinkForPostId')->with(15)->andReturn('expected permalink');
Expand All @@ -26,7 +26,7 @@ public function should_be_able_to_fake_permalink_before_creating_permalinnk()
/**
* @test
*/
public function should_be_able_to_fake_permalink_after_creating_permalinnk()
public function should_be_able_to_fake_permalink_after_creating_permalink()
{
$resolver = \Mockery::mock(PermalinkResolver::class);
$resolver->shouldReceive('permalinkForPostId')->with(15)->andReturn('expected permalink');
Expand All @@ -36,4 +36,16 @@ public function should_be_able_to_fake_permalink_after_creating_permalinnk()

$this->assertEquals('expected permalink', (string)$permalink);
}

/**
* @test
*/
public function should_be_able_to_easily_fake_a_passthrough_url()
{
Permalink::fakePassthrough();

$permalink = Permalink::fromPostId(15);

$this->assertEquals('permalink_for_15', (string)$permalink);
}
}

0 comments on commit 3a3ce30

Please sign in to comment.