Skip to content

Commit

Permalink
Refactor to move Blade mocks into closure
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jun 26, 2024
1 parent 5e7869f commit 4868497
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions packages/framework/tests/Unit/IncludesFacadeUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,31 +157,31 @@ public function testMarkdownWithAndWithoutExtension()
public function testBladeReturnsRenderedPartial()
{
$filename = 'foo.blade.php';
$content = '{{ "foo bar" }}';
$expected = 'foo bar';

$this->mockFilesystem(function ($filesystem) use ($content, $filename) {
$this->mockFilesystem(function ($filesystem) use ($expected, $filename) {
$content = '{{ "foo bar" }}';
$filesystem->shouldReceive('exists')->with(Hyde::path('resources/includes/'.$filename))->andReturn(true);
$filesystem->shouldReceive('get')->with(Hyde::path('resources/includes/'.$filename))->andReturn($content);
});

Blade::shouldReceive('render')->with($content)->andReturn($expected);
Blade::shouldReceive('render')->with($content)->andReturn($expected);
});

$this->assertSame($expected, Includes::blade($filename));
}

public function testBladeWithAndWithoutExtension()
{
$content = '{{ "foo bar" }}';
$expected = 'foo bar';

$this->mockFilesystem(function ($filesystem) use ($content) {
$this->mockFilesystem(function ($filesystem) {
$expected = 'foo bar';
$content = '{{ "foo bar" }}';
$filename = 'foo.blade.php';
$filesystem->shouldReceive('exists')->with(Hyde::path('resources/includes/'.$filename))->andReturn(true);
$filesystem->shouldReceive('get')->with(Hyde::path('resources/includes/'.$filename))->andReturn($content);
});

Blade::shouldReceive('render')->with($content)->andReturn($expected);
Blade::shouldReceive('render')->with($content)->andReturn($expected);
});

$this->assertSame(Includes::blade('foo.blade.php'), Includes::blade('foo'));
}
Expand All @@ -192,12 +192,11 @@ public function testBladeReturnsDefaultValueWhenNotFound()
$default = '{{ "default" }}';
$expected = 'default';

$this->mockFilesystem(function ($filesystem) use ($filename) {
$this->mockFilesystem(function ($filesystem) use ($default, $expected, $filename) {
$filesystem->shouldReceive('exists')->with(Hyde::path('resources/includes/'.$filename))->andReturn(false);
Blade::shouldReceive('render')->with($default)->andReturn($expected);
});

Blade::shouldReceive('render')->with($default)->andReturn($expected);

$this->assertNull(Includes::blade($filename));
$this->assertSame($expected, Includes::blade($filename, $default));
}
Expand Down

0 comments on commit 4868497

Please sign in to comment.