ArrayConverterTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 array(
  25. array(
  26. // input
  27. array(
  28. 'foo1' => 'bar',
  29. 'foo.bar' => 'value',
  30. ),
  31. // expected output
  32. array(
  33. 'foo1' => 'bar',
  34. 'foo' => array('bar' => 'value'),
  35. ),
  36. ),
  37. array(
  38. // input
  39. array(
  40. 'foo.bar' => 'value1',
  41. 'foo.bar.test' => 'value2',
  42. ),
  43. // expected output
  44. array(
  45. 'foo' => array(
  46. 'bar' => 'value1',
  47. 'bar.test' => 'value2',
  48. ),
  49. ),
  50. ),
  51. array(
  52. // input
  53. array(
  54. 'foo.level2.level3.level4' => 'value1',
  55. 'foo.level2' => 'value2',
  56. 'foo.bar' => 'value3',
  57. ),
  58. // expected output
  59. array(
  60. 'foo' => array(
  61. 'level2' => 'value2',
  62. 'level2.level3.level4' => 'value1',
  63. 'bar' => 'value3',
  64. ),
  65. ),
  66. ),
  67. );
  68. }
  69. }