Changeset 1771

Show
Ignore:
Timestamp:
08/06/08 13:07:25 (4 months ago)
Author:
prema
Message:
  • add new test case for stubMetaClass
  • add/change properties and method fetching by meta class
Files:

Legend:

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

    r1770 r1771  
    1313); 
    1414/** 
    15  * Meta Object 
     15 * Meta Class 
    1616 * 
    17  * @package     stubbles_lang 
     17 * @package     stubbles 
    1818 * @subpackage  mop 
    1919 */ 
     
    2323     * register of specific meta methods name signature 
    2424     * 
    25      * @var array <string> 
     25     * @var array <string> 
    2626     */ 
    2727    protected $metaMethods = array(); 
    2828 
    2929    /** 
    30      * return only the specific supported meta method
     30     * register of specific meta property name
    3131     * 
    32      * @return  array 
     32     * @var  array <string> 
     33     */ 
     34    protected $metaProperties = array(); 
     35 
     36    /** 
     37     * obtain a list of all meta properties available on this meta class 
     38     * 
     39     * @return  array <string> 
     40     */ 
     41    public function getProperties() 
     42    { 
     43        if (empty($this->metaProperties)) { 
     44            foreach ($this->getClass()->getProperties() as $reflectionProperty) { 
     45                if ($reflectionProperty->isPublic() === true) { 
     46                    $this->metaProperties[] = $reflectionProperty->getName(); 
     47                } 
     48            } 
     49        } 
     50 
     51        return $this->metaProperties; 
     52    } 
     53 
     54    /** 
     55     * return only the specific supported meta methods names 
     56     * 
     57     * @return  array <string> 
    3358     */ 
    3459    public function getMethods() 
    3560    { 
     61        if (empty($this->metaMethods)) { 
     62            foreach ($this->getClass()->getMethods() as $reflectionMethod) { 
     63                if ($reflectionMethod->isPublic() === true) { 
     64                    $this->metaMethods[] = $reflectionMethod->getName(); 
     65                } 
     66            } 
     67        } 
     68 
    3669        return $this->metaMethods; 
    3770    } 
     
    71104        throw new stubMethodNotSupportedException( 
    72105            sprintf( 
    73                     'Not supported meta class method: %s on: %s' 
     106                    'Invoke unsupported meta class method: %s on: %s' 
    74107                ,   $method 
    75                 ,   $receiver->getClass()->getName() 
     108                ,   $receiver->getClassName() 
    76109            ) 
    77110        ); 
    78111    } 
    79112} 
    80  
    81113?> 
  • labs/incubator/src/test/php/net/stubbles/lang/LangTestSuite.php

    r1770 r1771  
    3535 
    3636        // lang::mop 
     37        $suite->addTestFile($dir . '/mop/stubMetaClassTestCase.php'); 
    3738        $suite->addTestFile($dir . '/mop/stubMetaObjectTestCase.php'); 
    3839 
  • labs/incubator/src/test/php/net/stubbles/lang/mop/stubMetaObjectTestCase.php

    r1770 r1771  
    4141    { 
    4242        $this->assertEquals('stubMetaClass', $this->stubMetaObject->getMetaClass()->getClass()->getName()); 
     43        $this->assertEquals('net::stubbles::lang::mop::stubMetaClass', $this->stubMetaObject->getMetaClass()->getClassName()); 
    4344    } 
    4445 
     
    5354        $this->stubMetaObject->unknownMethod(); 
    5455    } 
     56 
     57    /** 
     58     * test if can change the meta class instance for meta object 
     59     * 
     60     * @test 
     61     */ 
     62    public function canChangeMetaClassInstance() 
     63    { 
     64        $mock = $this->getMock('stubMetaClass'); 
     65        $meta = $this->stubMetaObject->getMetaClass(); 
     66 
     67        $this->assertNotEquals($meta, $this->stubMetaObject->setMetaClass($mock)->getMetaClass()); 
     68        $this->assertEquals($mock, $this->stubMetaObject->getMetaClass()); 
     69    } 
    5570} 
    5671?>