File tree Expand file tree Collapse file tree 2 files changed +24
-13
lines changed Expand file tree Collapse file tree 2 files changed +24
-13
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use Yii ;
6
6
use yii \base \Behavior ;
7
+ use yii \base \InvalidArgumentException ;
7
8
use yii \base \InvalidConfigException ;
8
9
use yii \base \UnknownPropertyException ;
9
10
use yii \db \ActiveRecord ;
@@ -123,7 +124,7 @@ public function afterValidate()
123
124
}
124
125
125
126
$ errors = [];
126
- $ models = isset ($ this ->_inserteds [ $ name ]) ? $ this -> _inserteds [ $ name] : [] ;
127
+ $ models = ArrayHelper:: getValue ($ this ->_inserteds , $ name, []) ;
127
128
128
129
foreach ($ models as $ model ) {
129
130
if (!$ model ->validate ()) {
@@ -149,6 +150,10 @@ public function __set($name, $value)
149
150
try {
150
151
parent ::__set ($ name , $ value );
151
152
} catch (UnknownPropertyException $ exception ) {
153
+ if (!is_array ($ value )) {
154
+ throw new InvalidArgumentException ("The ' $ name' property must be an array " );
155
+ }
156
+
152
157
$ definition = $ this ->findDefinition ($ name );
153
158
if ($ definition !== null ) {
154
159
$ this ->prepareRelation ($ definition , [$ name => $ value ]);
Original file line number Diff line number Diff line change 4
4
5
5
use solutosoft \linkmany \LinkManyBehavior ;
6
6
use solutosoft \linkmany \tests \models \Post ;
7
- use solutosoft \linkmany \tests \models \Tag ;
8
7
9
- //use solutosoft\linkmany\tests\models\PostLanguage;
10
- //use solutosoft\linkmany\tests\models\Tag;
11
8
12
9
class LinkManyBehaviorTest extends TestCase
13
10
{
14
- public function testInitException ()
11
+ public function testInitSuccess ()
15
12
{
16
- $ this ->setExpectedException ('\yii\base\InvalidConfigException ' );
17
-
18
13
new LinkManyBehavior ([
19
14
'relations ' => [
20
- ['invalid ' => true ]
15
+ 'relation_1 ' ,
16
+ 'relation_2 ' => [
17
+ 'formName ' => 'test '
18
+ ]
21
19
]
22
20
]);
23
21
}
24
22
25
- public function testInitSuccess ()
23
+ public function testInitException ()
26
24
{
25
+ $ this ->setExpectedException ('\yii\base\InvalidConfigException ' );
26
+
27
27
new LinkManyBehavior ([
28
28
'relations ' => [
29
- 'relation_1 ' ,
30
- 'relation_2 ' => [
31
- 'formName ' => 'test '
32
- ]
29
+ ['invalid ' => true ]
33
30
]
34
31
]);
35
32
}
36
33
34
+ public function testInvalidRelationValue ()
35
+ {
36
+ $ this ->setExpectedException ('\yii\base\InvalidArgumentException ' );
37
+
38
+ $ post = new Post ();
39
+ $ post ->comments = null ;
40
+ }
41
+
37
42
public function testFillNewRecord ()
38
43
{
39
44
$ post = new Post ();
@@ -234,6 +239,7 @@ public function testSetRelation()
234
239
$ post ->tags = [1 ];
235
240
236
241
$ post ->save ();
242
+ $ post ->refresh ();
237
243
$ this ->assertCount (1 , $ post ->tags );
238
244
}
239
245
}
You can’t perform that action at this time.
0 commit comments