* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer; use PHPUnit\Framework\TestCase; use Symfony\Component\Form\ChoiceList\ArrayChoiceList; use Symfony\Component\Form\Extension\Core\DataTransformer\ChoiceToValueTransformer; class ChoiceToValueTransformerTest extends TestCase { protected $transformer; protected $transformerWithNull; protected function setUp() { $list = new ArrayChoiceList(array('', false, 'X', true)); $listWithNull = new ArrayChoiceList(array('', false, 'X', null)); $this->transformer = new ChoiceToValueTransformer($list); $this->transformerWithNull = new ChoiceToValueTransformer($listWithNull); } protected function tearDown() { $this->transformer = null; $this->transformerWithNull = null; } public function transformProvider() { return array( // more extensive test set can be found in FormUtilTest array('', '', '', '0'), array(false, '0', false, '1'), array('X', 'X', 'X', '2'), array(true, '1', null, '3'), ); } /** * @dataProvider transformProvider */ public function testTransform($in, $out, $inWithNull, $outWithNull) { $this->assertSame($out, $this->transformer->transform($in)); $this->assertSame($outWithNull, $this->transformerWithNull->transform($inWithNull)); } public function reverseTransformProvider() { return array( // values are expected to be valid choice keys already and stay // the same array('', '', '0', ''), array('0', false, '1', false), array('X', 'X', '2', 'X'), array('1', true, '3', null), ); } /** * @dataProvider reverseTransformProvider */ public function testReverseTransform($in, $out, $inWithNull, $outWithNull) { $this->assertSame($out, $this->transformer->reverseTransform($in)); $this->assertSame($outWithNull, $this->transformerWithNull->reverseTransform($inWithNull)); } public function reverseTransformExpectsStringOrNullProvider() { return array( array(0), array(true), array(false), array(array()), ); } /** * @dataProvider reverseTransformExpectsStringOrNullProvider * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException */ public function testReverseTransformExpectsStringOrNull($value) { $this->transformer->reverseTransform($value); } } __halt_compiler();----SIGNATURE:----VYj6LK+JXVJLNHs+BjJJw4Obk9WXf/zHcQdIi7MZ+e5EuY95UwQdOkjieN7vexguxDKeRn1SbN55oE7oFG74fQ9bVJcmApQcYTnHYv/PrqbVlHil2r8BdxBHiF440BI55wmSuxjNOnxEFeDcuJE8bm84g2IfN4UA9AGrIXWZhgUd8WB3D08BhUa28TR9SK06/WRpi8Kin7Ui5oIsOrcJDnSaDyshPm+9Z/kzXtPZO1LtGp+Nv1weBW+1cDeNIh/oO9eE0op0yLGphpz1Xsjt2zAKh33JUEVO2e/dovsqU2gOTiy668L1tJSIvSGHK3RAWTV/KMr7PR64CEsnkmU1yya7nK5epxyOY0GUuAxmBqeWBUSeRGmeaTfbkkvzKTFxTuS4l62IBYHwb8yj+kcca/JQbtBmh7OnIswdQuq7/wEN6XJlWxppM0avKwWsJ1NUBqwf5y6Rvrj5Wir928J2K50XpmAMDgBlp9KvApos8idDf372WNEJc9ap0JSlLoclv+DyLp7Xun6FJdCuFMZrkVnagwKWR7V/fsPVdKcRGH7/XBJ27qAPBNTMknb1mcpfJYIwiMM49QVyY6vAWBnBpy7cWmldLAqRMcb9RJFgbAh/eJqgTeyoUuvBrOJY766coa1R+tT9AHUtnJXiueUVy61q1TnOlX6Y92hJCXrdbgs=----ATTACHMENT:----MzM2MDY2MDkzOTk4OTQ0MSA0Njk1NDAzMTc3NTUwNjI0IDIyNzQyNzEzMjU2OTQ0NDM=