Skip to content

Commit 5f78beb

Browse files
authored
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
1 parent 33a206e commit 5f78beb

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/Illuminate/View/Component.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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',

tests/View/ViewComponentTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\View\Component;
66
use Illuminate\View\ComponentAttributeBag;
77
use PHPUnit\Framework\TestCase;
8+
use ReflectionMethod;
89

910
class 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;

0 commit comments

Comments
 (0)