* * 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:----KYPIItTdlsj9rEDzpfpso/tw3CzPismYdOYTXHK2vo0G3jGcsdjLd3ehWU1iNkE+WdVGGHou5RPMvUNqKG2GuKBxH+OOF3dK/hKLIYw2VVpXDsd9p6SYsjoy/JpvzQqus79cqE3rgaWbqz/R8jdWv8xUcThekAC8/1IZ7EKpm8pYzRbpoIYwiJ19BU6yBc41rmfL8PH1y2Kapb0ZUEi3IakRjTB5rMY7sol4olSLmvsJQFcTxaSucj6Ba02b8TcNtJSRyFLshpuj116PV17A/DofTwl1NQeFwfgRczp23GgV6eTTJeHi6k3/ZqoNShc13ZQnayIlMieTAzFhwBgRJfC0Hhk/LdG1x9bK1uRAoAQIRxfdvcPO+b0mGdFIXjubBDTZs+Qs1mLu45Q8AAb6lPAXixgLXymGeuHll+aeHpro+hhdxjhum8WKzGDRf+irPTujC/h7+8Y2SRyLxHTPfzerl42rpKEX1dDWx+38E4wvJE1CpMzvN4H21jDWtXXC0eL2h+cg3ZzlNM3H1WIa9VuOy9m5HT8sOkoZLG6h6wGfXElrcbNkD7FzIF+aQU0N7n8FAj3y0RXcbt/aCYU07Hs8MQGJ17Pp179KI/QNa9HQOf5KFBgsxQyfRyzW8F+fAfy2wXcyL3iCKpz+DFsqmpxjHDwCaO+MtdFpjaECCuw=----ATTACHMENT:----NzA4Njc3MTAwNDQxNzc0OCAyMzQ3MzY3MzcxNTIyMjE0IDc4MDc1Mzg5OTA4Mjg1MjY=