Author: smarr
Date: Sun Dec 30 20:04:25 2007
New Revision: 7044

Log:
- this commit will brake many tests but adds some missing features
  thus its a work in progress commit

Added:
    experimental/Reflection/tests/reflection_test.php
      - copied unchanged from r7040, 
experimental/Reflection/tests/extended_reflection_test.php
Removed:
    experimental/Reflection/tests/extended_reflection_test.php
Modified:
    experimental/Reflection/src/class.php
    experimental/Reflection/src/method.php
    experimental/Reflection/src/property.php
    experimental/Reflection/tests/class_external_test.php
    experimental/Reflection/tests/class_test.php
    experimental/Reflection/tests/extension_test.php
    experimental/Reflection/tests/parameter_test.php
    experimental/Reflection/tests/suite.php
    experimental/Reflection/tests/test_classes/SomeClass.php

Modified: experimental/Reflection/src/class.php
==============================================================================
--- experimental/Reflection/src/class.php [iso-8859-1] (original)
+++ experimental/Reflection/src/class.php [iso-8859-1] Sun Dec 30 20:04:25 2007
@@ -120,11 +120,10 @@
         } else {
             $constructor = parent::getConstructor();
         }
+        
         if ($constructor != null) {
-            $extCon = new ezcReflectionMethod($this->class, 
$constructor->getName());
-            return $extCon;
-        }
-        else {
+            return new ezcReflectionMethod($constructor);
+        } else {
             return null;
         }
     }
@@ -154,6 +153,24 @@
         }
         return $extMethods;
     }
+    
+    /**
+     * Returns an array of all interfaces implemented by the class.
+     * @return ezcReflectionClass[]
+     */
+    public function getInterfaces() {
+       if ( $this->class instanceof ReflectionClass ) {
+               $ifaces = $this->class->getInterfaces();
+       } else {
+               $ifaces = parent::getInterfaces();
+       }
+       
+       $result = array();
+       foreach ($ifaces as $i) {
+               $result[] = new ezcReflectionClassType($i);
+       }
+       return $result;
+    }
 
     /**
      * @return ezcReflectionClassType
@@ -204,16 +221,16 @@
      * ReflectionProperty::IS_PRIVATE
      * @return ezcReflectionProperty[]
      */
-    public function getProperties($filter = 0) {
-        if ($filter > 0) {
-            $props = parent::getProperties($filter);
-        } else {
-            $props = parent::getProperties();
-        }
+    public function getProperties($filter = null) {
+        if ( $this->reflectionSource ) {
+               $props = $this->reflectionSource->getProperties($filter);
+        } else {
+               $props = parent::getProperties($filter);
+        }
+        
         $extProps = array();
         foreach ($props as $prop) {
-            $extProps[] = new ezcReflectionProperty($this->getName(),
-                                                    $prop->getName());
+            $extProps[] = new ezcReflectionProperty( $prop );
         }
         return $extProps;
     }
@@ -265,11 +282,15 @@
      * @return ezcReflectionExtension
      */
     public function getExtension() {
-        $name = $this->getExtensionName();
-        if (!empty($name)) {
-            return new ezcReflectionExtension($name);
-        }
-        else {
+       if ( $this->class instanceof ReflectionClass ) {
+               $ext = $this->class->getExtension();
+       } else {
+               $ext = parent::getExtension();
+       }
+       
+        if ($ext) {
+            return new ezcReflectionExtension($ext);
+        } else {
             return null;
         }
     }

Modified: experimental/Reflection/src/method.php
==============================================================================
--- experimental/Reflection/src/method.php [iso-8859-1] (original)
+++ experimental/Reflection/src/method.php [iso-8859-1] Sun Dec 30 20:04:25 2007
@@ -31,12 +31,17 @@
      * @var ReflectionClass
      */
     protected $curClass;
-
-    /**
-    * @param mixed $class
-    * @param string $name
-    */
-    public function __construct($class, $name) {
+    
+    /**
+     * @var ReflectionMethod
+     */
+    protected $reflectionSource = null;
+
+    /**
+    * @param mixed $classOrSource name of class, ReflectionClass, or 
ReflectionMethod
+    * @param string $name Optional if $classOrSource is instance of 
ReflectionMethod
+    */
+    public function __construct($classOrSource, $name = null) {
                if ($class instanceof ReflectionClass) {
                        parent::__construct($class->getName(), $name);
             $this->curClass = $class;
@@ -207,5 +212,22 @@
                    return null;
                }
     }
+    
+    /**
+     * Use overloading to call additional methods
+     * of the reflection instance given to the constructor
+     *
+     * @param string $method Method to be called
+     * @param array(integer => mixed) $arguments Arguments that were passed
+     * @return mixed
+     */
+    public function __call( $method, $arguments )
+    {
+        if ( $this->reflectionSource ) {
+            return call_user_func_array( array($this->reflectionSource, 
$method), $arguments );
+        } else {
+            throw new Exception( 'Call to undefined method ' . __CLASS__ . 
'::' . $method );
+        }
+    }
 }
 ?>

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 20:04:25 
2007
@@ -194,6 +194,23 @@
             parent::setValue($object, $value);
         }
     }
