@@ -13,6 +13,19 @@ public function setUp()
13
13
// Mock the Model that uses the custom traits
14
14
$ this ->model = Mockery::mock ('ModelEloquentStub ' );
15
15
$ this ->model ->makePartial ();
16
+
17
+ // Mock the Model without fillable array set
18
+ $ this ->modelWithoutFillable = Mockery::mock ('ModelEloquentStubWithoutFillable ' );
19
+ $ this ->modelWithoutFillable ->makePartial ();
20
+
21
+ // Default payload for Model
22
+ $ this ->payload = [
23
+ 'model_bar ' => ['text ' => 'bar ' ],
24
+ 'model_foos ' => [
25
+ ['text ' => 'foo1 ' ],
26
+ ['text ' => 'foo2 ' ],
27
+ ]
28
+ ];
16
29
}
17
30
18
31
/**
@@ -28,55 +41,72 @@ public function tearDown()
28
41
*/
29
42
public function testFillable ()
30
43
{
31
- $ payload = [
32
- 'title ' => 'foo ' ,
33
- 'not_exists ' => [],
44
+ $ this ->model ->fill (array_merge ($ this ->payload , ['title ' => 'foo ' , 'not_exists ' => []]));
45
+
46
+ $ this ->assertEquals (['title ' => 'foo ' ], $ this ->model ->getAttributes ());
47
+ $ this ->assertEquals ([
34
48
'model_bar ' => ['text ' => 'bar ' ],
35
49
'model_foos ' => [
36
50
['text ' => 'foo1 ' ],
37
- ['text ' => 'foo2 ' ],
51
+ ['text ' => 'foo2 ' ]
38
52
]
39
- ];
53
+ ], $ this ->model ->getAcceptNestedAttributesFor ());
54
+ }
40
55
41
- $ this ->model ->fill ($ payload );
56
+ /**
57
+ * Test that a model with nested attributes can still save without fillable array.
58
+ */
59
+ public function testModelWithNestedAttributesCanSaveWithoutFillableArraySet ()
60
+ {
61
+ $ this ->modelWithoutFillable ->fill ($ this ->payload );
42
62
43
- $ this ->assertEquals (['title ' => 'foo ' ], $ this ->model ->getAttributes ());
44
63
$ this ->assertEquals ([
45
64
'model_bar ' => ['text ' => 'bar ' ],
46
65
'model_foos ' => [
47
- ['text ' => 'foo1 ' ],
66
+ ['text ' => 'foo1 ' ],
48
67
['text ' => 'foo2 ' ]
49
68
]
50
- ], $ this ->model ->getAcceptNestedAttributesFor ());
69
+ ], $ this ->modelWithoutFillable ->getAcceptNestedAttributesFor ());
51
70
}
52
71
}
53
72
54
- class ModelEloquentStub extends Model {
73
+ class ModelEloquentStubWithoutFillable extends Model
74
+ {
55
75
protected $ table = 'stubs ' ;
56
- protected $ fillable = ['title ' ];
57
76
protected $ nested = ['model_bar ' , 'model_foos ' ];
58
-
59
- public function modelBar () {
77
+
78
+ public function modelBar ()
79
+ {
60
80
return $ this ->hasOne (ModelBarStub::class);
61
81
}
62
82
63
- public function modelFoos () {
83
+ public function modelFoos ()
84
+ {
64
85
return $ this ->hasOne (ModelFooStub::class);
65
86
}
66
87
}
67
88
68
- class ModelBarStub extends Model {
89
+ class ModelEloquentStub extends ModelEloquentStubWithoutFillable
90
+ {
91
+ protected $ fillable = ['title ' ];
92
+ }
93
+
94
+ class ModelBarStub extends Model
95
+ {
69
96
protected $ fillable = ['text ' ];
70
-
71
- public function parent () {
97
+
98
+ public function parent ()
99
+ {
72
100
return $ this ->belongsTo (ModelEloquentStub::class);
73
101
}
74
102
}
75
103
76
- class ModelFooStub extends Model {
104
+ class ModelFooStub extends Model
105
+ {
77
106
protected $ fillable = ['text ' ];
78
107
79
- public function parent () {
108
+ public function parent ()
109
+ {
80
110
return $ this ->belongsTo (ModelEloquentStub::class);
81
111
}
82
- }
112
+ }
0 commit comments