Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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