ChoiceUtilTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Form\Util;
  11. use Symfony\Component\Form\Util\ChoiceUtil;
  12. class ChoiceUtilTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function toValidChoiceProvider()
  15. {
  16. return array(
  17. array(0, 0),
  18. array('0', 0),
  19. array('1', 1),
  20. array(false, 0),
  21. array(true, 1),
  22. array('', ''),
  23. array(null, ''),
  24. array('1.23', '1.23'),
  25. array('foo', 'foo'),
  26. array('foo10', 'foo10'),
  27. );
  28. }
  29. /**
  30. * @dataProvider toValidChoiceProvider
  31. */
  32. public function testToValidChoice($in, $out)
  33. {
  34. $this->assertSame($out, ChoiceUtil::toValidChoice($in));
  35. }
  36. public function testToValidChoiceArray()
  37. {
  38. $in = $out = array();
  39. foreach ($this->toValidChoiceProvider() as $call) {
  40. $in[] = $call[0];
  41. $out[] = $call[1];
  42. }
  43. $this->assertSame($out, ChoiceUtil::toValidChoiceArray($in));
  44. }
  45. }