4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer
;
14 use Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedStringTransformer
;
15 use Symfony\Component\Intl\Util\IntlTestHelper
;
17 class MoneyToLocalizedStringTransformerTest
extends \PHPUnit_Framework_TestCase
19 protected function setUp()
23 // Since we test against "de_AT", we need the full implementation
24 IntlTestHelper
::requireFullIntl($this);
26 \Locale
::setDefault('de_AT');
29 public function testTransform()
31 $transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
33 $this->assertEquals('1,23', $transformer->transform(123));
36 public function testTransformExpectsNumeric()
38 $transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
40 $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
42 $transformer->transform('abcd');
45 public function testTransformEmpty()
47 $transformer = new MoneyToLocalizedStringTransformer();
49 $this->assertSame('', $transformer->transform(null));
52 public function testReverseTransform()
54 $transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
56 $this->assertEquals(123, $transformer->reverseTransform('1,23'));
59 public function testReverseTransformExpectsString()
61 $transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
63 $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
65 $transformer->reverseTransform(12345);
68 public function testReverseTransformEmpty()
70 $transformer = new MoneyToLocalizedStringTransformer();
72 $this->assertNull($transformer->reverseTransform(''));