ArrayConverterTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Translation\Tests\Util;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Translation\Util\ArrayConverter;
  13. class ArrayConverterTest extends TestCase
  14. {
  15. /**
  16. * @dataProvider messagesData
  17. */
  18. public function testDump($input, $expectedOutput)
  19. {
  20. $this->assertEquals($expectedOutput, ArrayConverter::expandToTree($input));
  21. }
  22. public function messagesData()
  23. {
  24. return [
  25. [
  26. // input
  27. [
  28. 'foo1' => 'bar',
  29. 'foo.bar' => 'value',
  30. ],
  31. // expected output
  32. [
  33. 'foo1' => 'bar',
  34. 'foo' => ['bar' => 'value'],
  35. ],
  36. ],
  37. [
  38. // input
  39. [
  40. 'foo.bar' => 'value1',
  41. 'foo.bar.test' => 'value2',
  42. ],
  43. // expected output
  44. [
  45. 'foo' => [
  46. 'bar' => 'value1',
  47. 'bar.test' => 'value2',
  48. ],
  49. ],
  50. ],
  51. [
  52. // input
  53. [
  54. 'foo.level2.level3.level4' => 'value1',
  55. 'foo.level2' => 'value2',
  56. 'foo.bar' => 'value3',
  57. ],
  58. // expected output
  59. [
  60. 'foo' => [
  61. 'level2' => 'value2',
  62. 'level2.level3.level4' => 'value1',
  63. 'bar' => 'value3',
  64. ],
  65. ],
  66. ],
  67. ];
  68. }
  69. }