Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit dbc0c93

Browse files
committed
add tests for dynamic properties
1 parent 17139c7 commit dbc0c93

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/DynamicPropertiesTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace MichaelRubel\LoopFunctions\Tests;
4+
5+
use Illuminate\Support\Collection;
6+
use MichaelRubel\LoopFunctions\Tests\Boilerplate\TestClass;
7+
use MichaelRubel\LoopFunctions\Traits\LoopFunctions;
8+
9+
class DynamicPropertiesTest extends TestCase
10+
{
11+
use LoopFunctions;
12+
13+
public function __get(string $name): mixed
14+
{
15+
return $this->{$name};
16+
}
17+
18+
public function __set(string $name, $value): void
19+
{
20+
$this->{$name} = $value;
21+
}
22+
23+
/** @test */
24+
public function testCanUseDynamicProperties()
25+
{
26+
config(['loop-functions.dynamic_properties' => true]);
27+
28+
$array = [
29+
'test' => true,
30+
];
31+
32+
$this->propertiesFrom($array);
33+
34+
$this->assertTrue($this->test);
35+
}
36+
37+
/** @test */
38+
public function testDynamicPropertiesDisabled()
39+
{
40+
config(['loop-functions.dynamic_properties' => false]);
41+
42+
$this->expectException(\ErrorException::class);
43+
44+
$array = [
45+
'test' => true,
46+
];
47+
48+
$this->propertiesFrom($array);
49+
50+
$this->assertFalse($this->test);
51+
}
52+
}

0 commit comments

Comments
 (0)