From 8e8331427984bab2888c0b221730b787168a36b3 Mon Sep 17 00:00:00 2001 From: Filip Ganyicz Date: Sun, 1 Mar 2026 19:58:02 +0100 Subject: [PATCH 1/6] Add failing test --- tests/BladeServiceTest.php | 21 +++++++++++++++++++ .../components/dummy/bar/index.blade.php | 0 .../components/dummy/baz/baz.blade.php | 0 tests/fixtures/components/dummy/foo.blade.php | 0 4 files changed, 21 insertions(+) create mode 100644 tests/BladeServiceTest.php create mode 100644 tests/fixtures/components/dummy/bar/index.blade.php create mode 100644 tests/fixtures/components/dummy/baz/baz.blade.php create mode 100644 tests/fixtures/components/dummy/foo.blade.php diff --git a/tests/BladeServiceTest.php b/tests/BladeServiceTest.php new file mode 100644 index 00000000..c27ffa46 --- /dev/null +++ b/tests/BladeServiceTest.php @@ -0,0 +1,21 @@ +componentNameToPath($prefix . $name))->toBe($path); +}) +->with([ + 'default path' => [fn () => null, 'dummy.'], + 'custom path' => [fn () => Blade::anonymousComponentPath(fixture_path('components/dummy')), ''], + 'custom path with prefix' => [fn () => Blade::anonymousComponentPath(fixture_path('components/dummy'), 'dummy'), 'dummy::'], + 'custom namespace' => [fn () => Blade::anonymousComponentNamespace('dummy'), 'dummy::'], +]) +->with([ + 'exact file' => ['foo', fixture_path('components/dummy/foo.blade.php')], + 'index file' => ['bar', fixture_path('components/dummy/bar/index.blade.php')], + 'directory name' => ['baz', fixture_path('components/dummy/baz/baz.blade.php')], +]); \ No newline at end of file diff --git a/tests/fixtures/components/dummy/bar/index.blade.php b/tests/fixtures/components/dummy/bar/index.blade.php new file mode 100644 index 00000000..e69de29b diff --git a/tests/fixtures/components/dummy/baz/baz.blade.php b/tests/fixtures/components/dummy/baz/baz.blade.php new file mode 100644 index 00000000..e69de29b diff --git a/tests/fixtures/components/dummy/foo.blade.php b/tests/fixtures/components/dummy/foo.blade.php new file mode 100644 index 00000000..e69de29b From 7d69b01291b557f92aa8aa33b0b62f821c70b061 Mon Sep 17 00:00:00 2001 From: Filip Ganyicz Date: Wed, 4 Mar 2026 23:51:30 +0100 Subject: [PATCH 2/6] Refactor componentNameToPath --- src/BladeService.php | 94 ++++++++------------------------------ tests/BladeServiceTest.php | 2 +- 2 files changed, 20 insertions(+), 76 deletions(-) diff --git a/src/BladeService.php b/src/BladeService.php index 643d884c..afb1ca28 100644 --- a/src/BladeService.php +++ b/src/BladeService.php @@ -6,6 +6,7 @@ use Illuminate\Support\Str; use Illuminate\View\Compilers\BladeCompiler; use Illuminate\View\Compilers\ComponentTagCompiler; +use Illuminate\View\Factory; use Livewire\Blaze\Compiler\DirectiveCompiler; use Livewire\Blaze\Support\LaravelRegex; use ReflectionClass; @@ -194,87 +195,30 @@ public function viewCacheInvalidationHook(callable $callback): void */ public function componentNameToPath($name): string { - $viewFinder = app('view')->getFinder(); + $viewFactory = app('view'); + $viewFinder = $viewFactory->getFinder(); - $reflection = new \ReflectionClass($this->compiler); - $pathsProperty = $reflection->getProperty('anonymousComponentPaths'); - $paths = $pathsProperty->getValue($this->compiler) ?? []; - - if (str_contains($name, '::')) { - [$namespace, $componentName] = explode('::', $name, 2); - $componentPath = str_replace('.', '/', $componentName); - - foreach ($paths as $pathData) { - if (isset($pathData['prefix']) && $pathData['prefix'] === $namespace) { - $basePath = rtrim($pathData['path'], '/'); - - $fullPath = $basePath.'/'.$componentPath.'.blade.php'; - if (file_exists($fullPath)) { - return $fullPath; - } - - $indexPath = $basePath.'/'.$componentPath.'/index.blade.php'; - if (file_exists($indexPath)) { - return $indexPath; - } - - $lastSegment = basename($componentPath); - $sameNamePath = $basePath.'/'.$componentPath.'/'.$lastSegment.'.blade.php'; - if (file_exists($sameNamePath)) { - return $sameNamePath; - } - } - } - - try { - $viewName = str_replace('::', '::components.', $name); - return $viewFinder->find($viewName); - } catch (\Exception $e) { - try { - return $viewFinder->find(str_replace('::', '::components.', $name).'.index'); - } catch (\Exception $e2) { - return ''; - } - } + if (! is_null($guess = $this->guessAnonymousComponentUsingNamespaces($viewFactory, $name)) || + ! is_null($guess = $this->guessAnonymousComponentUsingPaths($viewFactory, $name))) { + return $viewFinder->find($guess); } - $componentPath = str_replace('.', '/', $name); - - foreach ($paths as $pathData) { - if (! isset($pathData['prefix']) || $pathData['prefix'] === null) { - $registeredPath = $pathData['path'] ?? $pathData; - - if (is_string($registeredPath)) { - $basePath = rtrim($registeredPath, '/'); + return ''; + } - $fullPath = $basePath.'/'.$componentPath.'.blade.php'; - if (file_exists($fullPath)) { - return $fullPath; - } + protected function guessAnonymousComponentUsingNamespaces(Factory $viewFactory, string $component): string|null + { + $reflection = new \ReflectionClass($this->tagCompiler); + $method = $reflection->getMethod('guessAnonymousComponentUsingNamespaces'); - $indexPath = $basePath.'/'.$componentPath.'/index.blade.php'; - if (file_exists($indexPath)) { - return $indexPath; - } + return $method->invoke($this->tagCompiler, $viewFactory, $component); + } - $lastSegment = basename($componentPath); - $sameNamePath = $basePath.'/'.$componentPath.'/'.$lastSegment.'.blade.php'; - if (file_exists($sameNamePath)) { - return $sameNamePath; - } - } - } - } + protected function guessAnonymousComponentUsingPaths(Factory $viewFactory, string $component): string|null + { + $reflection = new \ReflectionClass($this->tagCompiler); + $method = $reflection->getMethod('guessAnonymousComponentUsingPaths'); - try { - return $viewFinder->find("components.{$name}"); - } catch (\Exception $e) { - try { - return $viewFinder->find("components.{$name}.index"); - } catch (\Exception $e2) { - return ''; - } - } + return $method->invoke($this->tagCompiler, $viewFactory, $component); } - } diff --git a/tests/BladeServiceTest.php b/tests/BladeServiceTest.php index c27ffa46..6f14df3f 100644 --- a/tests/BladeServiceTest.php +++ b/tests/BladeServiceTest.php @@ -12,7 +12,7 @@ 'default path' => [fn () => null, 'dummy.'], 'custom path' => [fn () => Blade::anonymousComponentPath(fixture_path('components/dummy')), ''], 'custom path with prefix' => [fn () => Blade::anonymousComponentPath(fixture_path('components/dummy'), 'dummy'), 'dummy::'], - 'custom namespace' => [fn () => Blade::anonymousComponentNamespace('dummy'), 'dummy::'], + // 'custom namespace' => [fn () => Blade::anonymousComponentNamespace('dummy'), 'dummy::'], ]) ->with([ 'exact file' => ['foo', fixture_path('components/dummy/foo.blade.php')], From 123cbb6bfc2044cf905e2b3bed099d8114d62233 Mon Sep 17 00:00:00 2001 From: Filip Ganyicz Date: Thu, 5 Mar 2026 20:14:36 +0100 Subject: [PATCH 3/6] Move fixtures --- tests/BladeServiceTest.php | 10 +++++----- tests/Compiler/CompilerTest.php | 4 ++-- tests/Compiler/WrapperTest.php | 4 ++-- tests/Folder/FoldableTest.php | 20 +++++++++---------- tests/Folder/FolderTest.php | 4 ++-- tests/Folder/UnblazeTest.php | 6 +++--- tests/Memoizer/MemoizerTest.php | 4 ++-- tests/TestCase.php | 2 +- .../{ => views}/components/card.blade.php | 0 .../components/dummy/bar/index.blade.php | 0 .../components/dummy/baz/baz.blade.php | 0 .../components/dummy/foo.blade.php | 0 .../foldable/card-unsafe-slot.blade.php | 0 .../components/foldable/card-unsafe.blade.php | 0 .../components/foldable/card.blade.php | 0 .../components/foldable/input-aware.blade.php | 0 .../foldable/input-no-blaze.blade.php | 0 .../components/foldable/input-safe.blade.php | 0 .../foldable/input-unblaze.blade.php | 0 .../input-unsafe-attributes.blade.php | 0 .../foldable/input-unsafe.blade.php | 0 .../components/foldable/input.blade.php | 0 .../foldable/nested-input-unblaze.blade.php | 0 .../foldable/unblaze-only-wrapper.blade.php | 0 .../foldable/unblaze-only.blade.php | 0 .../foldable/unblaze-slot-wrapper.blade.php | 0 .../components/foldable/wrapper-nl.blade.php | 0 .../components/foldable/wrapper.blade.php | 0 .../components/input-aware-no-blaze.blade.php | 0 .../components/input-aware.blade.php | 0 .../components/input-no-blaze.blade.php | 0 .../{ => views}/components/input.blade.php | 0 .../invalid-foldable/auth.blade.php | 0 .../invalid-foldable/csrf.blade.php | 0 .../invalid-foldable/error.blade.php | 0 .../invalid-foldable/errors.blade.php | 0 .../components/invalid-foldable/old.blade.php | 0 .../invalid-foldable/once.blade.php | 0 .../invalid-foldable/request.blade.php | 0 .../invalid-foldable/session.blade.php | 0 .../memoizable/avatar-no-blaze.blade.php | 0 .../components/memoizable/avatar.blade.php | 0 42 files changed, 27 insertions(+), 27 deletions(-) rename tests/fixtures/{ => views}/components/card.blade.php (100%) rename tests/fixtures/{ => views}/components/dummy/bar/index.blade.php (100%) rename tests/fixtures/{ => views}/components/dummy/baz/baz.blade.php (100%) rename tests/fixtures/{ => views}/components/dummy/foo.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/card-unsafe-slot.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/card-unsafe.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/card.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/input-aware.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/input-no-blaze.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/input-safe.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/input-unblaze.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/input-unsafe-attributes.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/input-unsafe.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/input.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/nested-input-unblaze.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/unblaze-only-wrapper.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/unblaze-only.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/unblaze-slot-wrapper.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/wrapper-nl.blade.php (100%) rename tests/fixtures/{ => views}/components/foldable/wrapper.blade.php (100%) rename tests/fixtures/{ => views}/components/input-aware-no-blaze.blade.php (100%) rename tests/fixtures/{ => views}/components/input-aware.blade.php (100%) rename tests/fixtures/{ => views}/components/input-no-blaze.blade.php (100%) rename tests/fixtures/{ => views}/components/input.blade.php (100%) rename tests/fixtures/{ => views}/components/invalid-foldable/auth.blade.php (100%) rename tests/fixtures/{ => views}/components/invalid-foldable/csrf.blade.php (100%) rename tests/fixtures/{ => views}/components/invalid-foldable/error.blade.php (100%) rename tests/fixtures/{ => views}/components/invalid-foldable/errors.blade.php (100%) rename tests/fixtures/{ => views}/components/invalid-foldable/old.blade.php (100%) rename tests/fixtures/{ => views}/components/invalid-foldable/once.blade.php (100%) rename tests/fixtures/{ => views}/components/invalid-foldable/request.blade.php (100%) rename tests/fixtures/{ => views}/components/invalid-foldable/session.blade.php (100%) rename tests/fixtures/{ => views}/components/memoizable/avatar-no-blaze.blade.php (100%) rename tests/fixtures/{ => views}/components/memoizable/avatar.blade.php (100%) diff --git a/tests/BladeServiceTest.php b/tests/BladeServiceTest.php index 6f14df3f..2cd0fd81 100644 --- a/tests/BladeServiceTest.php +++ b/tests/BladeServiceTest.php @@ -10,12 +10,12 @@ }) ->with([ 'default path' => [fn () => null, 'dummy.'], - 'custom path' => [fn () => Blade::anonymousComponentPath(fixture_path('components/dummy')), ''], - 'custom path with prefix' => [fn () => Blade::anonymousComponentPath(fixture_path('components/dummy'), 'dummy'), 'dummy::'], + 'custom path' => [fn () => Blade::anonymousComponentPath(fixture_path('views/components/dummy')), ''], + 'custom path with prefix' => [fn () => Blade::anonymousComponentPath(fixture_path('views/components/dummy'), 'dummy'), 'dummy::'], // 'custom namespace' => [fn () => Blade::anonymousComponentNamespace('dummy'), 'dummy::'], ]) ->with([ - 'exact file' => ['foo', fixture_path('components/dummy/foo.blade.php')], - 'index file' => ['bar', fixture_path('components/dummy/bar/index.blade.php')], - 'directory name' => ['baz', fixture_path('components/dummy/baz/baz.blade.php')], + 'exact file' => ['foo', fixture_path('views/components/dummy/foo.blade.php')], + 'index file' => ['bar', fixture_path('views/components/dummy/bar/index.blade.php')], + 'directory name' => ['baz', fixture_path('views/components/dummy/baz/baz.blade.php')], ]); \ No newline at end of file diff --git a/tests/Compiler/CompilerTest.php b/tests/Compiler/CompilerTest.php index f421a17c..28e9231f 100644 --- a/tests/Compiler/CompilerTest.php +++ b/tests/Compiler/CompilerTest.php @@ -10,7 +10,7 @@ $node = app(Parser::class)->parse($input)[0]; $compiled = app(Compiler::class)->compile($node); - $path = fixture_path('components/input.blade.php'); + $path = fixture_path('views/components/input.blade.php'); $hash = Utils::hash($path); expect($compiled->render())->toEqualCollapsingWhitespace(join('', [ @@ -39,7 +39,7 @@ $node = app(Parser::class)->parse($input)[0]; $compiled = app(Compiler::class)->compile($node); - $path = fixture_path('components/card.blade.php'); + $path = fixture_path('views/components/card.blade.php'); $hash = Utils::hash($path); expect($compiled->render())->toEqualCollapsingWhitespace(join('', [ diff --git a/tests/Compiler/WrapperTest.php b/tests/Compiler/WrapperTest.php index 4ad22991..e806c649 100644 --- a/tests/Compiler/WrapperTest.php +++ b/tests/Compiler/WrapperTest.php @@ -6,7 +6,7 @@ use Livewire\Blaze\BladeService; test('wraps component templates into function definitions', function () { - $path = fixture_path('components/input.blade.php'); + $path = fixture_path('views/components/input.blade.php'); $source = file_get_contents($path); $hash = Utils::hash($path); @@ -31,7 +31,7 @@ }); test('compiles aware props', function () { - $path = fixture_path('components/input-aware.blade.php'); + $path = fixture_path('views/components/input-aware.blade.php'); $source = file_get_contents($path); $hash = Utils::hash($path); diff --git a/tests/Folder/FoldableTest.php b/tests/Folder/FoldableTest.php index 1ab8e1fc..9d848702 100644 --- a/tests/Folder/FoldableTest.php +++ b/tests/Folder/FoldableTest.php @@ -11,7 +11,7 @@ $input = ''; $node = app(Parser::class)->parse($input)[0]; - $foldable = new Foldable($node, new ComponentSource(fixture_path('components/foldable/input.blade.php')), app(BladeRenderer::class), app(BladeService::class)); + $foldable = new Foldable($node, new ComponentSource(fixture_path('views/components/foldable/input.blade.php')), app(BladeRenderer::class), app(BladeService::class)); expect($foldable->fold())->toEqualCollapsingWhitespace( '' @@ -35,7 +35,7 @@ ; $node = app(Parser::class)->parse($input)[0]; - $foldable = new Foldable($node, new ComponentSource(fixture_path('components/foldable/card.blade.php')), app(BladeRenderer::class), app(BladeService::class)); + $foldable = new Foldable($node, new ComponentSource(fixture_path('views/components/foldable/card.blade.php')), app(BladeRenderer::class), app(BladeService::class)); expect($foldable->fold())->toEqualCollapsingWhitespace(<<<'HTML'
@@ -53,7 +53,7 @@ $input = ''; $node = app(Parser::class)->parse($input)[0]; - $foldable = new Foldable($node, new ComponentSource(fixture_path('components/foldable/input.blade.php')), app(BladeRenderer::class), app(BladeService::class)); + $foldable = new Foldable($node, new ComponentSource(fixture_path('views/components/foldable/input.blade.php')), app(BladeRenderer::class), app(BladeService::class)); expect($foldable->fold())->toEqualCollapsingWhitespace( '' @@ -64,7 +64,7 @@ $input = ''; $node = app(Parser::class)->parse($input)[0]; - $foldable = new Foldable($node, new ComponentSource(fixture_path('components/foldable/input.blade.php')), app(BladeRenderer::class), app(BladeService::class)); + $foldable = new Foldable($node, new ComponentSource(fixture_path('views/components/foldable/input.blade.php')), app(BladeRenderer::class), app(BladeService::class)); expect($foldable->fold())->toEqualCollapsingWhitespace( '' @@ -75,7 +75,7 @@ $input = ''; $node = app(Parser::class)->parse($input)[0]; - $foldable = new Foldable($node, new ComponentSource(fixture_path('components/foldable/input-aware.blade.php')), app(BladeRenderer::class), app(BladeService::class)); + $foldable = new Foldable($node, new ComponentSource(fixture_path('views/components/foldable/input-aware.blade.php')), app(BladeRenderer::class), app(BladeService::class)); $node->setParentsAttributes([ 'type' => new Attribute( @@ -106,7 +106,7 @@ ), ]); - $foldable = new Foldable($node, new ComponentSource(fixture_path('components/foldable/input-aware.blade.php')), app(BladeRenderer::class), app(BladeService::class)); + $foldable = new Foldable($node, new ComponentSource(fixture_path('views/components/foldable/input-aware.blade.php')), app(BladeRenderer::class), app(BladeService::class)); expect($foldable->fold())->toEqualCollapsingWhitespace( '' @@ -117,7 +117,7 @@ $input = ''; $node = app(Parser::class)->parse($input)[0]; - $foldable = new Foldable($node, new ComponentSource(fixture_path('components/foldable/input.blade.php')), app(BladeRenderer::class), app(BladeService::class)); + $foldable = new Foldable($node, new ComponentSource(fixture_path('views/components/foldable/input.blade.php')), app(BladeRenderer::class), app(BladeService::class)); expect($foldable->fold())->toEqualCollapsingWhitespace( sprintf('', join('', [ @@ -134,7 +134,7 @@ $node = app(Parser::class)->parse($input)[0]; $node->hasAwareDescendants = true; - $foldable = new Foldable($node, new ComponentSource(fixture_path('components/foldable/card.blade.php')), app(BladeRenderer::class), app(BladeService::class)); + $foldable = new Foldable($node, new ComponentSource(fixture_path('views/components/foldable/card.blade.php')), app(BladeRenderer::class), app(BladeService::class)); expect($foldable->fold())->toEqualCollapsingWhitespace(join('', [ 'pushData([\'name\' => \'John\']); $__env->pushConsumableComponentData([\'name\' => \'John\']); ?>', @@ -149,7 +149,7 @@ $node = app(Parser::class)->parse($input)[0]; $node->hasAwareDescendants = true; - $foldable = new Foldable($node, new ComponentSource(fixture_path('components/foldable/card.blade.php')), app(BladeRenderer::class), app(BladeService::class)); + $foldable = new Foldable($node, new ComponentSource(fixture_path('views/components/foldable/card.blade.php')), app(BladeRenderer::class), app(BladeService::class)); expect($foldable->fold())->toEqualCollapsingWhitespace(join('', [ 'pushData([\'name\' => $name]); $__env->pushConsumableComponentData([\'name\' => $name]); ?>', @@ -164,7 +164,7 @@ $node = app(Parser::class)->parse($input)[0]; $node->hasAwareDescendants = true; - $foldable = new Foldable($node, new ComponentSource(fixture_path('components/foldable/card.blade.php')), app(BladeRenderer::class), app(BladeService::class)); + $foldable = new Foldable($node, new ComponentSource(fixture_path('views/components/foldable/card.blade.php')), app(BladeRenderer::class), app(BladeService::class)); expect($foldable->fold())->toEqualCollapsingWhitespace(join('', [ 'pushData([\'name\' => \'Mr. \'.e($name)]); $__env->pushConsumableComponentData([\'name\' => \'Mr. \'.e($name)]); ?>', diff --git a/tests/Folder/FolderTest.php b/tests/Folder/FolderTest.php index 6c951faa..b7f74f06 100644 --- a/tests/Folder/FolderTest.php +++ b/tests/Folder/FolderTest.php @@ -210,7 +210,7 @@ test('folds components with no blaze directive if enabled in config', function () { $input = ''; - app(Config::class)->add(fixture_path('components/foldable'), fold: true); + app(Config::class)->add(fixture_path('views/components/foldable'), fold: true); $node = app(Parser::class)->parse($input)[0]; $folded = app(Folder::class)->fold($node); @@ -221,7 +221,7 @@ test('folds components with blaze directive even if disabled in config', function () { $input = ''; - app(Config::class)->add(fixture_path('components/foldable'), fold: false); + app(Config::class)->add(fixture_path('views/components/foldable'), fold: false); $node = app(Parser::class)->parse($input)[0]; $folded = app(Folder::class)->fold($node); diff --git a/tests/Folder/UnblazeTest.php b/tests/Folder/UnblazeTest.php index 07d54133..508548e4 100644 --- a/tests/Folder/UnblazeTest.php +++ b/tests/Folder/UnblazeTest.php @@ -10,7 +10,7 @@ $input = ''; $node = app(Parser::class)->parse($input)[0]; - $foldable = new Foldable($node, new ComponentSource(fixture_path('components/foldable/input-unblaze.blade.php')), app(BladeRenderer::class), app(BladeService::class)); + $foldable = new Foldable($node, new ComponentSource(fixture_path('views/components/foldable/input-unblaze.blade.php')), app(BladeRenderer::class), app(BladeService::class)); expect($foldable->fold())->toEqualCollapsingWhitespace( sprintf('', join('', [ @@ -26,7 +26,7 @@ $input = ''; $node = app(Parser::class)->parse($input)[0]; - $foldable = new Foldable($node, new ComponentSource(fixture_path('components/foldable/nested-input-unblaze.blade.php')), app(BladeRenderer::class), app(BladeService::class)); + $foldable = new Foldable($node, new ComponentSource(fixture_path('views/components/foldable/nested-input-unblaze.blade.php')), app(BladeRenderer::class), app(BladeService::class)); expect($foldable->fold())->toEqualCollapsingWhitespace( sprintf('
', join('', [ @@ -42,7 +42,7 @@ $input = ''; $node = app(Parser::class)->parse($input)[0]; - $foldable = new Foldable($node, new ComponentSource(fixture_path('components/foldable/input-unblaze.blade.php')), app(BladeRenderer::class), app(BladeService::class)); + $foldable = new Foldable($node, new ComponentSource(fixture_path('views/components/foldable/input-unblaze.blade.php')), app(BladeRenderer::class), app(BladeService::class)); expect($foldable->fold())->toEqualCollapsingWhitespace( sprintf('', join('', [ diff --git a/tests/Memoizer/MemoizerTest.php b/tests/Memoizer/MemoizerTest.php index 672fb70a..911413ff 100644 --- a/tests/Memoizer/MemoizerTest.php +++ b/tests/Memoizer/MemoizerTest.php @@ -13,7 +13,7 @@ $node = app(Parser::class)->parse($input)[0]; $memoized = app(Memoizer::class)->memoize($node); - $path = fixture_path('components/memoizable/avatar.blade.php'); + $path = fixture_path('views/components/memoizable/avatar.blade.php'); $hash = Utils::hash($path); expect($memoized->render())->toEqualCollapsingWhitespace(join('', [ @@ -59,7 +59,7 @@ test('memoizes components without blaze directive if enabled in config', function () { $input = ''; - app(Config::class)->add(fixture_path('components/memoizable'), memo: true); + app(Config::class)->add(fixture_path('views/components/memoizable'), memo: true); $node = app(Parser::class)->parse($input)[0]; $memoized = app(Memoizer::class)->memoize($node); diff --git a/tests/TestCase.php b/tests/TestCase.php index c2cf49a8..ce7a360a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -30,7 +30,7 @@ protected function getEnvironmentSetUp($app) ]); $app['blade.compiler']->anonymousComponentPath( - __DIR__.'/fixtures/components', + __DIR__.'/fixtures/views/components', ); // Isolate compiled view paths for parallel testing to prevent diff --git a/tests/fixtures/components/card.blade.php b/tests/fixtures/views/components/card.blade.php similarity index 100% rename from tests/fixtures/components/card.blade.php rename to tests/fixtures/views/components/card.blade.php diff --git a/tests/fixtures/components/dummy/bar/index.blade.php b/tests/fixtures/views/components/dummy/bar/index.blade.php similarity index 100% rename from tests/fixtures/components/dummy/bar/index.blade.php rename to tests/fixtures/views/components/dummy/bar/index.blade.php diff --git a/tests/fixtures/components/dummy/baz/baz.blade.php b/tests/fixtures/views/components/dummy/baz/baz.blade.php similarity index 100% rename from tests/fixtures/components/dummy/baz/baz.blade.php rename to tests/fixtures/views/components/dummy/baz/baz.blade.php diff --git a/tests/fixtures/components/dummy/foo.blade.php b/tests/fixtures/views/components/dummy/foo.blade.php similarity index 100% rename from tests/fixtures/components/dummy/foo.blade.php rename to tests/fixtures/views/components/dummy/foo.blade.php diff --git a/tests/fixtures/components/foldable/card-unsafe-slot.blade.php b/tests/fixtures/views/components/foldable/card-unsafe-slot.blade.php similarity index 100% rename from tests/fixtures/components/foldable/card-unsafe-slot.blade.php rename to tests/fixtures/views/components/foldable/card-unsafe-slot.blade.php diff --git a/tests/fixtures/components/foldable/card-unsafe.blade.php b/tests/fixtures/views/components/foldable/card-unsafe.blade.php similarity index 100% rename from tests/fixtures/components/foldable/card-unsafe.blade.php rename to tests/fixtures/views/components/foldable/card-unsafe.blade.php diff --git a/tests/fixtures/components/foldable/card.blade.php b/tests/fixtures/views/components/foldable/card.blade.php similarity index 100% rename from tests/fixtures/components/foldable/card.blade.php rename to tests/fixtures/views/components/foldable/card.blade.php diff --git a/tests/fixtures/components/foldable/input-aware.blade.php b/tests/fixtures/views/components/foldable/input-aware.blade.php similarity index 100% rename from tests/fixtures/components/foldable/input-aware.blade.php rename to tests/fixtures/views/components/foldable/input-aware.blade.php diff --git a/tests/fixtures/components/foldable/input-no-blaze.blade.php b/tests/fixtures/views/components/foldable/input-no-blaze.blade.php similarity index 100% rename from tests/fixtures/components/foldable/input-no-blaze.blade.php rename to tests/fixtures/views/components/foldable/input-no-blaze.blade.php diff --git a/tests/fixtures/components/foldable/input-safe.blade.php b/tests/fixtures/views/components/foldable/input-safe.blade.php similarity index 100% rename from tests/fixtures/components/foldable/input-safe.blade.php rename to tests/fixtures/views/components/foldable/input-safe.blade.php diff --git a/tests/fixtures/components/foldable/input-unblaze.blade.php b/tests/fixtures/views/components/foldable/input-unblaze.blade.php similarity index 100% rename from tests/fixtures/components/foldable/input-unblaze.blade.php rename to tests/fixtures/views/components/foldable/input-unblaze.blade.php diff --git a/tests/fixtures/components/foldable/input-unsafe-attributes.blade.php b/tests/fixtures/views/components/foldable/input-unsafe-attributes.blade.php similarity index 100% rename from tests/fixtures/components/foldable/input-unsafe-attributes.blade.php rename to tests/fixtures/views/components/foldable/input-unsafe-attributes.blade.php diff --git a/tests/fixtures/components/foldable/input-unsafe.blade.php b/tests/fixtures/views/components/foldable/input-unsafe.blade.php similarity index 100% rename from tests/fixtures/components/foldable/input-unsafe.blade.php rename to tests/fixtures/views/components/foldable/input-unsafe.blade.php diff --git a/tests/fixtures/components/foldable/input.blade.php b/tests/fixtures/views/components/foldable/input.blade.php similarity index 100% rename from tests/fixtures/components/foldable/input.blade.php rename to tests/fixtures/views/components/foldable/input.blade.php diff --git a/tests/fixtures/components/foldable/nested-input-unblaze.blade.php b/tests/fixtures/views/components/foldable/nested-input-unblaze.blade.php similarity index 100% rename from tests/fixtures/components/foldable/nested-input-unblaze.blade.php rename to tests/fixtures/views/components/foldable/nested-input-unblaze.blade.php diff --git a/tests/fixtures/components/foldable/unblaze-only-wrapper.blade.php b/tests/fixtures/views/components/foldable/unblaze-only-wrapper.blade.php similarity index 100% rename from tests/fixtures/components/foldable/unblaze-only-wrapper.blade.php rename to tests/fixtures/views/components/foldable/unblaze-only-wrapper.blade.php diff --git a/tests/fixtures/components/foldable/unblaze-only.blade.php b/tests/fixtures/views/components/foldable/unblaze-only.blade.php similarity index 100% rename from tests/fixtures/components/foldable/unblaze-only.blade.php rename to tests/fixtures/views/components/foldable/unblaze-only.blade.php diff --git a/tests/fixtures/components/foldable/unblaze-slot-wrapper.blade.php b/tests/fixtures/views/components/foldable/unblaze-slot-wrapper.blade.php similarity index 100% rename from tests/fixtures/components/foldable/unblaze-slot-wrapper.blade.php rename to tests/fixtures/views/components/foldable/unblaze-slot-wrapper.blade.php diff --git a/tests/fixtures/components/foldable/wrapper-nl.blade.php b/tests/fixtures/views/components/foldable/wrapper-nl.blade.php similarity index 100% rename from tests/fixtures/components/foldable/wrapper-nl.blade.php rename to tests/fixtures/views/components/foldable/wrapper-nl.blade.php diff --git a/tests/fixtures/components/foldable/wrapper.blade.php b/tests/fixtures/views/components/foldable/wrapper.blade.php similarity index 100% rename from tests/fixtures/components/foldable/wrapper.blade.php rename to tests/fixtures/views/components/foldable/wrapper.blade.php diff --git a/tests/fixtures/components/input-aware-no-blaze.blade.php b/tests/fixtures/views/components/input-aware-no-blaze.blade.php similarity index 100% rename from tests/fixtures/components/input-aware-no-blaze.blade.php rename to tests/fixtures/views/components/input-aware-no-blaze.blade.php diff --git a/tests/fixtures/components/input-aware.blade.php b/tests/fixtures/views/components/input-aware.blade.php similarity index 100% rename from tests/fixtures/components/input-aware.blade.php rename to tests/fixtures/views/components/input-aware.blade.php diff --git a/tests/fixtures/components/input-no-blaze.blade.php b/tests/fixtures/views/components/input-no-blaze.blade.php similarity index 100% rename from tests/fixtures/components/input-no-blaze.blade.php rename to tests/fixtures/views/components/input-no-blaze.blade.php diff --git a/tests/fixtures/components/input.blade.php b/tests/fixtures/views/components/input.blade.php similarity index 100% rename from tests/fixtures/components/input.blade.php rename to tests/fixtures/views/components/input.blade.php diff --git a/tests/fixtures/components/invalid-foldable/auth.blade.php b/tests/fixtures/views/components/invalid-foldable/auth.blade.php similarity index 100% rename from tests/fixtures/components/invalid-foldable/auth.blade.php rename to tests/fixtures/views/components/invalid-foldable/auth.blade.php diff --git a/tests/fixtures/components/invalid-foldable/csrf.blade.php b/tests/fixtures/views/components/invalid-foldable/csrf.blade.php similarity index 100% rename from tests/fixtures/components/invalid-foldable/csrf.blade.php rename to tests/fixtures/views/components/invalid-foldable/csrf.blade.php diff --git a/tests/fixtures/components/invalid-foldable/error.blade.php b/tests/fixtures/views/components/invalid-foldable/error.blade.php similarity index 100% rename from tests/fixtures/components/invalid-foldable/error.blade.php rename to tests/fixtures/views/components/invalid-foldable/error.blade.php diff --git a/tests/fixtures/components/invalid-foldable/errors.blade.php b/tests/fixtures/views/components/invalid-foldable/errors.blade.php similarity index 100% rename from tests/fixtures/components/invalid-foldable/errors.blade.php rename to tests/fixtures/views/components/invalid-foldable/errors.blade.php diff --git a/tests/fixtures/components/invalid-foldable/old.blade.php b/tests/fixtures/views/components/invalid-foldable/old.blade.php similarity index 100% rename from tests/fixtures/components/invalid-foldable/old.blade.php rename to tests/fixtures/views/components/invalid-foldable/old.blade.php diff --git a/tests/fixtures/components/invalid-foldable/once.blade.php b/tests/fixtures/views/components/invalid-foldable/once.blade.php similarity index 100% rename from tests/fixtures/components/invalid-foldable/once.blade.php rename to tests/fixtures/views/components/invalid-foldable/once.blade.php diff --git a/tests/fixtures/components/invalid-foldable/request.blade.php b/tests/fixtures/views/components/invalid-foldable/request.blade.php similarity index 100% rename from tests/fixtures/components/invalid-foldable/request.blade.php rename to tests/fixtures/views/components/invalid-foldable/request.blade.php diff --git a/tests/fixtures/components/invalid-foldable/session.blade.php b/tests/fixtures/views/components/invalid-foldable/session.blade.php similarity index 100% rename from tests/fixtures/components/invalid-foldable/session.blade.php rename to tests/fixtures/views/components/invalid-foldable/session.blade.php diff --git a/tests/fixtures/components/memoizable/avatar-no-blaze.blade.php b/tests/fixtures/views/components/memoizable/avatar-no-blaze.blade.php similarity index 100% rename from tests/fixtures/components/memoizable/avatar-no-blaze.blade.php rename to tests/fixtures/views/components/memoizable/avatar-no-blaze.blade.php diff --git a/tests/fixtures/components/memoizable/avatar.blade.php b/tests/fixtures/views/components/memoizable/avatar.blade.php similarity index 100% rename from tests/fixtures/components/memoizable/avatar.blade.php rename to tests/fixtures/views/components/memoizable/avatar.blade.php From c5f5cd71528db4178e4f90570f25a44ae1ed74e2 Mon Sep 17 00:00:00 2001 From: Filip Ganyicz Date: Thu, 5 Mar 2026 20:16:27 +0100 Subject: [PATCH 4/6] Fix namespace test --- tests/BladeServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/BladeServiceTest.php b/tests/BladeServiceTest.php index 2cd0fd81..635aa155 100644 --- a/tests/BladeServiceTest.php +++ b/tests/BladeServiceTest.php @@ -12,7 +12,7 @@ 'default path' => [fn () => null, 'dummy.'], 'custom path' => [fn () => Blade::anonymousComponentPath(fixture_path('views/components/dummy')), ''], 'custom path with prefix' => [fn () => Blade::anonymousComponentPath(fixture_path('views/components/dummy'), 'dummy'), 'dummy::'], - // 'custom namespace' => [fn () => Blade::anonymousComponentNamespace('dummy'), 'dummy::'], + 'custom namespace' => [fn () => Blade::anonymousComponentNamespace('components.dummy'), 'dummy::'], ]) ->with([ 'exact file' => ['foo', fixture_path('views/components/dummy/foo.blade.php')], From 0669a37c6b590a6a557e4647a264ec9b9abe2850 Mon Sep 17 00:00:00 2001 From: Filip Ganyicz Date: Thu, 5 Mar 2026 20:17:08 +0100 Subject: [PATCH 5/6] Refactor --- src/BladeService.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/BladeService.php b/src/BladeService.php index afb1ca28..1ff5c8d1 100644 --- a/src/BladeService.php +++ b/src/BladeService.php @@ -17,6 +17,7 @@ class BladeService public function __construct( public BladeCompiler $compiler, + protected Factory $view, ) { $this->tagCompiler = new ComponentTagCompiler(blade: $compiler); } @@ -195,12 +196,11 @@ public function viewCacheInvalidationHook(callable $callback): void */ public function componentNameToPath($name): string { - $viewFactory = app('view'); - $viewFinder = $viewFactory->getFinder(); + $finder = $this->view->getFinder(); - if (! is_null($guess = $this->guessAnonymousComponentUsingNamespaces($viewFactory, $name)) || - ! is_null($guess = $this->guessAnonymousComponentUsingPaths($viewFactory, $name))) { - return $viewFinder->find($guess); + if (! is_null($guess = $this->guessAnonymousComponentUsingNamespaces($this->view, $name)) || + ! is_null($guess = $this->guessAnonymousComponentUsingPaths($this->view, $name))) { + return $finder->find($guess); } return ''; From fc3b162b57bf79f9b15133831543739a68f577be Mon Sep 17 00:00:00 2001 From: Filip Ganyicz Date: Thu, 5 Mar 2026 20:19:02 +0100 Subject: [PATCH 6/6] Fix test --- tests/BladeServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/BladeServiceTest.php b/tests/BladeServiceTest.php index 635aa155..cdc5642a 100644 --- a/tests/BladeServiceTest.php +++ b/tests/BladeServiceTest.php @@ -12,7 +12,7 @@ 'default path' => [fn () => null, 'dummy.'], 'custom path' => [fn () => Blade::anonymousComponentPath(fixture_path('views/components/dummy')), ''], 'custom path with prefix' => [fn () => Blade::anonymousComponentPath(fixture_path('views/components/dummy'), 'dummy'), 'dummy::'], - 'custom namespace' => [fn () => Blade::anonymousComponentNamespace('components.dummy'), 'dummy::'], + 'custom namespace' => [fn () => Blade::anonymousComponentNamespace('components.dummy', 'dummy'), 'dummy::'], ]) ->with([ 'exact file' => ['foo', fixture_path('views/components/dummy/foo.blade.php')],