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

Commit 047c8de

Browse files
committed
add more tests
1 parent 190d3e4 commit 047c8de

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/AttributeMappingTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ class AttributeMappingTest extends TestCase
1010
{
1111
use WithModelMapping;
1212

13+
public int $id;
1314
public bool $test;
1415
public string $name;
16+
public string $password;
1517
public object $files;
1618

1719
public ?\Closure $default = null;
@@ -85,4 +87,38 @@ public function testMappingWithCasts()
8587
$this->assertInstanceOf(Collection::class, $this->collection);
8688
$this->assertIsString($this->intAsString);
8789
}
90+
91+
/** @test */
92+
public function testIdAndPasswordIsIgnored()
93+
{
94+
$model = new TestModel([
95+
'id' => 1,
96+
'password' => 'hash',
97+
'test' => true,
98+
]);
99+
100+
$this->mapModelAttributes($model);
101+
102+
$this->assertTrue($this->test);
103+
$this->assertFalse((new \ReflectionProperty($this, 'id'))->isInitialized($this));
104+
$this->assertFalse((new \ReflectionProperty($this, 'password'))->isInitialized($this));
105+
}
106+
107+
/** @test */
108+
public function testSetsDefaultValueWithWrongConfig()
109+
{
110+
config(['model-mapper.ignore_attributes' => 123]);
111+
112+
$model = new TestModel([
113+
'id' => 1,
114+
'password' => 'hash',
115+
'test' => true,
116+
]);
117+
118+
$this->mapModelAttributes($model);
119+
120+
$this->assertTrue($this->test);
121+
$this->assertFalse((new \ReflectionProperty($this, 'id'))->isInitialized($this));
122+
$this->assertFalse((new \ReflectionProperty($this, 'password'))->isInitialized($this));
123+
}
88124
}

0 commit comments

Comments
 (0)