Ver código fonte

Added missing file, test-case for Commit r18000

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18001 44c647ce-9c0f-0410-b52a-842ac1e357ba
beberlei 16 anos atrás
pai
commit
b4e504b551
1 arquivos alterados com 178 adições e 0 exclusões
  1. 178 0
      tests/Zend/CodeGenerator/Php/ParameterTest.php

+ 178 - 0
tests/Zend/CodeGenerator/Php/ParameterTest.php

@@ -93,4 +93,182 @@ class Zend_CodeGenerator_Php_ParameterTest extends PHPUnit_Framework_TestCase
         $this->_parameter->setDefaultValue('foo');
         $this->assertEquals('Foo $bar = \'foo\'', $this->_parameter->generate());
     }
+
+    public function testFromReflection_GetParameterName()
+    {
+        $reflParam = $this->getFirstReflectionParameter('name');
+        $codeGenParam = Zend_CodeGenerator_Php_Parameter::fromReflection($reflParam);
+
+        $this->assertEquals('param', $codeGenParam->getName());
+    }
+
+    public function testFromReflection_GetParameterType()
+    {
+        $reflParam = $this->getFirstReflectionParameter('type');
+        $codeGenParam = Zend_CodeGenerator_Php_Parameter::fromReflection($reflParam);
+
+        $this->assertEquals('stdClass', $codeGenParam->getType());
+    }
+
+    public function testFromReflection_GetReference()
+    {
+        $reflParam = $this->getFirstReflectionParameter('reference');
+        $codeGenParam = Zend_CodeGenerator_Php_Parameter::fromReflection($reflParam);
+
+        $this->assertTrue($codeGenParam->getPassedByReference());
+    }
+
+    public function testFromReflection_GetDefaultValue()
+    {
+        $reflParam = $this->getFirstReflectionParameter('defaultValue');
+        $codeGenParam = Zend_CodeGenerator_Php_Parameter::fromReflection($reflParam);
+
+        $this->assertEquals('foo', $codeGenParam->getDefaultValue());
+    }
+
+    public function testFromReflection_GetArrayHint()
+    {
+        $reflParam = $this->getFirstReflectionParameter('fromArray');
+        $codeGenParam = Zend_CodeGenerator_Php_Parameter::fromReflection($reflParam);
+
+        $this->assertEquals('array', $codeGenParam->getType());
+    }
+
+    public function testFromReflection_GetWithNativeType()
+    {
+        $reflParam = $this->getFirstReflectionParameter('hasNativeDocTypes');
+        $codeGenParam = Zend_CodeGenerator_Php_Parameter::fromReflection($reflParam);
+
+        $this->assertNotEquals('int', $codeGenParam->getType());
+        $this->assertEquals('', $codeGenParam->getType());
+    }
+
+    static public function dataFromReflection_Generate()
+    {
+        return array(
+            array('name', '$param'),
+            array('type', 'stdClass $bar'),
+            array('reference', '&$baz'),
+            array('defaultValue', '$value = \'foo\''),
+            array('defaultNull', '$value = null'),
+            array('fromArray', 'array $array'),
+            array('hasNativeDocTypes', '$integer'),
+            array('defaultArray', '$array = array ()'),
+            array('defaultArrayWithValues', '$array = array (  0 => 1,  1 => 2,  2 => 3,)'),
+            array('defaultFalse', '$val = false'),
+            array('defaultTrue', '$val = true'),
+            array('defaultZero', '$number = 0'),
+            array('defaultNumber', '$number = 1234'),
+            array('defaultFloat', '$float = 1.34'),
+            array('defaultConstant', '$con = \'foo\'')
+        );
+    }
+
+    /**
+     * @dataProvider dataFromReflection_Generate
+     * @param string $methodName
+     * @param string $expectedCode
+     */
+    public function testFromReflection_Generate($methodName, $expectedCode)
+    {
+        $reflParam = $this->getFirstReflectionParameter($methodName);
+        $codeGenParam = Zend_CodeGenerator_Php_Parameter::fromReflection($reflParam);
+
+        $this->assertEquals($expectedCode, $codeGenParam->generate());
+    }
+
+    /**
+     * @param  string $method
+     * @return Zend_Reflection_Parameter
+     */
+    private function getFirstReflectionParameter($method)
+    {
+        $reflClass = new Zend_Reflection_Class('Zend_CodeGenerator_Php_ParameterExample');
+        $method = $reflClass->getMethod($method);
+
+        $params = $method->getParameters();
+        return array_shift($params);
+    }
+}
+
+class Zend_CodeGenerator_Php_ParameterExample
+{
+    public function name($param)
+    {
+        
+    }
+
+    public function type(stdClass $bar)
+    {
+        
+    }
+
+    public function reference(&$baz)
+    {
+        
+    }
+
+    public function defaultValue($value="foo")
+    {
+    }
+
+    public function defaultNull($value=null)
+    {
+        
+    }
+
+    public function fromArray(array $array)
+    {
+        
+    }
+
+    public function defaultArray($array = array())
+    {
+        
+    }
+
+    public function defaultFalse($val = false)
+    {
+
+    }
+
+    public function defaultTrue($val = true)
+    {
+        
+    }
+
+    public function defaultZero($number = 0)
+    {
+        
+    }
+
+    public function defaultNumber($number = 1234)
+    {
+
+    }
+
+    public function defaultFloat($float = 1.34)
+    {
+        
+    }
+
+    public function defaultArrayWithValues($array = array(0 => 1, 1 => 2, 2 => 3))
+    {
+        
+    }
+
+    const FOO = "foo";
+
+    public function defaultConstant($con = self::FOO)
+    {
+        
+    }
+
+    /**
+     * @param int $integer
+     */
+    public function hasNativeDocTypes($integer)
+    {
+
+    }
 }