+    
+       /**
+     * Use overloading to call additional methods
+     * of the reflection instance given to the constructor
+     *
+     * @param string $method Method to be called
+     * @param array(integer => mixed) $arguments Arguments that were passed
+     * @return mixed
+     */
+    public function __call( $method, $arguments )
+    {
+        if ( $this->reflectionSource ) {
+            return call_user_func_array( array($this->reflectionSource, 
$method), $arguments );
+        } else {
+            throw new Exception( 'Call to undefined method ' . __CLASS__ . 
'::' . $method );
+        }
+    }
        
 }
 ?>

Modified: experimental/Reflection/tests/class_external_test.php
==============================================================================
--- experimental/Reflection/tests/class_external_test.php [iso-8859-1] 
(original)
+++ experimental/Reflection/tests/class_external_test.php [iso-8859-1] Sun Dec 
30 20:04:25 2007
@@ -24,7 +24,67 @@
     {
         unset($this->class);
     }
-
+    
+       public function testCall() {
+               self::assertTrue($this->class->doSomeMetaProgramming());
+       }
+       
+       public function testGetMethod() {
+               parent::testGetMethod();
+               
+               $m = $this->class->getMethod('helloWorld');
+               self::assertTrue($m->change());
+       }
+       
+       public function testGetProperty() {
+               parent::testGetProperty();
+               
+               $prop = $this->class->getProperty('fields');
+               self::assertTrue($prop->change());
+       }
+       
+       public function testGetProperties() {
+               parent::testGetProperties();
+               
+               $props = $this->class->getProperties();
+               self::assertTrue($props[0]->change());
+       }
+       
+       public function testGetConstructor() {
+               parent::testGetConstructor();
+               
+               $ctr = $this->class->getConstructor();
+               self::assertTrue($ctr->change());
+       }
+       
+       public function testGetMethods() {
+               parent::testGetMethods();
+               
+               $ms = $this->class->getMethods();
+               self::assertTrue($ms[0]->change());
+       }
+    
+       public function testGetInterfaces() {
+               parent::testGetInterfaces();
+               
+               $is = $this->class->getInterfaces();
+               self::assertTrue($is[0]->change());
+       }
+       
+       public function testGetParentClass() {
+               parent::testGetParentClass();
+               
+               $parent = $this->class->getParentClass();
+               self::assertTrue($parent->change());
+       }
+       
+       public function testGetExtension() {
+               parent::testGetExtension();
+               
+               $ext = $this->class->getExtension();
+               self::assertTrue($ext->change());
+       }
+    
     public static function suite()
     {
          return new PHPUnit_Framework_TestSuite( 
"ezcReflectionClassExternalTest" );

Modified: experimental/Reflection/tests/class_test.php
==============================================================================
--- experimental/Reflection/tests/class_test.php [iso-8859-1] (original)
+++ experimental/Reflection/tests/class_test.php [iso-8859-1] Sun Dec 30 
20:04:25 2007
@@ -26,11 +26,6 @@
     public function testGetName() {
         self::assertEquals('SomeClass', $this->class->getName());
     }
-       
-       public function testCall() {
-               $myRefClass = new ezcReflectionClass(new 
MyReflectionClass('MyReflectionClass'));
-               self::assertTrue($myRefClass->doSomeMetaProgramming());
-       }
 
     public function testGetMethod() {
         $method = $this->class->getMethod('helloWorld');
@@ -43,7 +38,14 @@
         self::assertType('ezcReflectionMethod', $method);
         self::assertEquals($method->getName(), '__construct');
     }
+    
+       public function testGetInterfaces() {
+        $ifaces = $this->class->getInterfaces();
 
+        self::assertType('ezcReflectionClass', $ifaces[0]);
+        self::assertEquals('IInterface', $ifaces[0]->getName());
+        self::assertEquals(1, count($ifaces));
+    }
 
     public function testGetMethods() {
         $class = new ezcReflectionClass('TestWebservice');

Modified: experimental/Reflection/tests/extension_test.php
==============================================================================
--- experimental/Reflection/tests/extension_test.php [iso-8859-1] (original)
+++ experimental/Reflection/tests/extension_test.php [iso-8859-1] Sun Dec 30 
20:04:25 2007
@@ -10,27 +10,70 @@
 
 class ezcReflectionExtensionTest extends ezcTestCase
 {
+       /**
+        * @var ezcReflectionExtension
+        */
+       private $extRef;
+       private $extSpl;
+       
+    public function setUp() {
+        $this->extRef = new ezcReflectionExtension('Reflection');
+        $this->extSpl = new ezcReflectionExtension('Spl');
+    }
+
+    public function tearDown() {
+        unset($this->extRef);
+        unset($this->extSpl);
+    }
+       
     public function testGetFunctions() {
-        $ext = new ezcReflectionExtension('Spl');
-        $functs = $ext->getFunctions();
+        $functs = $this->extRef->getFunctions();
         foreach ($functs as $func) {
             self::assertType('ezcReflectionFunction', $func);
         }
-
-        $ext = new ezcReflectionExtension('Reflection');
-        $functs = $ext->getFunctions();
         self::assertEquals(0, count($functs));
     }
 
     public function testGetClasses() {
-        $ext = new ezcReflectionExtension('Reflection');
-        $classes = $ext->getClasses();
+        $classes = $this->extRef->getClasses();
 
         foreach ($classes as $class) {
             self::assertType('ezcReflectionClassType', $class);
         }
     }
-
+    
+    public function testGetName() {
+       self::assertEquals('Reflection', $this->extRef->getName());
+       self::assertEquals('SPL', $this->extSpl->getName());
+    }
+    
+    public function testGetVersion() {
+       $version = $this->extRef->getVersion();
+       self::assertFalse(empty($version));
+    }
+    
+    public function testInfo() {
+       ob_start();
+       $this->extRef->info();
+       $info = ob_get_clean(); 
+       self::assertFalse(empty($info));
+    }
+    
+    public function testGetConstants() {
+       $constants = $this->extRef->getConstants();
+       self::assertTrue(empty($constants));
+    }
+    
+    public function testGetINIEntries() {
+       $iniEntries = $this->extRef->getINIEntries();
+       self::assertTrue(empty($iniEntries));
+    }
+    
+    public function testGetClassNames() {
+       $classNames = $this->extRef->getClassNames();
+       self::assertFalse(empty($classNames));
+    }
+    
     public static function suite()
     {
          return new PHPUnit_Framework_TestSuite( "ezcReflectionExtensionTest" 
);

Modified: experimental/Reflection/tests/parameter_test.php
==============================================================================
--- experimental/Reflection/tests/parameter_test.php [iso-8859-1] (original)
+++ experimental/Reflection/tests/parameter_test.php [iso-8859-1] Sun Dec 30 
20:04:25 2007
@@ -91,13 +91,15 @@
                self::assertTrue($params[0]->allowsNull());
        }
        
-    public function isOptional() {
+    public function testIsOptional() {
                $func = new ezcReflectionFunction('mmm');
-               $param = $func->getParameter('t');
+               $param = $func->getParameters();
+               $param = $param[0];
                self::assertTrue($param->isOptional());
                
                $func = new ezcReflectionFunction('m1');
-               $param = $func->getParameter('test');
+               $param = $func->getParameters();
+               $param = $param[0];
                self::assertFalse($param->isOptional());
        }
        

Modified: experimental/Reflection/tests/suite.php
==============================================================================
--- experimental/Reflection/tests/suite.php [iso-8859-1] (original)
+++ experimental/Reflection/tests/suite.php [iso-8859-1] Sun Dec 30 20:04:25 
2007
@@ -9,7 +9,7 @@
 
 require_once 'class_test.php';
 require_once 'class_external_test.php';
-require_once 'extended_reflection_test.php';
+require_once 'reflection_test.php';
 require_once 'extension_test.php';
 require_once 'function_test.php';
 require_once 'method_test.php';
@@ -25,6 +25,7 @@
 require_once 'test_classes/methods2.php';
 require_once 'test_classes/MyReflectionClass.php';
 require_once 'test_classes/webservice.php';
+require_once 'test_classes/interface.php';
 require_once 'test_classes/BaseClass.php';
 require_once 'test_classes/SomeClass.php';
 

Modified: experimental/Reflection/tests/test_classes/SomeClass.php
==============================================================================
--- experimental/Reflection/tests/test_classes/SomeClass.php [iso-8859-1] 
(original)
+++ experimental/Reflection/tests/test_classes/SomeClass.php [iso-8859-1] Sun 
Dec 30 20:04:25 2007
@@ -5,7 +5,7 @@
 * @testclass
 * @ignore
 */
-class SomeClass extends BaseClass {
+class SomeClass extends BaseClass implements IInterface {
 
        /**
        * @var int[]


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

Reply via email to