@@ -330,22 +330,59 @@ public function testSaveToCheckScopeDataSet()
330
330
$ this ->model ->save ();
331
331
}
332
332
333
- public function testSetDataByPath ()
333
+ /**
334
+ * @param string $path
335
+ * @param string $value
336
+ * @param string $section
337
+ * @param array $groups
338
+ * @dataProvider setDataByPathDataProvider
339
+ */
340
+ public function testSetDataByPath (string $ path , string $ value , string $ section , array $ groups )
334
341
{
335
- $ value = 'value ' ;
336
- $ path = '<section>/<group>/<field> ' ;
337
342
$ this ->model ->setDataByPath ($ path , $ value );
338
- $ expected = [
339
- 'section ' => '<section> ' ,
340
- 'groups ' => [
341
- '<group> ' => [
342
- 'fields ' => [
343
- '<field> ' => ['value ' => $ value ],
343
+ $ this ->assertEquals ($ section , $ this ->model ->getData ('section ' ));
344
+ $ this ->assertEquals ($ groups , $ this ->model ->getData ('groups ' ));
345
+ }
346
+
347
+ /**
348
+ * @return array
349
+ */
350
+ public function setDataByPathDataProvider (): array
351
+ {
352
+ return [
353
+ 'depth 3 ' => [
354
+ 'a/b/c ' ,
355
+ 'value1 ' ,
356
+ 'a ' ,
357
+ [
358
+ 'b ' => [
359
+ 'fields ' => [
360
+ 'c ' => ['value ' => 'value1 ' ],
361
+ ],
362
+ ],
363
+ ],
364
+ ],
365
+ 'depth 5 ' => [
366
+ 'a/b/c/d/e ' ,
367
+ 'value1 ' ,
368
+ 'a ' ,
369
+ [
370
+ 'b ' => [
371
+ 'groups ' => [
372
+ 'c ' => [
373
+ 'groups ' => [
374
+ 'd ' => [
375
+ 'fields ' => [
376
+ 'e ' => ['value ' => 'value1 ' ],
377
+ ],
378
+ ],
379
+ ],
380
+ ],
381
+ ],
344
382
],
345
383
],
346
384
],
347
385
];
348
- $ this ->assertSame ($ expected , $ this ->model ->getData ());
349
386
}
350
387
351
388
/**
@@ -359,14 +396,13 @@ public function testSetDataByPathEmpty()
359
396
360
397
/**
361
398
* @param string $path
362
- * @param string $expectedException
363
- *
364
399
* @dataProvider setDataByPathWrongDepthDataProvider
365
400
*/
366
- public function testSetDataByPathWrongDepth ($ path , $ expectedException )
401
+ public function testSetDataByPathWrongDepth (string $ path )
367
402
{
368
- $ expectedException = 'Allowed depth of configuration is 3 (<section>/<group>/<field>). ' . $ expectedException ;
369
- $ this ->expectException ('\UnexpectedValueException ' );
403
+ $ currentDepth = count (explode ('/ ' , $ path ));
404
+ $ expectedException = 'Minimum depth of configuration is 3. Your configuration depth is ' . $ currentDepth . '. ' ;
405
+ $ this ->expectException (\UnexpectedValueException::class);
370
406
$ this ->expectExceptionMessage ($ expectedException );
371
407
$ value = 'value ' ;
372
408
$ this ->model ->setDataByPath ($ path , $ value );
@@ -375,13 +411,11 @@ public function testSetDataByPathWrongDepth($path, $expectedException)
375
411
/**
376
412
* @return array
377
413
*/
378
- public function setDataByPathWrongDepthDataProvider ()
414
+ public function setDataByPathWrongDepthDataProvider (): array
379
415
{
380
416
return [
381
- 'depth 2 ' => ['section/group ' , "Your configuration depth is 2 for path 'section/group' " ],
382
- 'depth 1 ' => ['section ' , "Your configuration depth is 1 for path 'section' " ],
383
- 'depth 4 ' => ['section/group/field/sub-field ' , "Your configuration depth is 4 for path "
384
- . " 'section/group/field/sub-field' " , ],
417
+ 'depth 2 ' => ['section/group ' ],
418
+ 'depth 1 ' => ['section ' ],
385
419
];
386
420
}
387
421
}
0 commit comments