]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/BooleanToStringTransformerTest.php
gitignore vendor
[github/wallabag/wallabag.git] / vendor / symfony / form / Symfony / Component / Form / Tests / Extension / Core / DataTransformer / BooleanToStringTransformerTest.php
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
13
14 use Symfony\Component\Form\Extension\Core\DataTransformer\BooleanToStringTransformer;
15
16 class BooleanToStringTransformerTest extends \PHPUnit_Framework_TestCase
17 {
18 const TRUE_VALUE = '1';
19
20 protected $transformer;
21
22 protected function setUp()
23 {
24 $this->transformer = new BooleanToStringTransformer(self::TRUE_VALUE);
25 }
26
27 protected function tearDown()
28 {
29 $this->transformer = null;
30 }
31
32 public function testTransform()
33 {
34 $this->assertEquals(self::TRUE_VALUE, $this->transformer->transform(true));
35 $this->assertNull($this->transformer->transform(false));
36 $this->assertNull($this->transformer->transform(null));
37 }
38
39 public function testTransformExpectsBoolean()
40 {
41 $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
42
43 $this->transformer->transform('1');
44 }
45
46 public function testReverseTransformExpectsString()
47 {
48 $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
49
50 $this->transformer->reverseTransform(1);
51 }
52
53 public function testReverseTransform()
54 {
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));
59 }
60 }