From 15843a378b262367748f8a01ffd2eda2828a658c Mon Sep 17 00:00:00 2001 From: Derek Date: Sun, 27 Mar 2022 13:34:21 -0400 Subject: [PATCH] Remove PHP 8.1 deprecated notice in @pushOnce() & @includeOnce() trim() no longer accepts null arguments because reasons. --- .../View/Compilers/Concerns/CompilesStacks.php | 4 ++-- tests/View/Blade/BladePrependTest.php | 18 ++++++++++++++++++ tests/View/Blade/BladePushTest.php | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/View/Compilers/Concerns/CompilesStacks.php b/src/Illuminate/View/Compilers/Concerns/CompilesStacks.php index dc5192580f71..16ceef37ce3e 100644 --- a/src/Illuminate/View/Compilers/Concerns/CompilesStacks.php +++ b/src/Illuminate/View/Compilers/Concerns/CompilesStacks.php @@ -38,7 +38,7 @@ protected function compilePushOnce($expression) { $parts = explode(',', $this->stripParentheses($expression), 2); - [$stack, $id] = [$parts[0], $parts[1] ?? null]; + [$stack, $id] = [$parts[0], $parts[1] ?? '']; $id = trim($id) ?: "'".(string) Str::uuid()."'"; @@ -87,7 +87,7 @@ protected function compilePrependOnce($expression) { $parts = explode(',', $this->stripParentheses($expression), 2); - [$stack, $id] = [$parts[0], $parts[1] ?? null]; + [$stack, $id] = [$parts[0], $parts[1] ?? '']; $id = trim($id) ?: "'".(string) Str::uuid()."'"; diff --git a/tests/View/Blade/BladePrependTest.php b/tests/View/Blade/BladePrependTest.php index bccb64723c96..11bc1fa100da 100644 --- a/tests/View/Blade/BladePrependTest.php +++ b/tests/View/Blade/BladePrependTest.php @@ -2,6 +2,8 @@ namespace Illuminate\Tests\View\Blade; +use Illuminate\Support\Str; + class BladePrependTest extends AbstractBladeTestCase { public function testPrependIsCompiled() @@ -25,6 +27,22 @@ public function testPrependOnceIsCompiled() $expected = 'hasRenderedOnce(\'bar\')): $__env->markAsRenderedOnce(\'bar\'); $__env->startPrepend(\'foo\'); ?> test +stopPrepend(); endif; ?>'; + + $this->assertEquals($expected, $this->compiler->compileString($string)); + } + + public function testPrependOnceIsCompiledWhenIdIsMissing() + { + Str::createUuidsUsing(fn () => 'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f'); + + $string = '@prependOnce(\'foo\') +test +@endPrependOnce'; + + $expected = 'hasRenderedOnce(\'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f\')): $__env->markAsRenderedOnce(\'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f\'); +$__env->startPrepend(\'foo\'); ?> +test stopPrepend(); endif; ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); diff --git a/tests/View/Blade/BladePushTest.php b/tests/View/Blade/BladePushTest.php index 0f1addbfba9c..27d0041363ba 100644 --- a/tests/View/Blade/BladePushTest.php +++ b/tests/View/Blade/BladePushTest.php @@ -2,6 +2,8 @@ namespace Illuminate\Tests\View\Blade; +use Illuminate\Support\Str; + class BladePushTest extends AbstractBladeTestCase { public function testPushIsCompiled() @@ -24,6 +26,22 @@ public function testPushOnceIsCompiled() $expected = 'hasRenderedOnce(\'bar\')): $__env->markAsRenderedOnce(\'bar\'); $__env->startPush(\'foo\'); ?> test +stopPush(); endif; ?>'; + + $this->assertEquals($expected, $this->compiler->compileString($string)); + } + + public function testPushOnceIsCompiledWhenIdIsMissing() + { + Str::createUuidsUsing(fn () => 'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f'); + + $string = '@pushOnce(\'foo\') +test +@endPushOnce'; + + $expected = 'hasRenderedOnce(\'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f\')): $__env->markAsRenderedOnce(\'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f\'); +$__env->startPush(\'foo\'); ?> +test stopPush(); endif; ?>'; $this->assertEquals($expected, $this->compiler->compileString($string));