ConfigDataTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Config\Test\Unit\Data;
  7. use Magento\Framework\Config\Data\ConfigData;
  8. class ConfigDataTest extends \PHPUnit\Framework\TestCase
  9. {
  10. public function testSet()
  11. {
  12. $fileKey = 'testFileKey';
  13. $expectedValue = [
  14. 'test' => [
  15. 'path' => [
  16. 'value1' => 'val1',
  17. 'value2' => 'val4',
  18. 'value3' => 'val3',
  19. ]
  20. ]
  21. ];
  22. $configData = new ConfigData($fileKey);
  23. $configData->set('test/path/value1', 'val1');
  24. $configData->set('test/path/value2', 'val2');
  25. $configData->set('test/path/value3', 'val3');
  26. $configData->set('test/path/value2', 'val4');
  27. $this->assertEquals($expectedValue, $configData->getData());
  28. $this->assertEquals($fileKey, $configData->getFileKey());
  29. }
  30. /**
  31. * @param string $key
  32. * @param string $expectedException
  33. * @dataProvider setWrongKeyDataProvider
  34. */
  35. public function testSetWrongKey($key, $expectedException)
  36. {
  37. $configData = new ConfigData('testKey');
  38. $this->expectException('InvalidArgumentException');
  39. $this->expectExceptionMessage($expectedException);
  40. $configData->set($key, 'value');
  41. }
  42. /**
  43. * @return array
  44. */
  45. public function setWrongKeyDataProvider()
  46. {
  47. return [
  48. 'segment is empty' => [
  49. '/test/test/test',
  50. "Path '/test/test/test' is invalid. It cannot be empty nor start or end with '/'"
  51. ],
  52. 'key is empty' => [
  53. '',
  54. "Path '' is invalid. It cannot be empty nor start or end with '/'"
  55. ],
  56. 'access by empty value key' => [
  57. 'test/',
  58. "Path 'test/' is invalid. It cannot be empty nor start or end with '/'"
  59. ]
  60. ];
  61. }
  62. }