Author: smarr
Date: Sun Dec 30 15:14:24 2007
New Revision: 7043

Log:
- fixed bug in array_type.php, had been introduced by renaming with 
search&replaceall
- fixed signature of getValue and setValue in ezcReflectionProperty
- added missing test cases for ezcReflectionFunction and ezcReflectionMethod
- TODO: test cases for delegation

Modified:
    experimental/Reflection/src/function.php
    experimental/Reflection/src/property.php
    experimental/Reflection/src/types/array_type.php
    experimental/Reflection/tests/function_test.php
    experimental/Reflection/tests/method_test.php
    experimental/Reflection/tests/property_test.php
    experimental/Reflection/tests/test_classes/functions.php
    experimental/Reflection/tests/test_classes/methods.php

Modified: experimental/Reflection/src/function.php
==============================================================================
--- experimental/Reflection/src/function.php [iso-8859-1] (original)
+++ experimental/Reflection/src/function.php [iso-8859-1] Sun Dec 30 15:14:24 
2007
@@ -22,12 +22,23 @@
     * @var ezcReflectionDocParser
     */
     protected $docParser;
+    
+    /**
+     * ReflectionFunction object or name used to initialize this object
+     *
+     * @var string|ReflectionFunction
+     */
+    protected $reflectionSource;
 
     /**
     * @param string $name
     */
     public function __construct($name) {
-        parent::__construct($name);
+       if ( !$name instanceof ReflectionFunction ) {
+               parent::__construct($name);
+       }
+       $this->reflectionSource = $name;
+       
         $this->docParser = ezcReflectionApi::getDocParserInstance();
         $this->docParser->parse($this->getDocComment());
     }
@@ -122,5 +133,13 @@
             return $this->docParser->getTagsByName($name);
         }
     }
+    
+    public function isDisabled() {
+       if ($this->reflectionSource instanceof ReflectionFunction ) {
+               return $this->reflectionSource->isDisabled();
+       } else {
+               return parent::isDisabled();
+       }
+    }
 }
 ?>

Modified: experimental/Reflection/src/property.php
==============================================================================
--- experimental/Reflection/src/property.php [iso-8859-1] (original)
+++ experimental/Reflection/src/property.php [iso-8859-1] Sun Dec 30 15:14:24 
2007
@@ -176,7 +176,7 @@
        /**
      * @return mixed
      */
