CurrencyBundleTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\ResourceBundle;
  11. use Symfony\Component\Intl\ResourceBundle\CurrencyBundle;
  12. /**
  13. * @author Bernhard Schussek <bschussek@gmail.com>
  14. */
  15. class CurrencyBundleTest extends \PHPUnit_Framework_TestCase
  16. {
  17. const RES_DIR = '/base/curr';
  18. /**
  19. * @var CurrencyBundle
  20. */
  21. private $bundle;
  22. /**
  23. * @var \PHPUnit_Framework_MockObject_MockObject
  24. */
  25. private $reader;
  26. protected function setUp()
  27. {
  28. $this->reader = $this->getMock('Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface');
  29. $this->bundle = new CurrencyBundle(self::RES_DIR, $this->reader);
  30. }
  31. public function testGetCurrencySymbol()
  32. {
  33. $this->reader->expects($this->once())
  34. ->method('readEntry')
  35. ->with(self::RES_DIR, 'en', array('Currencies', 'EUR', 1))
  36. ->will($this->returnValue('€'));
  37. $this->assertSame('€', $this->bundle->getCurrencySymbol('EUR', 'en'));
  38. }
  39. public function testGetCurrencyName()
  40. {
  41. $this->reader->expects($this->once())
  42. ->method('readEntry')
  43. ->with(self::RES_DIR, 'en', array('Currencies', 'EUR', 0))
  44. ->will($this->returnValue('Euro'));
  45. $this->assertSame('Euro', $this->bundle->getCurrencyName('EUR', 'en'));
  46. }
  47. public function testGetCurrencyNames()
  48. {
  49. $sortedCurrencies = array(
  50. 'USD' => array(0 => 'Dollar'),
  51. 'EUR' => array(0 => 'Euro'),
  52. );
  53. $this->reader->expects($this->once())
  54. ->method('readEntry')
  55. ->with(self::RES_DIR, 'en', array('Currencies'))
  56. ->will($this->returnValue($sortedCurrencies));
  57. $sortedNames = array(
  58. 'USD' => 'Dollar',
  59. 'EUR' => 'Euro',
  60. );
  61. $this->assertSame($sortedNames, $this->bundle->getCurrencyNames('en'));
  62. }
  63. public function testGetFractionDigits()
  64. {
  65. $this->reader->expects($this->once())
  66. ->method('readEntry')
  67. ->with(self::RES_DIR, 'en', array('Currencies', 'EUR', 2))
  68. ->will($this->returnValue(123));
  69. $this->assertSame(123, $this->bundle->getFractionDigits('EUR'));
  70. }
  71. public function testGetRoundingIncrement()
  72. {
  73. $this->reader->expects($this->once())
  74. ->method('readEntry')
  75. ->with(self::RES_DIR, 'en', array('Currencies', 'EUR', 3))
  76. ->will($this->returnValue(123));
  77. $this->assertSame(123, $this->bundle->getRoundingIncrement('EUR'));
  78. }
  79. }