Changeset 1773

Show
Ignore:
Timestamp:
08/06/08 14:20:36 (3 months ago)
Author:
prema
Message:
  • add new test for stubMetaClass
  • fix the reflection call
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • labs/incubator/src/main/php/net/stubbles/lang/mop/stubMetaClass.php

    r1772 r1773  
    1111                      'net::stubbles::lang::exceptions::stubMethodNotSupportedException', 
    1212                      'net::stubbles::lang::mop::stubMetaObjectProtocol', 
     13                      'net::stubbles::reflection::stubReflectionMethod', 
    1314                      'net::stubbles::reflection::stubReflectionObject' 
    1415); 
     
    7273 
    7374    /** 
     75     * returns true of the implementing MetaClass has a method of the given name 
     76     * 
     77     * Note that this method will only return true for realised method and does 
     78     * not take into account implementation of invokeMethod or invokeMissingMethod 
     79     * 
     80     * @return  boolean 
     81     */ 
     82    public function hasMethod($methodName) 
     83    { 
     84        return in_array($methodName, $this->getMethods()); 
     85    } 
     86 
     87    /** 
    7488     * invokes a method on the given receiver with the specified arguments 
    7589     * 
     
    8094     * @throws  stubMethodNotSupportedException 
    8195     */ 
    82     public function invokeMethod(stubMetaObjectProtocol $receiver, $method, array $arguments
     96    public function invokeMethod(stubMetaObjectProtocol $receiver, $method, array $arguments = array()
    8397    { 
    84         if (in_array($method, $this->getMethods())) { 
    85             return $this->getClass()->getMethod($method)->invoke($arguments); 
     98        if ($this->hasMethod($method)) { 
     99            return ($this->getClass()->getMethod($method)->invokeArgs($this, $arguments)); 
    86100        } 
    87101 
  • labs/incubator/src/test/php/net/stubbles/lang/mop/stubMetaClassTestCase.php

    r1771 r1773  
    77 * @subpackage  lang_mop_test 
    88 */ 
    9 stubClassLoader::load('net::stubbles::lang::mop::stubMetaClass'); 
     9stubClassLoader::load('net::stubbles::lang::mop::stubMetaClass', 
     10                      'net::stubbles::lang::mop::stubMetaObject' 
     11); 
    1012/** 
    1113 * Tests for net::stubbles::lang::mop::stubMetaClass. 
     
    4547                'getProperties', 
    4648                'getMethods', 
     49                'hasMethod', 
    4750                'invokeMethod', 
    4851                'invokeMissingMethod', 
     
    7174        ); 
    7275    } 
     76 
     77    /** 
     78     * test invoke a method on meta class 
     79     * 
     80     * @test 
     81     */ 
     82    public function canInvokeMethodSuccessfulIfExists() 
     83    { 
     84        $this->assertEquals( 
     85            $this->stubMetaClass->invokeMethod(new stubMetaObject, 'getClass'), 
     86            'net::stubbles::lang::mop::stubMetaClass' 
     87        ); 
     88    } 
    7389} 
    7490?>