File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -324,6 +324,7 @@ protected function ignoredMethods()
324324 return array_merge ([
325325 'data ' ,
326326 'render ' ,
327+ 'resolve ' ,
327328 'resolveView ' ,
328329 'shouldRender ' ,
329330 'view ' ,
Original file line number Diff line number Diff line change 55use Illuminate \View \Component ;
66use Illuminate \View \ComponentAttributeBag ;
77use PHPUnit \Framework \TestCase ;
8+ use ReflectionMethod ;
89
910class ViewComponentTest extends TestCase
1011{
@@ -19,6 +20,44 @@ public function testDataExposure()
1920 $ this ->assertSame ('taylor ' , $ variables ['hello ' ]('taylor ' ));
2021 }
2122
23+ public function testIgnoredMethodsAreNotExposedToViewData ()
24+ {
25+ $ component = new class extends Component
26+ {
27+ protected $ except = ['goodbye ' ];
28+
29+ public function render ()
30+ {
31+ return 'test ' ;
32+ }
33+
34+ public function hello ()
35+ {
36+ return 'hello world ' ;
37+ }
38+
39+ public function goodbye ()
40+ {
41+ return 'goodbye ' ;
42+ }
43+ };
44+
45+ $ data = $ component ->data ();
46+
47+ $ this ->assertArrayHasKey ('hello ' , $ data );
48+ $ this ->assertArrayNotHasKey ('goodbye ' , $ data );
49+
50+ $ reflectionMethod = new ReflectionMethod ($ component , 'ignoredMethods ' );
51+
52+ $ reflectionMethod ->setAccessible (true );
53+
54+ $ ignoredMethods = $ reflectionMethod ->invoke ($ component );
55+
56+ foreach ($ ignoredMethods as $ method ) {
57+ $ this ->assertArrayNotHasKey ($ method , $ data );
58+ }
59+ }
60+
2261 public function testAttributeParentInheritance ()
2362 {
2463 $ component = new TestViewComponent ;
You can’t perform that action at this time.
0 commit comments