From 5f78beb2f44c2d26a21f43b08ac65842f663432d Mon Sep 17 00:00:00 2001 From: Pedro Oliveira <38913462+PH7-Jack@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:33:00 -0300 Subject: [PATCH] add "resolve" to `Component::ignoredMethods()` method (#48373) * add "resolve" to `Component::ignoredMethods()` method - add a missing internal method to the ignored component methods * fix code styling --- src/Illuminate/View/Component.php | 1 + tests/View/ViewComponentTest.php | 39 +++++++++++++++++++++++++++++++ 2 files changed, 40 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..a51be9f3cd59 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,44 @@ 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;