ModelToIdTransformerTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  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 Sonata\AdminBundle\Tests\Form\DataTransformer;
  11. use Sonata\AdminBundle\Form\DataTransformer\ModelToIdTransformer;
  12. class ModelToIdTransformerTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function setUp()
  15. {
  16. $this->modelManager = $this->getMock('Sonata\AdminBundle\Model\ModelManagerInterface');
  17. }
  18. public function testReverseTransformWhenPassing0AsId()
  19. {
  20. $transformer = new ModelToIdTransformer($this->modelManager,'TEST');
  21. $this->modelManager
  22. ->expects($this->exactly(2))
  23. ->method('find');
  24. //we pass 0 as integer
  25. // this must call the model manager find method... i not care what is returned, but must be called
  26. $transformer->reverseTransform(0);
  27. //we pass 0 as string
  28. //this must call the model manager find method... i not care what is returned, but must be called
  29. $transformer->reverseTransform('0');
  30. //we pass null must return null
  31. $this->assertNull($transformer->reverseTransform(null));
  32. //we pass false, must return null
  33. $this->assertNull($transformer->reverseTransform(false));
  34. }
  35. }
  36. class TEST {
  37. }