From 829da5d71d13930009c442e204b805609c9a8fd2 Mon Sep 17 00:00:00 2001 From: PH7-Jack Date: Wed, 13 Sep 2023 01:16:09 -0300 Subject: [PATCH 1/2] add "resolve" to `Component::ignoredMethods()` method - add a missing internal method to the ignored component methods --- src/Illuminate/View/Component.php | 1 + tests/View/ViewComponentTest.php | 38 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/Illuminate/View/Component.php b/src/Illuminate/View/Component.php index 329035c47c81..150129ca65f9 100644 --- a/src/Illuminate/View/Component.php +++ b/src/Illuminate/View/Component.php @@ -324,6 +324,7 @@ protected function ignoredMethods() return array_merge([ 'data', 'render', + 'resolve', 'resolveView', 'shouldRender', 'view', diff --git a/tests/View/ViewComponentTest.php b/tests/View/ViewComponentTest.php index c7ac6cda96ec..e8b475d2cb3e 100644 --- a/tests/View/ViewComponentTest.php +++ b/tests/View/ViewComponentTest.php @@ -5,6 +5,7 @@ use Illuminate\View\Component; use Illuminate\View\ComponentAttributeBag; use PHPUnit\Framework\TestCase; +use ReflectionMethod; class ViewComponentTest extends TestCase { @@ -19,6 +20,43 @@ public function testDataExposure() $this->assertSame('taylor', $variables['hello']('taylor')); } + public function testIgnoredMethodsAreNotExposedToViewData() + { + $component = new class extends Component { + protected $except = ['goodbye']; + + public function render() + { + return 'test'; + } + + public function hello() + { + return 'hello world'; + } + + public function goodbye() + { + return 'goodbye'; + } + }; + + $data = $component->data(); + + $this->assertArrayHasKey('hello', $data); + $this->assertArrayNotHasKey('goodbye', $data); + + $reflectionMethod = new ReflectionMethod($component, 'ignoredMethods'); + + $reflectionMethod->setAccessible(true); + + $ignoredMethods = $reflectionMethod->invoke($component); + + foreach ($ignoredMethods as $method) { + $this->assertArrayNotHasKey($method, $data); + } + } + public function testAttributeParentInheritance() { $component = new TestViewComponent; From 73deb7b219f3a360ba9647008040bf20778235f7 Mon Sep 17 00:00:00 2001 From: PH7-Jack Date: Wed, 13 Sep 2023 01:25:29 -0300 Subject: [PATCH 2/2] fix code styling --- tests/View/ViewComponentTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/View/ViewComponentTest.php b/tests/View/ViewComponentTest.php index e8b475d2cb3e..a51be9f3cd59 100644 --- a/tests/View/ViewComponentTest.php +++ b/tests/View/ViewComponentTest.php @@ -22,7 +22,8 @@ public function testDataExposure() public function testIgnoredMethodsAreNotExposedToViewData() { - $component = new class extends Component { + $component = new class extends Component + { protected $except = ['goodbye']; public function render()