PhpBundleWriterTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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\Intl\Tests\Data\Bundle\Writer;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Filesystem\Filesystem;
  13. use Symfony\Component\Intl\Data\Bundle\Writer\PhpBundleWriter;
  14. /**
  15. * @author Bernhard Schussek <bschussek@gmail.com>
  16. */
  17. class PhpBundleWriterTest extends TestCase
  18. {
  19. /**
  20. * @var PhpBundleWriter
  21. */
  22. private $writer;
  23. private $directory;
  24. /**
  25. * @var Filesystem
  26. */
  27. private $filesystem;
  28. protected function setUp()
  29. {
  30. $this->writer = new PhpBundleWriter();
  31. $this->directory = sys_get_temp_dir().'/PhpBundleWriterTest/'.mt_rand(1000, 9999);
  32. $this->filesystem = new Filesystem();
  33. $this->filesystem->mkdir($this->directory);
  34. }
  35. protected function tearDown()
  36. {
  37. $this->filesystem->remove($this->directory);
  38. }
  39. public function testWrite()
  40. {
  41. $this->writer->write($this->directory, 'en', array(
  42. 'Entry1' => array(
  43. 'Array' => array('foo', 'bar'),
  44. 'Integer' => 5,
  45. 'Boolean' => false,
  46. 'Float' => 1.23,
  47. ),
  48. 'Entry2' => 'String',
  49. 'Traversable' => new \ArrayIterator(array(
  50. 'Foo' => 'Bar',
  51. )),
  52. ));
  53. $this->assertFileEquals(__DIR__.'/Fixtures/en.php', $this->directory.'/en.php');
  54. }
  55. /**
  56. * @requires extension intl
  57. */
  58. public function testWriteResourceBundle()
  59. {
  60. $bundle = new \ResourceBundle('rb', __DIR__.'/Fixtures', false);
  61. $this->writer->write($this->directory, 'en', $bundle);
  62. $this->assertFileEquals(__DIR__.'/Fixtures/rb.php', $this->directory.'/en.php');
  63. }
  64. }