-    public function getValue($object) {
+    public function getValue($object = null) {
         if ( $this->reflectionSource instanceof ReflectionProperty ) {
             return $this->reflectionSource->getValue($object);
         } else {
@@ -187,7 +187,7 @@
        /**
         * @param mixed $value
      */
-    public function setValue($object, $value) {
+    public function setValue($object = null, $value) {
         if ( $this->reflectionSource instanceof ReflectionProperty ) {
             $this->reflectionSource->setValue($object, $value);
         } else {

Modified: experimental/Reflection/src/types/array_type.php
==============================================================================
--- experimental/Reflection/src/types/array_type.php [iso-8859-1] (original)
+++ experimental/Reflection/src/types/array_type.php [iso-8859-1] Sun Dec 30 
15:14:24 2007
@@ -52,7 +52,7 @@
      * Returns type of array items or null
      * @return ezcReflectionType
      */
-    public function getezcReflectionArrayType()
+    public function getArrayType()
     {
         return $this->arrayType;
     }
@@ -118,13 +118,13 @@
             if ($posm !== false) {
                 if ($posm < $pos) {
                     $typeName = substr($this->typeName, 0, $pos);
-                    $this->ezcReflectionArrayType
+                    $this->arrayType
                        = ezcReflectionApi::getTypeByName($typeName);
                 }
             }
             else {
                 $typeName = substr($this->typeName, 0, $pos);
-                $this->ezcReflectionArrayType
+                $this->arrayType
                    = ezcReflectionApi::getTypeByName($typeName);
             }
         }
@@ -139,10 +139,10 @@
             }
 
             if ($type1 == null and $type2 != null) {
-                $this->ezcReflectionArrayType = $type2;
+                $this->arrayType = $type2;
             }
             elseif ($type1 != null and $type2 == null) {
-                $this->ezcReflectionArrayType = $type1;
+                $this->arrayType = $type1;
             }
             elseif ($type1 != null and $type2 != null) {
                 $this->mapKeyType = $type1;
@@ -158,7 +158,7 @@
     public function toString()
     {
         if ($this->isArray()) {
-            return $this->ezcReflectionArrayType->toString().'[]';
+            return $this->arrayType->toString().'[]';
         }
         else if ($this->isMap()) {
             return 'array<'.$this->mapKeyType->toString()
@@ -191,7 +191,7 @@
             $prefix = '';
         }
         if ($this->isArray()) {
-            return $prefix . 
'ArrayOf'.$this->ezcReflectionArrayType->getXmlName(false);
+            return $prefix . 'ArrayOf'.$this->arrayType->getXmlName(false);
         }
         elseif ($this->isMap()) {
             throw new Exception('XML Schema mapping is not supported for 
map-types');
@@ -240,8 +240,8 @@
         $elm->setAttribute('maxOccurs', 'unbounded');
         $elm->setAttribute('nillable', 'true');
 
-        $elm->setAttribute('name', 
$this->ezcReflectionArrayType->getXmlName(false));
-        $elm->setAttribute('type', 
$this->ezcReflectionArrayType->getXmlName(true));
+        $elm->setAttribute('name', $this->arrayType->getXmlName(false));
+        $elm->setAttribute('type', $this->arrayType->getXmlName(true));
 
         return $schema;
     }

Modified: experimental/Reflection/tests/function_test.php
==============================================================================
--- experimental/Reflection/tests/function_test.php [iso-8859-1] (original)
+++ experimental/Reflection/tests/function_test.php [iso-8859-1] Sun Dec 30 
15:14:24 2007
@@ -10,42 +10,59 @@
 
 class ezcReflectionFunctionTest extends ezcTestCase
 {
+       /**
+     * @var ezcReflectionFunction
+     */
+    protected $fctM1;
+    protected $fctM2;
+    protected $fctM3;
+
+    public function setUp() {
+        $this->fctM1 = new ezcReflectionFunction('m1');
+        $this->fctM2 = new ezcReflectionFunction('m2');
+        $this->fctM3 = new ezcReflectionFunction('m3');
+    }
+
+    public function tearDown() {
+        unset($this->fctM1);
+        unset($this->fctM2);
+        unset($this->fctM3);
+    }
+       
     public function testGetTags() {
-        $func = new ezcReflectionFunction('m1');
+        $func = $this->fctM1;
         $tags = $func->getTags();
 
         $expectedTags = array('webmethod', 'author', 'param', 'param', 
'param', 'return');
         ReflectionTestHelper::expectedTags($expectedTags, $tags, $this);
 
 
-        $func = new ezcReflectionFunction('m2');
+        $func = $this->fctM2;
         $tags = $func->getTags();
         $expectedTags = array('param', 'author');
         ReflectionTestHelper::expectedTags($expectedTags, $tags, $this);
     }
 
     public function testIsTagged() {
-        $func = new ezcReflectionFunction('m1');
+        $func = $this->fctM1;
         self::assertFalse($func->isTagged('licence'));
-
-        $func = new ezcReflectionFunction('m1');
         self::assertTrue($func->isTagged('webmethod'));
     }
 
     public function testGetLongDescription() {
-        $func = new ezcReflectionFunction('m1');
-        $desc = $func->getLongDescription();
-
-        $expected = '';
-        self::assertEquals($expected, $desc);
-
-        $func = new ezcReflectionFunction('m2');
-        $desc = $func->getLongDescription();
-
-        $expected = '';
-        self::assertEquals($expected, $desc);
-
-        $func = new ezcReflectionFunction('m3');
+        $func = $this->fctM1;
+        $desc = $func->getLongDescription();
+
+        $expected = '';
+        self::assertEquals($expected, $desc);
+
+        $func = $this->fctM2;
+        $desc = $func->getLongDescription();
+
+        $expected = '';
+        self::assertEquals($expected, $desc);
+
+        $func = $this->fctM3;
         $desc = $func->getLongDescription();
 
         $expected = '';
@@ -64,17 +81,17 @@
     }
 
     public function testGetShortDescription() {
-        $func = new ezcReflectionFunction('m1');
+        $func = $this->fctM1;
         $desc = $func->getShortDescription();
         $expected = 'To check whether a tag was used';
         self::assertEquals($expected, $desc);
 
-        $func = new ezcReflectionFunction('m2');
-        $desc = $func->getShortDescription();
-        $expected = '';
-        self::assertEquals($expected, $desc);
-
-        $func = new ezcReflectionFunction('m3');
+        $func = $this->fctM2;
+        $desc = $func->getShortDescription();
+        $expected = '';
+        self::assertEquals($expected, $desc);
+
+        $func = $this->fctM3;
         $desc = $func->getShortDescription();
         $expected = '';
         self::assertEquals($expected, $desc);
@@ -86,15 +103,15 @@
     }
 
     public function testIsWebmethod() {
-        $func = new ezcReflectionFunction('m1');
+        $func = $this->fctM1;
         self::assertTrue($func->isWebmethod());
 
-        $func = new ezcReflectionFunction('m2');
+        $func = $this->fctM2;
         self::assertFalse($func->isWebmethod());
     }
 
     public function testGetReturnDescription() {
-        $func = new ezcReflectionFunction('m1');
+        $func = $this->fctM1;
         $desc = $func->getReturnDescription();
         self::assertEquals('Hello World', $desc);
 
@@ -120,11 +137,71 @@
         $expected = array('test', 'test2', 'test3');
         ReflectionTestHelper::expectedParams($expected, $params, $this);
 
-        $func = new ezcReflectionFunction('m3');
+        $func = $this->fctM3;
         $params = $func->getParameters();
         self::assertTrue(count($params) == 0);
     }
 
+    public function testGetName() {
+       self::assertEquals('m1', $this->fctM1->getName());
+       self::assertEquals('m2', $this->fctM2->getName());
+    }
+       
+    public function testIsInternal() {
+       self::assertFalse($this->fctM1->isInternal());
+    }
+    
+    public function testIsDisabled() {
+       self::assertFalse($this->fctM1->isDisabled());
+    }
+    
+    public function testIsUserDefined() {
+       self::assertTrue($this->fctM1->isUserDefined());
+    }
+    
+    public function testGetFileName() {
+       self::assertEquals('functions.php', 
basename($this->fctM1->getFileName()));
+    }
+    
+    public function testGetStartLine() {
+       self::assertEquals(12, $this->fctM1->getStartLine());
+    }
+    
+    public function testGetEndLine() {
+       self::assertEquals(14, $this->fctM1->getEndLine());
+    }
+    
+    public function testGetDocComment() {
+       self::assertEquals("/**
+ * @param void \$DocuFlaw
+ * @author flaw joe
+ */", $this->fctM2->getDocComment());
+    }
+    
+    public function testGetStaticVariables() {
+       $vars = $this->fctM3->getStaticVariables();
+       self::assertEquals(1, count($vars));
+       self::assertTrue(array_key_exists('staticVar', $vars));
+    }
+    
+    //public mixed invoke([mixed args [, ...]])
+    //public mixed invokeArgs(array args)
+    
+    public function testReturnsReference() {
+       self::assertFalse($this->fctM3->returnsReference());
+    }
+    
+    public function testGetNumberOfParameters() {
+       self::assertEquals(3, $this->fctM1->getNumberOfParameters());
+       $func = new ReflectionFunction('mmm');
+       self::assertEquals(1, $func->getNumberOfParameters());
+    }
+    public function testGetNumberOfRequiredParameters() {
+       self::assertEquals(3, $this->fctM1->getNumberOfRequiredParameters());
+       $func = new ReflectionFunction('mmm');
+       self::assertEquals(0, $func->getNumberOfRequiredParameters());
+    }
+    
     public static function suite()
     {
          return new PHPUnit_Framework_TestSuite( "ezcReflectionFunctionTest" );

Modified: experimental/Reflection/tests/method_test.php
==============================================================================
--- experimental/Reflection/tests/method_test.php [iso-8859-1] (original)
+++ experimental/Reflection/tests/method_test.php [iso-8859-1] Sun Dec 30 
15:14:24 2007
@@ -8,20 +8,30 @@
  * @subpackage Tests
  */
 
-class ezcReflectionMethodTest extends ezcTestCase
+class ezcReflectionMethodTest extends ezcReflectionFunctionTest 
 {
+       public function setUp() {
+        $this->fctM1 = new ezcReflectionMethod('TestMethods', 'm1');
+        $this->fctM2 = new ezcReflectionMethod('TestMethods', 'm2');
+        $this->fctM3 = new ezcReflectionMethod('TestMethods', 'm3');
+    }
+
+    public function tearDown() {
+        unset($this->fctM1);
+        unset($this->fctM2);
+        unset($this->fctM3);
+    }
+       
     public function testGetDeclaringClass() {
-        $method = new ezcReflectionMethod('TestMethods', 'm1');
-        $class = $method->getDeclaringClass();
+        $class = $this->fctM1->getDeclaringClass();
         self::assertType('ezcReflectionClassType', $class);
         self::assertEquals('TestMethods', $class->getName());
     }
 
     public function testIsMagic() {
-        $method = new ezcReflectionMethod('TestMethods', 'm1');
-        self::assertFalse($method->isMagic());
-
-        $class = $method->getDeclaringClass();
+        self::assertFalse($this->fctM1->isMagic());
+
+        $class = $this->fctM1->getDeclaringClass();
         self::assertTrue($class->getConstructor()->isMagic());
     }
 
@@ -54,24 +64,21 @@
     }
 
     public function testGetLongDescription() {
-        $method = new ezcReflectionMethod('TestMethods', 'm3');
-        $desc = $method->getLongDescription();
+        $desc = $this->fctM3->getLongDescription();
 
         $expected = "This is the long description with may be additional infos 
and much more lines\nof text.\n\nEmpty lines are valide to.\n\nfoo bar";
         self::assertEquals($expected, $desc);
     }
 
     public function testGetShortDescription() {
-        $method = new ezcReflectionMethod('TestMethods', 'm3');
-        $desc = $method->getShortDescription();
+        $desc = $this->fctM3->getShortDescription();
 
         $expected = "This is the short description";
         self::assertEquals($expected, $desc);
     }
 
     public function testIsWebmethod() {
-        $method = new ezcReflectionMethod('TestMethods', 'm3');
-        self::assertFalse($method->isWebmethod());
+        self::assertFalse($this->fctM3->isWebmethod());
         $method = new ezcReflectionMethod('TestMethods', 'm4');
         self::assertTrue($method->isWebmethod());
     }
@@ -145,7 +152,86 @@
         $method = new ezcReflectionMethod('TestMethods2', 'm4');
         self::assertFalse($method->isIntroduced());
     }
-
+    
+       public function testIsDisabled() {
+       // is not available for methods
+    }
+    
+       public function testGetFileName() {
+       self::assertEquals('methods.php', 
basename($this->fctM1->getFileName()));
+    }
+    
+    public function testGetStartLine() {
+       self::assertEquals(16, $this->fctM1->getStartLine());
+    }
+    
+    public function testGetEndLine() {
+       self::assertEquals(18, $this->fctM1->getEndLine());
+    }
+    
+       public function testGetDocComment() {
+       self::assertEquals("/**
+     * @foo
+     * @bar
+     * @foobar
+     */", $this->fctM2->getDocComment());
+    }
+    
+       public function testGetNumberOfParameters() {
+       self::assertEquals(1, $this->fctM3->getNumberOfParameters());
+       self::assertEquals(0, $this->fctM1->getNumberOfParameters());
+    }
+    
+    public function testGetNumberOfRequiredParameters() {
+       self::assertEquals(0, $this->fctM1->getNumberOfRequiredParameters());
+       self::assertEquals(1, $this->fctM3->getNumberOfRequiredParameters());
+    }
+    
+    public function testIsFinal() {
+       self::assertFalse($this->fctM1->isFinal());
+       self::assertFalse($this->fctM2->isFinal());
+    }
+    
+       public function testIsAbstract() {
+       self::assertFalse($this->fctM1->isAbstract());
+       self::assertFalse($this->fctM2->isAbstract());
+    }
+    
+       public function testIsPublic() {
+       self::assertTrue($this->fctM1->isPublic());
+       self::assertTrue($this->fctM2->isPublic());
+    }
+    
+       public function testIsPrivate() {
+       self::assertFalse($this->fctM1->isPrivate());
+       self::assertFalse($this->fctM2->isPrivate());
+    }
+    
+       public function testIsProtected() {
+       self::assertFalse($this->fctM1->isProtected());
+       self::assertFalse($this->fctM2->isProtected());
+    }
+    
+       public function testIsStatic() {
+       self::assertFalse($this->fctM1->isStatic());
+       self::assertFalse($this->fctM2->isStatic());
+    }
+    
+       public function testIsConstructor() {
+       self::assertFalse($this->fctM1->isConstructor());
+       self::assertFalse($this->fctM2->isConstructor());
+    }
+    
+       public function testIsDestructor() {
+       self::assertFalse($this->fctM1->isDestructor());
+       self::assertFalse($this->fctM2->isDestructor());
+    }
+    
+       public function testGetModifiers() {
+       self::assertEquals(65792, $this->fctM1->getModifiers());
+       self::assertEquals(65792, $this->fctM2->getModifiers());
+    }
+    
     public static function suite()
     {
          return new PHPUnit_Framework_TestSuite( "ezcReflectionMethodTest" );

Modified: experimental/Reflection/tests/property_test.php
==============================================================================
--- experimental/Reflection/tests/property_test.php [iso-8859-1] (original)
+++ experimental/Reflection/tests/property_test.php [iso-8859-1] Sun Dec 30 
15:14:24 2007
@@ -27,7 +27,7 @@
     public function testGetType() {
         $type = $this->refProp->getType();
         self::assertType('ezcReflectionArrayType', $type);
-        self::assertEquals('int[]', $type->toString());
+        self::assertEquals('integer[]', $type->toString());
     }
 
     public function testGetDeclaringClass() {

Modified: experimental/Reflection/tests/test_classes/functions.php
==============================================================================
--- experimental/Reflection/tests/test_classes/functions.php [iso-8859-1] 
(original)
+++ experimental/Reflection/tests/test_classes/functions.php [iso-8859-1] Sun 
Dec 30 15:14:24 2007
@@ -24,7 +24,7 @@
 }
 
 function m3() {
-
+       static $staticVar;
 }
 
 /**

Modified: experimental/Reflection/tests/test_classes/methods.php
==============================================================================
--- experimental/Reflection/tests/test_classes/methods.php [iso-8859-1] 
(original)
+++ experimental/Reflection/tests/test_classes/methods.php [iso-8859-1] Sun Dec 
30 15:14:24 2007
@@ -37,7 +37,7 @@
      * foo bar
      */
     public function m3($undocumented) {
-
+               static $staticVar;
     }
 
 


-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to