@@ -734,6 +734,31 @@ public function testAttributesTreatedAsPropsAreRemovedFromFinalAttributes()
734
734
$ this ->assertSame ($ attributes ->get ('other ' ), 'ok ' );
735
735
}
736
736
737
+ public function testFalseShortSyntax ()
738
+ {
739
+ $ this ->mockViewFactory ();
740
+ $ result = $ this ->compiler (['bool ' => TestBoolComponent::class])->compileTags ('<x-bool !bool></x-bool> ' );
741
+
742
+ $ this ->assertSame ("##BEGIN-COMPONENT-CLASS##@component('Illuminate\Tests\View\Blade\TestBoolComponent', 'bool', ['bool' => false])
743
+ <?php if (isset( \$attributes) && \$attributes instanceof Illuminate\View\ComponentAttributeBag && \$constructor = (new ReflectionClass(Illuminate\Tests\View\Blade\TestBoolComponent::class))->getConstructor()): ?>
744
+ <?php \$attributes = \$attributes->except(collect( \$constructor->getParameters())->map->getName()->all()); ?>
745
+ <?php endif; ?>
746
+ <?php \$component->withAttributes([]); ?> @endComponentClass##END-COMPONENT-CLASS## " , trim ($ result ));
747
+ }
748
+
749
+ public function testSelfClosingComponentWithFalseShortSyntax ()
750
+ {
751
+ $ this ->mockViewFactory ();
752
+ $ result = $ this ->compiler (['bool ' => TestBoolComponent::class])->compileTags ('<x-bool !bool /> ' );
753
+
754
+ $ this ->assertSame ("##BEGIN-COMPONENT-CLASS##@component('Illuminate\Tests\View\Blade\TestBoolComponent', 'bool', ['bool' => false])
755
+ <?php if (isset( \$attributes) && \$attributes instanceof Illuminate\View\ComponentAttributeBag && \$constructor = (new ReflectionClass(Illuminate\Tests\View\Blade\TestBoolComponent::class))->getConstructor()): ?>
756
+ <?php \$attributes = \$attributes->except(collect( \$constructor->getParameters())->map->getName()->all()); ?>
757
+ <?php endif; ?>
758
+ <?php \$component->withAttributes([]); ?>
759
+ @endComponentClass##END-COMPONENT-CLASS## " , trim ($ result ));
760
+ }
761
+
737
762
protected function mockViewFactory ($ existsSucceeds = true )
738
763
{
739
764
$ container = new Container ;
@@ -797,3 +822,18 @@ public function render()
797
822
return 'input ' ;
798
823
}
799
824
}
825
+
826
+ class TestBoolComponent extends Component
827
+ {
828
+ public $ bool ;
829
+
830
+ public function __construct ($ bool )
831
+ {
832
+ $ this ->bool = $ bool ;
833
+ }
834
+
835
+ public function render ()
836
+ {
837
+ return 'bool ' ;
838
+ }
839
+ }
0 commit comments