diff --git a/composer.json b/composer.json index e77f8ab..0da00d8 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/tests/Integration/CompilerTest.php b/tests/Integration/CompilerTest.php index 2c97df7..f251f27 100644 --- a/tests/Integration/CompilerTest.php +++ b/tests/Integration/CompilerTest.php @@ -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; @@ -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 @@ -110,6 +112,32 @@ public function testDefaultCompilerResult(): void ); } + public function testComponentLayoutSlot(): void + { + static::assertEquals( + '' . PHP_EOL . + '
'. PHP_EOL . + ' foo Bar' . PHP_EOL . + ' boop' . PHP_EOL . + '
'. PHP_EOL . + '
' . PHP_EOL , + $this->renderTemplate( 'using-component-layout') + ); + } + + public function testComponentLayoutSlotDefaultCompiler(): void + { + static::assertEquals( + '' . PHP_EOL . + '
'. PHP_EOL . + ' foo Bar' . PHP_EOL . + ' boop' . PHP_EOL . + '
'. PHP_EOL . + '
' . PHP_EOL , + $this->renderTemplate( 'using-component-layout', [], false) + ); + } + private function renderTemplate(string $viewName, array $templateData = [], $useIndentedCompiler = true): string { $fileSystem = new Filesystem(); @@ -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;}); @@ -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. } diff --git a/tests/Integration/Component/layout.php b/tests/Integration/Component/layout.php new file mode 100644 index 0000000..532eb0b --- /dev/null +++ b/tests/Integration/Component/layout.php @@ -0,0 +1,14 @@ + +
+ {{ $slot }} +
+ diff --git a/tests/Integration/fixtures/using-component-layout.blade.php b/tests/Integration/fixtures/using-component-layout.blade.php new file mode 100644 index 0000000..bf13ba9 --- /dev/null +++ b/tests/Integration/fixtures/using-component-layout.blade.php @@ -0,0 +1,4 @@ + + foo Bar + boop + \ No newline at end of file