Skip to content

Commit

Permalink
add "resolve" to Component::ignoredMethods() method (#48373)
Browse files Browse the repository at this point in the history
* add "resolve" to `Component::ignoredMethods()` method

- add a missing internal method to the ignored component methods

* fix code styling
  • Loading branch information
ph7jack authored Sep 13, 2023
1 parent 33a206e commit 5f78beb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Illuminate/View/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ protected function ignoredMethods()
return array_merge([
'data',
'render',
'resolve',
'resolveView',
'shouldRender',
'view',
Expand Down
39 changes: 39 additions & 0 deletions tests/View/ViewComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\View\Component;
use Illuminate\View\ComponentAttributeBag;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;

class ViewComponentTest extends TestCase
{
Expand All @@ -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;
Expand Down

0 comments on commit 5f78beb

Please sign in to comment.