Skip to content

Commit 0a3a5da

Browse files
committed
Add CustomAttributesTest
1 parent 37caa0d commit 0a3a5da

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/Traits/Core/HasCustomAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ trait HasCustomAttributes
88
{
99
public function hasCustomAttributes(string $propertyName): bool
1010
{
11-
return isset($this->{$propertyName});
11+
return property_exists($this, $propertyName) && isset($this->{$propertyName});
1212
}
1313

1414
public function getCustomAttributes(string $propertyName, bool $default = false, bool $classicMode = true): array
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Tests\Traits\Core;
4+
5+
use PHPUnit\Framework\Attributes\DataProvider;
6+
use Rappasoft\LaravelLivewireTables\Tests\TestCase;
7+
8+
final class CustomAttributesTest extends TestCase
9+
{
10+
11+
public function test_can_get_custom_attribute_defaults_false_standard_mode(): void
12+
{
13+
$this->assertSame([
14+
'default' => false,
15+
'default-colors' => true,
16+
'default-styling' => true
17+
], $this->basicTable->getCustomAttributes('bulkActionsButtonAttributes', false, true));
18+
}
19+
20+
public function test_can_get_custom_attribute_defaults_false_classic_mode(): void
21+
{
22+
$this->assertSame([
23+
'default-colors' => true,
24+
'default-styling' => true
25+
], $this->basicTable->getCustomAttributes('bulkActionsButtonAttributes', false, false));
26+
}
27+
28+
public function test_can_get_custom_attribute_defaults_true_standard_mode(): void
29+
{
30+
$this->assertSame([
31+
'default' => true,
32+
'default-colors' => true,
33+
'default-styling' => true
34+
], $this->basicTable->getCustomAttributes('bulkActionsButtonAttributes', true, true));
35+
}
36+
37+
public function test_can_get_custom_attribute_defaults_true_classic_mode(): void
38+
{
39+
$this->assertSame([
40+
'default-colors' => true,
41+
'default-styling' => true
42+
], $this->basicTable->getCustomAttributes('bulkActionsButtonAttributes', true, false));
43+
}
44+
45+
46+
}

0 commit comments

Comments
 (0)