ModelToIdTransformerTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. private $modelManager = null;
  15. public function setUp()
  16. {
  17. $this->modelManager = $this->getMock('Sonata\AdminBundle\Model\ModelManagerInterface');
  18. }
  19. public function testReverseTransformWhenPassing0AsId()
  20. {
  21. $transformer = new ModelToIdTransformer($this->modelManager,'TEST');
  22. $this->modelManager
  23. ->expects($this->exactly(2))
  24. ->method('find');
  25. //we pass 0 as integer
  26. // this must call the model manager find method... i not care what is returned, but must be called
  27. $transformer->reverseTransform(0);
  28. //we pass 0 as string
  29. //this must call the model manager find method... i not care what is returned, but must be called
  30. $transformer->reverseTransform('0');
  31. //we pass null must return null
  32. $this->assertNull($transformer->reverseTransform(null));
  33. //we pass false, must return null
  34. $this->assertNull($transformer->reverseTransform(false));
  35. }
  36. }