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\BooleanToStringTransformer
;
16 class BooleanToStringTransformerTest
extends \PHPUnit_Framework_TestCase
18 const TRUE_VALUE
= '1';
20 protected $transformer;
22 protected function setUp()
24 $this->transformer
= new BooleanToStringTransformer(self
::TRUE_VALUE
);
27 protected function tearDown()
29 $this->transformer
= null;
32 public function testTransform()
34 $this->assertEquals(self
::TRUE_VALUE
, $this->transformer
->transform(true));
35 $this->assertNull($this->transformer
->transform(false));
36 $this->assertNull($this->transformer
->transform(null));
39 public function testTransformExpectsBoolean()
41 $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
43 $this->transformer
->transform('1');
46 public function testReverseTransformExpectsString()
48 $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
50 $this->transformer
->reverseTransform(1);
53 public function testReverseTransform()
55 $this->assertTrue($this->transformer
->reverseTransform(self
::TRUE_VALUE
));
56 $this->assertTrue($this->transformer
->reverseTransform('foobar'));
57 $this->assertTrue($this->transformer
->reverseTransform(''));
58 $this->assertFalse($this->transformer
->reverseTransform(null));