This repository was archived by the owner on Mar 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,10 @@ class AttributeMappingTest extends TestCase
10
10
{
11
11
use WithModelMapping;
12
12
13
+ public int $ id ;
13
14
public bool $ test ;
14
15
public string $ name ;
16
+ public string $ password ;
15
17
public object $ files ;
16
18
17
19
public ?\Closure $ default = null ;
@@ -85,4 +87,38 @@ public function testMappingWithCasts()
85
87
$ this ->assertInstanceOf (Collection::class, $ this ->collection );
86
88
$ this ->assertIsString ($ this ->intAsString );
87
89
}
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
+ }
88
124
}
You can’t perform that action at this time.
0 commit comments