@@ -715,7 +715,7 @@ public function testAttributesTreatedAsPropsAreRemovedFromFinalAttributes()
715
715
$ component ->shouldReceive ('shouldRender ' )->once ()->andReturn (true );
716
716
$ component ->shouldReceive ('resolveView ' )->once ()->andReturn ('' );
717
717
$ component ->shouldReceive ('data ' )->once ()->andReturn ([]);
718
- $ component ->shouldReceive ('withAttributes ' )->once ();
718
+ $ component ->shouldReceive ('withAttributes ' )->with ([ ' attributes ' => new ComponentAttributeBag ([ ' other ' => ' ok ' ])])-> once ();
719
719
720
720
Component::resolveComponentsUsing (fn () => $ component );
721
721
@@ -730,7 +730,57 @@ public function testAttributesTreatedAsPropsAreRemovedFromFinalAttributes()
730
730
eval (" ?> $ template <?php " );
731
731
ob_get_clean ();
732
732
733
- $ this ->assertNull ($ attributes ->get ('userId ' ));
733
+ $ this ->assertSame ($ attributes ->get ('userId ' ), 'bar ' );
734
+ $ this ->assertSame ($ attributes ->get ('other ' ), 'ok ' );
735
+ }
736
+
737
+ public function testOriginalAttributesAreRestoredAfterRenderingChildComponentWithProps ()
738
+ {
739
+ $ container = new Container ;
740
+ $ container ->instance (Application::class, $ app = m::mock (Application::class));
741
+ $ container ->instance (Factory::class, $ factory = m::mock (Factory::class));
742
+ $ container ->alias (Factory::class, 'view ' );
743
+ $ app ->shouldReceive ('getNamespace ' )->never ()->andReturn ('App \\' );
744
+ $ factory ->shouldReceive ('exists ' )->never ();
745
+
746
+ Container::setInstance ($ container );
747
+
748
+ $ attributes = new ComponentAttributeBag (['userId ' => 'bar ' , 'other ' => 'ok ' ]);
749
+
750
+ $ containerComponent = m::mock (Component::class);
751
+ $ containerComponent ->shouldReceive ('withName ' )->with ('container ' )->once ();
752
+ $ containerComponent ->shouldReceive ('shouldRender ' )->once ()->andReturn (true );
753
+ $ containerComponent ->shouldReceive ('resolveView ' )->once ()->andReturn ('' );
754
+ $ containerComponent ->shouldReceive ('data ' )->once ()->andReturn ([]);
755
+ $ containerComponent ->shouldReceive ('withAttributes ' )->once ();
756
+
757
+ $ profileComponent = m::mock (Component::class);
758
+ $ profileComponent ->shouldReceive ('withName ' )->with ('profile ' )->once ();
759
+ $ profileComponent ->shouldReceive ('shouldRender ' )->once ()->andReturn (true );
760
+ $ profileComponent ->shouldReceive ('resolveView ' )->once ()->andReturn ('' );
761
+ $ profileComponent ->shouldReceive ('data ' )->once ()->andReturn ([]);
762
+ $ profileComponent ->shouldReceive ('withAttributes ' )->with (['attributes ' => new ComponentAttributeBag (['other ' => 'ok ' ])])->once ();
763
+
764
+ Component::resolveComponentsUsing (fn ($ component ) => match ($ component ) {
765
+ TestContainerComponent::class => $ containerComponent ,
766
+ TestProfileComponent::class => $ profileComponent ,
767
+ });
768
+
769
+ $ __env = m::mock (\Illuminate \View \Factory::class);
770
+ $ __env ->shouldReceive ('startComponent ' )->twice ();
771
+ $ __env ->shouldReceive ('renderComponent ' )->twice ();
772
+
773
+ $ template = $ this ->compiler ([
774
+ 'container ' => TestContainerComponent::class,
775
+ 'profile ' => TestProfileComponent::class,
776
+ ])->compileTags ('<x-container><x-profile {{ $attributes }} /></x-container> ' );
777
+ $ template = $ this ->compiler ->compileString ($ template );
778
+
779
+ ob_start ();
780
+ eval (" ?> $ template <?php " );
781
+ ob_get_clean ();
782
+
783
+ $ this ->assertSame ($ attributes ->get ('userId ' ), 'bar ' );
734
784
$ this ->assertSame ($ attributes ->get ('other ' ), 'ok ' );
735
785
}
736
786
@@ -797,3 +847,11 @@ public function render()
797
847
return 'input ' ;
798
848
}
799
849
}
850
+
851
+ class TestContainerComponent extends Component
852
+ {
853
+ public function render ()
854
+ {
855
+ return 'container ' ;
856
+ }
857
+ }
0 commit comments