1
0
Fork 0
mirror of https://github.com/archtechx/livewire-access.git synced 2025-12-12 04:14:03 +00:00
This commit is contained in:
Samuel Štancl 2021-03-17 17:28:17 +01:00
parent a29235253b
commit e50e22434f
12 changed files with 159 additions and 138 deletions

View file

@ -0,0 +1,55 @@
<?php
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
{
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)
->call('$set', 'foo', 'xxx');
}
/** @test */
public function public_properties_can_be_explicitly_accessible()
{
Livewire::test(TestComponent::class)
->call('$set', 'bar', 'xxx');
// No exception
}
/** @test */
public function public_methods_are_not_acccessible_by_default()
{
$this->expectException(NonPublicComponentMethodCall::class);
Livewire::test(TestComponent::class)
->call('abc');
}
/** @test */
public function public_methods_can_be_explicitly_accessible()
{
Livewire::test(TestComponent::class)
->call('def');
// No exception
}
}

View file

@ -1,16 +0,0 @@
<?php
namespace Stancl\Package\Tests;
use Orchestra\Testbench\TestCase as TestbenchTestCase;
use Stancl\Package\PackageServiceProvider;
class TestCase extends TestbenchTestCase
{
protected function getPackageProviders($app)
{
return [
PackageServiceProvider::class,
];
}
}

27
tests/TestComponent.php Normal file
View file

@ -0,0 +1,27 @@
<?php
namespace Lean\LivewireAccess\Tests;
use Lean\LivewireAccess\WithExplicitAccess;
use Lean\LivewireAccess\FrontendAccess;
use Livewire\Component;
class TestComponent extends Component
{
use WithExplicitAccess;
public string $foo = 'foo';
#[FrontendAccess]
public string $bar = 'bar';
public function abc() {}
#[FrontendAccess]
public function def() {}
public function render()
{
return '';
}
}