mirror of
https://github.com/archtechx/livewire-access.git
synced 2025-12-13 21:04:03 +00:00
implicit access
This commit is contained in:
parent
a5e58a14d8
commit
8df06ae2c3
9 changed files with 184 additions and 22 deletions
|
|
@ -5,49 +5,40 @@ namespace Lean\LivewireAccess\Tests;
|
|||
use Livewire\Exceptions\NonPublicComponentMethodCall;
|
||||
use Livewire\Exceptions\PublicPropertyNotFoundException;
|
||||
use Livewire\Livewire;
|
||||
use Livewire\LivewireServiceProvider;
|
||||
use Orchestra\Testbench\TestCase as TestbenchTestCase;
|
||||
|
||||
class LivewireAccessTest extends TestbenchTestCase
|
||||
class ExplicitAccessTest extends TestCase
|
||||
{
|
||||
protected function getPackageProviders($app)
|
||||
{
|
||||
return [
|
||||
LivewireServiceProvider::class,
|
||||
];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function public_properties_are_not_accessible_by_default()
|
||||
{
|
||||
$this->expectException(PublicPropertyNotFoundException::class);
|
||||
|
||||
Livewire::test(TestComponent::class)
|
||||
Livewire::test(ExplicitComponent::class)
|
||||
->call('$set', 'foo', 'xxx');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function public_properties_can_be_explicitly_accessible()
|
||||
{
|
||||
Livewire::test(TestComponent::class)
|
||||
Livewire::test(ExplicitComponent::class)
|
||||
->call('$set', 'bar', 'xxx');
|
||||
|
||||
// No exception
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function public_methods_are_not_acccessible_by_default()
|
||||
public function public_methods_are_not_accessible_by_default()
|
||||
{
|
||||
$this->expectException(NonPublicComponentMethodCall::class);
|
||||
|
||||
Livewire::test(TestComponent::class)
|
||||
Livewire::test(ExplicitComponent::class)
|
||||
->call('abc');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function public_methods_can_be_explicitly_accessible()
|
||||
{
|
||||
Livewire::test(TestComponent::class)
|
||||
Livewire::test(ExplicitComponent::class)
|
||||
->call('def');
|
||||
|
||||
// No exception
|
||||
|
|
@ -6,7 +6,7 @@ use Lean\LivewireAccess\WithExplicitAccess;
|
|||
use Lean\LivewireAccess\FrontendAccess;
|
||||
use Livewire\Component;
|
||||
|
||||
class TestComponent extends Component
|
||||
class ExplicitComponent extends Component
|
||||
{
|
||||
use WithExplicitAccess;
|
||||
|
||||
46
tests/ImplicitAccessTest.php
Normal file
46
tests/ImplicitAccessTest.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Lean\LivewireAccess\Tests;
|
||||
|
||||
use Livewire\Exceptions\NonPublicComponentMethodCall;
|
||||
use Livewire\Exceptions\PublicPropertyNotFoundException;
|
||||
use Livewire\Livewire;
|
||||
|
||||
class ImplicitAccessTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function public_properties_are_accessible_by_default()
|
||||
{
|
||||
// No exception
|
||||
|
||||
Livewire::test(ImplicitComponent::class)
|
||||
->call('$set', 'foo', 'xxx');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function public_properties_can_be_explicitly_blocked()
|
||||
{
|
||||
$this->expectException(PublicPropertyNotFoundException::class);
|
||||
|
||||
Livewire::test(ImplicitComponent::class)
|
||||
->call('$set', 'bar', 'xxx');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function public_methods_are_accessible_by_default()
|
||||
{
|
||||
Livewire::test(ImplicitComponent::class)
|
||||
->call('abc');
|
||||
|
||||
// No exception
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function public_methods_can_be_explicitly_blocked()
|
||||
{
|
||||
$this->expectException(NonPublicComponentMethodCall::class);
|
||||
|
||||
Livewire::test(ImplicitComponent::class)
|
||||
->call('def');
|
||||
}
|
||||
}
|
||||
27
tests/ImplicitComponent.php
Normal file
27
tests/ImplicitComponent.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Lean\LivewireAccess\Tests;
|
||||
|
||||
use Lean\LivewireAccess\BlockFrontendAccess;
|
||||
use Lean\LivewireAccess\WithImplicitAccess;
|
||||
use Livewire\Component;
|
||||
|
||||
class ImplicitComponent extends Component
|
||||
{
|
||||
use WithImplicitAccess;
|
||||
|
||||
public string $foo = 'foo';
|
||||
|
||||
#[BlockFrontendAccess]
|
||||
public string $bar = 'bar';
|
||||
|
||||
public function abc() {}
|
||||
|
||||
#[BlockFrontendAccess]
|
||||
public function def() {}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
16
tests/TestCase.php
Normal file
16
tests/TestCase.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Lean\LivewireAccess\Tests;
|
||||
|
||||
use Livewire\LivewireServiceProvider;
|
||||
use Orchestra\Testbench\TestCase as TestbenchTestCase;
|
||||
|
||||
class TestCase extends TestbenchTestCase
|
||||
{
|
||||
protected function getPackageProviders($app)
|
||||
{
|
||||
return [
|
||||
LivewireServiceProvider::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue