@@ -355,22 +355,60 @@ public function testSaveToCheckScopeDataSet()
355
355
$ this ->model ->save ();
356
356
}
357
357
358
- public function testSetDataByPath ()
358
+ /**
359
+ * @param string $path
360
+ * @param string $value
361
+ * @param string $section
362
+ * @param array $groups
363
+ * @return void
364
+ * @dataProvider setDataByPathDataProvider
365
+ */
366
+ public function testSetDataByPath (string $ path , string $ value , string $ section , array $ groups )
359
367
{
360
- $ value = 'value ' ;
361
- $ path = '<section>/<group>/<field> ' ;
362
368
$ this ->model ->setDataByPath ($ path , $ value );
363
- $ expected = [
364
- 'section ' => '<section> ' ,
365
- 'groups ' => [
366
- '<group> ' => [
367
- 'fields ' => [
368
- '<field> ' => ['value ' => $ value ],
369
+ $ this ->assertEquals ($ section , $ this ->model ->getData ('section ' ));
370
+ $ this ->assertEquals ($ groups , $ this ->model ->getData ('groups ' ));
371
+ }
372
+
373
+ /**
374
+ * @return array
375
+ */
376
+ public function setDataByPathDataProvider (): array
377
+ {
378
+ return [
379
+ 'depth 3 ' => [
380
+ 'a/b/c ' ,
381
+ 'value1 ' ,
382
+ 'a ' ,
383
+ [
384
+ 'b ' => [
385
+ 'fields ' => [
386
+ 'c ' => ['value ' => 'value1 ' ],
387
+ ],
388
+ ],
389
+ ],
390
+ ],
391
+ 'depth 5 ' => [
392
+ 'a/b/c/d/e ' ,
393
+ 'value1 ' ,
394
+ 'a ' ,
395
+ [
396
+ 'b ' => [
397
+ 'groups ' => [
398
+ 'c ' => [
399
+ 'groups ' => [
400
+ 'd ' => [
401
+ 'fields ' => [
402
+ 'e ' => ['value ' => 'value1 ' ],
403
+ ],
404
+ ],
405
+ ],
406
+ ],
407
+ ],
369
408
],
370
409
],
371
410
],
372
411
];
373
- $ this ->assertSame ($ expected , $ this ->model ->getData ());
374
412
}
375
413
376
414
/**
@@ -384,14 +422,14 @@ public function testSetDataByPathEmpty()
384
422
385
423
/**
386
424
* @param string $path
387
- * @param string $expectedException
388
- *
425
+ * @return void
389
426
* @dataProvider setDataByPathWrongDepthDataProvider
390
427
*/
391
- public function testSetDataByPathWrongDepth ($ path , $ expectedException )
428
+ public function testSetDataByPathWrongDepth (string $ path )
392
429
{
393
- $ expectedException = 'Allowed depth of configuration is 3 (<section>/<group>/<field>). ' . $ expectedException ;
394
- $ this ->expectException ('\UnexpectedValueException ' );
430
+ $ currentDepth = count (explode ('/ ' , $ path ));
431
+ $ expectedException = 'Minimal depth of configuration is 3. Your configuration depth is ' . $ currentDepth ;
432
+ $ this ->expectException (\UnexpectedValueException::class);
395
433
$ this ->expectExceptionMessage ($ expectedException );
396
434
$ value = 'value ' ;
397
435
$ this ->model ->setDataByPath ($ path , $ value );
@@ -400,13 +438,11 @@ public function testSetDataByPathWrongDepth($path, $expectedException)
400
438
/**
401
439
* @return array
402
440
*/
403
- public function setDataByPathWrongDepthDataProvider ()
441
+ public function setDataByPathWrongDepthDataProvider (): array
404
442
{
405
443
return [
406
- 'depth 2 ' => ['section/group ' , "Your configuration depth is 2 for path 'section/group' " ],
407
- 'depth 1 ' => ['section ' , "Your configuration depth is 1 for path 'section' " ],
408
- 'depth 4 ' => ['section/group/field/sub-field ' , "Your configuration depth is 4 for path "
409
- . " 'section/group/field/sub-field' " , ],
444
+ 'depth 2 ' => ['section/group ' ],
445
+ 'depth 1 ' => ['section ' ],
410
446
];
411
447
}
412
448
}
0 commit comments