Changeset 702

Show
Ignore:
Timestamp:
06/02/07 12:09:51 (1 year ago)
Author:
schst
Message:

Added test to illustrate ticket #54

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/test/php/net/stubbles/reflection/annotations/stubAnnotationFactoryTestCase.php

    r501 r702  
    2525    public $argh; 
    2626    public $veggie; 
    27      
     27 
    2828    /** 
    2929     * Returns the target of the annotation as bitmap. 
     
    3131     * @return  int 
    3232     */ 
    33     public function getAnnotationTarget() { return stubAnnotation::TARGET_ALL; }     
     33    public function getAnnotationTarget() { return stubAnnotation::TARGET_ALL; } 
    3434} 
    3535 
     
    5050{ 
    5151    public $value; 
    52     public function getAnnotationTarget() { return stubAnnotation::TARGET_ALL; }     
     52    public function getAnnotationTarget() { return stubAnnotation::TARGET_ALL; } 
    5353} 
    5454 
     
    6262class EmptyAnnotation extends stubAbstractAnnotation implements stubAnnotation 
    6363{ 
    64     public function getAnnotationTarget() { return stubAnnotation::TARGET_CLASS; }     
     64    public function getAnnotationTarget() { return stubAnnotation::TARGET_CLASS; } 
    6565} 
    6666 
     
    7777} 
    7878 
     79/** 
     80 * Annotation with class parameter 
     81 * 
     82 * @MyAnnotation( 
     83 *     foo=AnyTestClass.class 
     84 * ) 
     85 */ 
     86class AnotherTestClass { 
     87} 
     88 
    7989 
    8090/** 
     
    92102     */ 
    93103    protected $comment = "/**\n * a test docblock\n * \n * \n * @param  string  \$foo\n * @StubAnnotation(foo = 'blub');\n */"; 
    94      
     104 
    95105    protected $commentComplex = '/** 
    96106 * Foobar bla 
     
    104114 * @CastedAnnotation[AnotherAnnotation](false) 
    105115 * @EmptyAnnotation 
     116 */'; 
     117 
     118    protected $commentWithClass = '/** 
     119 * Foobar bla 
     120 * 
     121 * @access public 
     122 * @MyAnnotation( 
     123 *     foo=AnyTestClass.class 
     124 * ) 
    106125 */'; 
    107126 
     
    142161        $this->assertIsA($castedAnnotation, 'AnotherAnnotation'); 
    143162        $this->assertFalse($castedAnnotation->value); 
    144          
     163 
    145164        $this->expectException('ReflectionException'); 
    146165        stubAnnotationFactory::create($this->commentComplex, 'NonExisting', stubAnnotation::TARGET_CLASS, 'MyClass'); 
     166 
     167        $myAnnotation = stubAnnotationFactory::create($this->commentCommentWithClass, 'MyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass'); 
     168        $this->assertIsA($myAnnotation, 'MyAnnotation'); 
     169        $this->assertIsA($myAnnotation->foo, 'stubReflectionClass'); 
     170    } 
     171 
     172    /** 
     173     * test that the cache works as expected 
     174     */ 
     175    public function testReflectionClass() 
     176    { 
     177        $class = new stubReflectionClass('AnotherTestClass'); 
     178        $anno  = $class->getAnnotation('MyAnnotation'); 
    147179    } 
    148180 
     
    154186        $class = new stubReflectionClass('AnyTestClass'); 
    155187        $anno  = $class->getAnnotation('MyAnnotation'); 
    156          
     188 
    157189        // assert the values read from the annotation 
    158190        $this->assertIsA($anno, 'MyAnnotation'); 
     
    165197        $this->assertEqual('tomato', $anno->veggie); 
    166198 
    167         // re-fetch  
     199        // re-fetch 
    168200        $anno2  = $class->getAnnotation('MyAnnotation'); 
    169201        $this->assertIsA($anno2, 'MyAnnotation'); 
     
    175207        $class2 = new stubReflectionClass('AnyTestClass'); 
    176208        $anno3  = $class2->getAnnotation('MyAnnotation'); 
    177          
     209 
    178210        $this->assertIsA($anno, 'MyAnnotation'); 
    179211        $this->assertEqual('bar', $anno3->foo);