]>
Commit | Line | Data |
---|---|---|
4f5b44bd NL |
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\ChoiceList\SimpleChoiceList; | |
15 | ||
16 | use Symfony\Component\Form\Extension\Core\DataTransformer\ChoicesToValuesTransformer; | |
17 | ||
18 | class ChoicesToValuesTransformerTest extends \PHPUnit_Framework_TestCase | |
19 | { | |
20 | protected $transformer; | |
21 | ||
22 | protected function setUp() | |
23 | { | |
24 | $list = new SimpleChoiceList(array(0 => 'A', 1 => 'B', 2 => 'C')); | |
25 | $this->transformer = new ChoicesToValuesTransformer($list); | |
26 | } | |
27 | ||
28 | protected function tearDown() | |
29 | { | |
30 | $this->transformer = null; | |
31 | } | |
32 | ||
33 | public function testTransform() | |
34 | { | |
35 | // Value strategy in SimpleChoiceList is to copy and convert to string | |
36 | $in = array(0, 1, 2); | |
37 | $out = array('0', '1', '2'); | |
38 | ||
39 | $this->assertSame($out, $this->transformer->transform($in)); | |
40 | } | |
41 | ||
42 | public function testTransformNull() | |
43 | { | |
44 | $this->assertSame(array(), $this->transformer->transform(null)); | |
45 | } | |
46 | ||
47 | /** | |
48 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | |
49 | */ | |
50 | public function testTransformExpectsArray() | |
51 | { | |
52 | $this->transformer->transform('foobar'); | |
53 | } | |
54 | ||
55 | public function testReverseTransform() | |
56 | { | |
57 | // values are expected to be valid choices and stay the same | |
58 | $in = array('0', '1', '2'); | |
59 | $out = array(0, 1, 2); | |
60 | ||
61 | $this->assertSame($out, $this->transformer->reverseTransform($in)); | |
62 | } | |
63 | ||
64 | public function testReverseTransformNull() | |
65 | { | |
66 | $this->assertSame(array(), $this->transformer->reverseTransform(null)); | |
67 | } | |
68 | ||
69 | /** | |
70 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | |
71 | */ | |
72 | public function testReverseTransformExpectsArray() | |
73 | { | |
74 | $this->transformer->reverseTransform('foobar'); | |
75 | } | |
76 | } |