Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigDataTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class ConfigDataTest extends \PHPUnit\Framework\TestCase
11 {
12  public function testSet()
13  {
14  $fileKey = 'testFileKey';
15  $expectedValue = [
16  'test' => [
17  'path' => [
18  'value1' => 'val1',
19  'value2' => 'val4',
20  'value3' => 'val3',
21  ]
22  ]
23  ];
24  $configData = new ConfigData($fileKey);
25 
26  $configData->set('test/path/value1', 'val1');
27  $configData->set('test/path/value2', 'val2');
28  $configData->set('test/path/value3', 'val3');
29  $configData->set('test/path/value2', 'val4');
30 
31  $this->assertEquals($expectedValue, $configData->getData());
32  $this->assertEquals($fileKey, $configData->getFileKey());
33  }
34 
40  public function testSetWrongKey($key, $expectedException)
41  {
42 
43  $configData = new ConfigData('testKey');
44 
45  $this->expectException('InvalidArgumentException');
46  $this->expectExceptionMessage($expectedException);
47  $configData->set($key, 'value');
48  }
49 
53  public function setWrongKeyDataProvider()
54  {
55  return [
56  'segment is empty' => [
57  '/test/test/test',
58  "Path '/test/test/test' is invalid. It cannot be empty nor start or end with '/'"
59  ],
60  'key is empty' => [
61  '',
62  "Path '' is invalid. It cannot be empty nor start or end with '/'"
63  ],
64  'access by empty value key' => [
65  'test/',
66  "Path 'test/' is invalid. It cannot be empty nor start or end with '/'"
67  ]
68  ];
69  }
70 }