From 608dcf080a3878a9978a83c0dcb5f2c5c8b2038d Mon Sep 17 00:00:00 2001 From: Frank Prins <25006490+PrinsFrank@users.noreply.github.com> Date: Wed, 23 Feb 2022 20:43:59 +0100 Subject: [PATCH 1/2] Add reproduction for component indenting --- composer.json | 3 +- tests/Integration/CompilerTest.php | 37 +++++++++++++++++++ tests/Integration/Component/layout.php | 14 +++++++ tests/Integration/composer.json | 7 ++++ .../fixtures/components/layout.blade.php | 5 +++ .../fixtures/using-component-layout.blade.php | 4 ++ 6 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/Integration/Component/layout.php create mode 100644 tests/Integration/composer.json create mode 100644 tests/Integration/fixtures/components/layout.blade.php create mode 100644 tests/Integration/fixtures/using-component-layout.blade.php diff --git a/composer.json b/composer.json index e77f8ab..fa0b63f 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "php": "^7.2 || ^8.0", "ext-json": "*", "illuminate/support": "^8.0", - "illuminate/view": "^8.0" + "illuminate/view": "^8.0", + "laravel/framework": "^8.0" }, "require-dev": { "phpunit/phpunit": "^8.2", 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 From fb477e237d7c3dcfc7c8d9b51862ab47c61350aa Mon Sep 17 00:00:00 2001 From: Frank Prins <25006490+PrinsFrank@users.noreply.github.com> Date: Wed, 23 Feb 2022 22:06:12 +0100 Subject: [PATCH 2/2] Add laravel framework as a dev dependency because the application needs to be be booted for the services and aliases to be available and the factory being called on the container. --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index fa0b63f..0da00d8 100644 --- a/composer.json +++ b/composer.json @@ -30,12 +30,12 @@ "php": "^7.2 || ^8.0", "ext-json": "*", "illuminate/support": "^8.0", - "illuminate/view": "^8.0", - "laravel/framework": "^8.0" + "illuminate/view": "^8.0" }, "require-dev": { "phpunit/phpunit": "^8.2", - "mockery/mockery": "^1.2" + "mockery/mockery": "^1.2", + "laravel/framework": "^8.0" }, "scripts": { "test": "phpunit",