CallbackTransformerTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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\Component\Form\Tests;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Form\CallbackTransformer;
  13. class CallbackTransformerTest extends TestCase
  14. {
  15. public function testTransform()
  16. {
  17. $transformer = new CallbackTransformer(
  18. function ($value) { return $value.' has been transformed'; },
  19. function ($value) { return $value.' has reversely been transformed'; }
  20. );
  21. $this->assertEquals('foo has been transformed', $transformer->transform('foo'));
  22. $this->assertEquals('bar has reversely been transformed', $transformer->reverseTransform('bar'));
  23. }
  24. /**
  25. * @dataProvider invalidCallbacksProvider
  26. *
  27. * @expectedException \InvalidArgumentException
  28. */
  29. public function testConstructorWithInvalidCallbacks($transformCallback, $reverseTransformCallback)
  30. {
  31. new CallbackTransformer($transformCallback, $reverseTransformCallback);
  32. }
  33. public function invalidCallbacksProvider()
  34. {
  35. return array(
  36. array(null, function () {}),
  37. array(function () {}, null),
  38. );
  39. }
  40. }