浏览代码

adding unit test for ModelToIdTransformer in the cases where it gets 0 as id

Javier 12 年之前
父节点
当前提交
7f84139b83
共有 1 个文件被更改,包括 49 次插入0 次删除
  1. 49 0
      Tests/Form/DataTransformer/ModelToIdTransformerTest.php

+ 49 - 0
Tests/Form/DataTransformer/ModelToIdTransformerTest.php

@@ -0,0 +1,49 @@
+<?php
+/*
+ * This file is part of the Sonata package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\AdminBundle\Tests\Form\DataTransformer;
+
+use Sonata\AdminBundle\Form\DataTransformer\ModelToIdTransformer;
+
+class ModelToIdTransformerTest extends \PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        $this->modelManager = $this->getMock('Sonata\AdminBundle\Model\ModelManagerInterface');
+    }
+
+    public function testReverseTransformWhenPassing0AsId()
+    {
+        $transformer = new ModelToIdTransformer($this->modelManager,'TEST');
+        
+        
+        $this->modelManager
+                ->expects($this->exactly(2))
+                ->method('find');
+        
+        //we pass 0 as integer
+        // this must call the model manager find method... i not care what is returned, but must be called
+        $transformer->reverseTransform(0);
+        
+        //we pass 0 as string        
+        //this must call the model manager find method... i not care what is returned, but must be called
+        $transformer->reverseTransform('0');
+
+        //we pass null must return null
+        $this->assertNull($transformer->reverseTransform(null));
+
+        //we pass false, must return null
+        $this->assertNull($transformer->reverseTransform(false));
+    }
+}
+
+class TEST {
+
+}