Skip to content

Commit 19b8b14

Browse files
committed
Update the Markdown render method to get service from container
This allows it to be mocked in unit tests
1 parent cfb8184 commit 19b8b14

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/framework/src/Markdown/Models/Markdown.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public static function fromFile(string $path): static
9090
*/
9191
public static function render(string $markdown, ?string $pageClass = null): string
9292
{
93-
return (new MarkdownService($markdown, $pageClass))->parse();
93+
return app(MarkdownService::class, [
94+
'markdown' => $markdown,
95+
'pageClass' => $pageClass,
96+
])->parse();
9497
}
9598
}

packages/framework/tests/Unit/MarkdownFacadeTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,27 @@
44

55
namespace Hyde\Framework\Testing\Unit;
66

7+
use Mockery;
78
use Hyde\Testing\UnitTestCase;
89
use Hyde\Markdown\Models\Markdown;
10+
use Hyde\Framework\Services\MarkdownService;
911

1012
/**
1113
* @covers \Hyde\Markdown\Models\Markdown
1214
*/
1315
class MarkdownFacadeTest extends UnitTestCase
1416
{
15-
protected static bool $needsKernel = true;
16-
protected static bool $needsConfig = true;
17-
1817
public function testRender(): void
1918
{
19+
$mock = Mockery::mock(MarkdownService::class);
20+
$mock->shouldReceive('parse')->once()->andReturn("<h1>Hello World!</h1>\n");
21+
app()->bind(MarkdownService::class, fn () => $mock);
22+
2023
$html = Markdown::render('# Hello World!');
2124

2225
$this->assertIsString($html);
2326
$this->assertSame("<h1>Hello World!</h1>\n", $html);
27+
28+
Mockery::close();
2429
}
2530
}

0 commit comments

Comments
 (0)