Skip to content

Commit

Permalink
test: add tests for computed properties on traits
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdw committed Sep 6, 2024
1 parent eb9dc96 commit 6e6a556
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/Properties/ComputedPropertyExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ public function itRegistersComputedProperyForGetterStyle(): void
));
}

#[Test]
public function itRegistersComputedProperiesFromTraits(): void
{
$properties = [
'trait_method',
'traitMethod',
'trait_getter',
'traitGetter',
];

foreach ($properties as $property) {
$this->assertTrue($this->reflectionExtension->hasProperty(
$this->classReflection,
$property,
));
}
}

#[Test]
public function itCanFindSnakeCaseProperties(): void
{
Expand Down
2 changes: 2 additions & 0 deletions tests/stubs/TestComponentWithComputedProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

final class TestComponentWithComputedProperties extends Component
{
use TraitWithComputedProperties;

public function notAComputedProperty(): bool
{
return true;
Expand Down
21 changes: 21 additions & 0 deletions tests/stubs/TraitWithComputedProperties.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace CalebDW\LarastanLivewire\Tests\stubs;

use Livewire\Attributes\Computed;

trait TraitWithComputedProperties
{
#[Computed]
private function traitMethod(): bool
{
return true;
}

public function getTraitGetterProperty(): bool
{
return true;
}
}

0 comments on commit 6e6a556

Please sign in to comment.