This repository was archived by the owner on Mar 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -14,8 +14,10 @@ class AttributeMappingTest extends TestCase
14
14
public bool $ test ;
15
15
public string $ name ;
16
16
public object $ files ;
17
- public ?\Closure $ default = null ;
18
- public ?Collection $ collection = null ;
17
+
18
+ public ?\Closure $ default = null ;
19
+ public ?Collection $ collection = null ;
20
+ public ?string $ intAsString = null ;
19
21
20
22
/** @test */
21
23
public function testMapsAttributesToClassPropertiesCorrectly ()
@@ -68,4 +70,21 @@ public function testMappingWorksWithCollections()
68
70
69
71
$ this ->assertInstanceOf (Collection::class, $ this ->collection );
70
72
}
73
+
74
+ /** @test */
75
+ public function testMappingWithCasts ()
76
+ {
77
+ $ model = new TestModel ([
78
+ 'collection ' => [
79
+ 0 => true ,
80
+ 1 => false ,
81
+ ],
82
+ 'intAsString ' => 100 ,
83
+ ]);
84
+
85
+ $ this ->mapModelAttributes ($ model );
86
+
87
+ $ this ->assertInstanceOf (Collection::class, $ this ->collection );
88
+ $ this ->assertIsString ($ this ->intAsString );
89
+ }
71
90
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace MichaelRubel \ModelMapper \Tests \Boilerplate ;
4
4
5
+ use Illuminate \Database \Eloquent \Casts \AsCollection ;
5
6
use Illuminate \Database \Eloquent \Model ;
6
7
7
8
class TestModel extends Model
@@ -10,4 +11,12 @@ class TestModel extends Model
10
11
* @var array
11
12
*/
12
13
protected $ guarded = [];
14
+
15
+ /**
16
+ * @var string[]
17
+ */
18
+ protected $ casts = [
19
+ 'collection ' => AsCollection::class,
20
+ 'intAsString ' => 'string ' ,
21
+ ];
13
22
}
You can’t perform that action at this time.
0 commit comments