Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
},
"require-dev": {
"phpunit/phpunit": "^8.2",
"mockery/mockery": "^1.2"
"mockery/mockery": "^1.2",
"laravel/framework": "^8.0"
},
"scripts": {
"test": "phpunit",
Expand Down
37 changes: 37 additions & 0 deletions tests/Integration/CompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PrinsFrank\IndentingPersistentBladeCompiler\Tests\Integration;

use Illuminate\Container\Container;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Events\Dispatcher;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\Engines\CompilerEngine;
Expand All @@ -14,6 +15,7 @@
use PHPUnit\Framework\TestCase;
use PrinsFrank\IndentingPersistentBladeCompiler\Compilers\IndentedBladeCompiler;
use PrinsFrank\IndentingPersistentBladeCompiler\IndentedViewFactory;
use PrinsFrank\IndentingPersistentBladeCompiler\Tests\Integration\Component\layout;

/**
* @coversNothing
Expand Down Expand Up @@ -110,6 +112,32 @@ public function testDefaultCompilerResult(): void
);
}

public function testComponentLayoutSlot(): void
{
static::assertEquals(
'<layout>' . PHP_EOL .
' <main>'. PHP_EOL .
' foo Bar' . PHP_EOL .
' boop' . PHP_EOL .
' </main>'. PHP_EOL .
'</layout>' . PHP_EOL ,
$this->renderTemplate( 'using-component-layout')
);
}

public function testComponentLayoutSlotDefaultCompiler(): void
{
static::assertEquals(
'<layout>' . PHP_EOL .
' <main>'. PHP_EOL .
' foo Bar' . PHP_EOL .
' boop' . PHP_EOL .
' </main>'. PHP_EOL .
'</layout>' . PHP_EOL ,
$this->renderTemplate( 'using-component-layout', [], false)
);
}

private function renderTemplate(string $viewName, array $templateData = [], $useIndentedCompiler = true): string
{
$fileSystem = new Filesystem();
Expand All @@ -119,6 +147,8 @@ private function renderTemplate(string $viewName, array $templateData = [], $use
$bladeCompiler = new BladeCompiler($fileSystem, self::PATH_OUT);
}

$bladeCompiler->component(layout::class, 'layout');

$viewResolver = new EngineResolver();
$viewResolver->register('blade', function () use ($bladeCompiler) {return new CompilerEngine($bladeCompiler);});
$viewResolver->register('php', function () {return new PhpEngine;});
Expand All @@ -129,6 +159,13 @@ private function renderTemplate(string $viewName, array $templateData = [], $use
$viewFactory = new Factory($viewResolver, new FileViewFinder($fileSystem, self::TEMPLATE_PATHS), new Dispatcher(new Container()));
}

$container = new Container();
$container->instance(Factory::class, $viewFactory);
$container->bind(\Illuminate\Contracts\View\Factory::class, static function () use ($viewFactory) { return $viewFactory; });
$container->bind(Application::class, static function () {return (new \Illuminate\Foundation\Application(__DIR__))->useAppPath(__DIR__);});
Container::setInstance($container);
$viewFactory->setContainer($container);

$renderedTemplate = $viewFactory->make($viewName, $templateData)->render();
return str_replace("\r", "", $renderedTemplate); // newlines are not handled properly on WSL.
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Integration/Component/layout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);

namespace PrinsFrank\IndentingPersistentBladeCompiler\Tests\Integration\Component;

use Illuminate\View\Component;

class layout extends Component
{
public function render()
{
return view('components.layout');
}
}
7 changes: 7 additions & 0 deletions tests/Integration/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"autoload": {
"psr-4": {
"PrinsFrank\\IndentingPersistentBladeCompiler\\Tests\\Integration\\fixtures\\Component\\": ""
}
}
}
5 changes: 5 additions & 0 deletions tests/Integration/fixtures/components/layout.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<layout>
<main>
{{ $slot }}
</main>
</layout>
4 changes: 4 additions & 0 deletions tests/Integration/fixtures/using-component-layout.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<x-layout>
foo Bar
boop
</x-layout>