Changeset 1072
- Timestamp:
- 11/27/07 09:21:08 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationAnnotationState.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationArgumentState.php (added)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationNameState.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationState.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParser.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationStateParser.php (modified) (4 diffs)
- trunk/src/main/php/net/stubbles/reflection/annotations/stubAnnotation.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/reflection/annotations/stubAnnotationFactory.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/reflection/stubReflectionParameter.php (modified) (4 diffs)
- trunk/src/test/php/net/stubbles/reflection/ReflectionTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationAnnotationStateTestCase.php (modified) (5 diffs)
- trunk/src/test/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationArgumentStateTestCase.php (added)
- trunk/src/test/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationNameStateTestCase.php (modified) (6 diffs)
- trunk/src/test/php/net/stubbles/reflection/annotations/parser/stubAnnotationStateParserTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/reflection/annotations/stubAnnotationFactoryApplicableTestCase.php (modified) (18 diffs)
- trunk/src/test/php/net/stubbles/reflection/annotations/stubAnnotationFactoryTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/reflection/stubReflectionParameterTestCase.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationAnnotationState.php
r488 r1072 31 31 } 32 32 33 if ('{' === $token) { 34 $this->parser->changeState(stubAnnotationState::ARGUMENT); 35 return; 36 } 37 33 38 if ('[' === $token) { 34 39 $this->parser->changeState(stubAnnotationState::ANNOTATION_TYPE); trunk/src/main/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationNameState.php
r490 r1072 35 35 return $this->name; 36 36 } 37 37 38 38 /** 39 39 * mark this state as the currently used state … … 75 75 } 76 76 77 if ('{' === $token) { 78 if (strlen($this->name) == 0) { 79 throw new ReflectionException('Annotation name can not be empty'); 80 } 81 82 $this->checkName(); 83 $this->parser->registerAnnotation($this->name); 84 $this->parser->changeState(stubAnnotationState::ARGUMENT); 85 return; 86 } 87 77 88 if ('[' === $token) { 78 89 if (strlen($this->name) == 0) { … … 99 110 $this->name .= $token; 100 111 } 101 112 102 113 /** 103 114 * check if the name is valid trunk/src/main/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationState.php
r454 r1072 49 49 */ 50 50 const PARAM_VALUE = 7; 51 /** 52 * parser is inside a argument declaration 53 */ 54 const ARGUMENT = 8; 51 55 52 56 /** trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParser.php
r452 r1072 70 70 */ 71 71 public function setAnnotationType($type); 72 73 /** 74 * sets the argument for which the annotation is declared 75 * 76 * @param string $argument name of the argument 77 */ 78 public function setAnnotationForArgument($argument); 72 79 } 73 80 ?> trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationStateParser.php
r896 r1072 9 9 */ 10 10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationParser', 11 'net.stubbles.reflection.annotations.parser.state.stubAnnotationArgumentState', 11 12 'net.stubbles.reflection.annotations.parser.state.stubAnnotationDocblockState', 12 13 'net.stubbles.reflection.annotations.parser.state.stubAnnotationAnnotationState', … … 67 68 $this->states[stubAnnotationState::ANNOTATION_NAME] = new stubAnnotationNameState($this); 68 69 $this->states[stubAnnotationState::ANNOTATION_TYPE] = new stubAnnotationTypeState($this); 70 $this->states[stubAnnotationState::ARGUMENT] = new stubAnnotationArgumentState($this); 69 71 $this->states[stubAnnotationState::PARAMS] = new stubAnnotationParamsState($this); 70 72 $this->states[stubAnnotationState::PARAM_NAME] = new stubAnnotationParamNameState($this); … … 122 124 public function registerAnnotation($name) 123 125 { 124 $this->annotations[$name] = array('type' => $name, 'params' => array()); 126 $this->annotations[$name] = array('type' => $name, 127 'params' => array(), 128 'argument' => null 129 ); 125 130 $this->currentAnnotation = $name; 126 131 } … … 171 176 { 172 177 $this->annotations[$this->currentAnnotation]['type'] = $type; 178 } 179 180 /** 181 * sets the argument for which the annotation is declared 182 * 183 * @param string $argument name of the argument 184 */ 185 public function setAnnotationForArgument($argument) 186 { 187 $this->annotations[$this->currentAnnotation . '#' . $argument] = $this->annotations[$this->currentAnnotation]; 188 unset($this->annotations[$this->currentAnnotation]); 189 $this->currentAnnotation .= '#' . $argument; 190 $this->annotations[$this->currentAnnotation]['argument'] = $argument; 173 191 } 174 192 trunk/src/main/php/net/stubbles/reflection/annotations/stubAnnotation.php
r832 r1072 33 33 const TARGET_FUNCTION = 8; 34 34 /** 35 * annotation is applicable for parameters 36 */ 37 const TARGET_PARAM = 16; 38 /** 35 39 * annotation is applicable for classes, properties, methods and functions 36 40 */ 37 const TARGET_ALL = 15;41 const TARGET_ALL = 31; 38 42 39 43 /** trunk/src/main/php/net/stubbles/reflection/annotations/stubAnnotationFactory.php
r1071 r1072 77 77 } 78 78 79 if (self::$annotations[$hash][$annotationName]['type'] !== $annotationName) { 80 $annotationType = self::findAnnotationClass($annotationName, true); 79 if (strpos($annotationName, '#') !== false) { 80 $realAnnotationName = substr($annotationName, 0, strpos($annotationName, '#')); 81 } else { 82 $realAnnotationName = $annotationName; 83 } 84 85 if (self::$annotations[$hash][$annotationName]['type'] !== $realAnnotationName) { 86 $annotationType = self::findAnnotationClass($realAnnotationName, true); 81 87 if (is_a($annotation, $annotationType) === false) { 82 88 throw new ReflectionException('The annotation: ' . $annotationName . ' is not an instance of ' . $annotationType . '.'); trunk/src/main/php/net/stubbles/reflection/stubReflectionParameter.php
r697 r1072 7 7 * @subpackage reflection 8 8 */ 9 stubClassLoader::load('net.stubbles.reflection.stubReflectionFunction', 9 stubClassLoader::load('net.stubbles.reflection.annotations.stubAnnotatable', 10 'net.stubbles.reflection.annotations.stubAnnotationFactory', 11 'net.stubbles.reflection.stubReflectionFunction', 10 12 'net.stubbles.reflection.stubReflectionClass' 11 13 ); … … 16 18 * @subpackage reflection 17 19 */ 18 class stubReflectionParameter extends ReflectionParameter 20 class stubReflectionParameter extends ReflectionParameter implements stubAnnotatable 19 21 { 20 22 /** … … 30 32 */ 31 33 protected $paramName; 34 /** 35 * doc block of method or function where this param belongs to 36 * 37 * @var string 38 */ 39 protected $docComment; 32 40 33 41 /** … … 42 50 $this->paramName = $paramName; 43 51 parent::__construct($functionName, $paramName); 52 } 53 54 /** 55 * check whether the class has the given annotation or not 56 * 57 * @param string $annotationName 58 * @return bool 59 */ 60 public function hasAnnotation($annotationName) 61 { 62 if (is_array($this->functionName) === true) { 63 $targetName = $this->functionName[0] . '::' . $this->functionName[1] . '()'; 64 $ref = new stubReflectionMethod($this->functionName[0], $this->functionName[1]); 65 } else { 66 $targetName = $this->functionName; 67 $ref = new stubReflectionFunction($this->functionName); 68 } 69 70 return stubAnnotationFactory::has($ref->getDocComment(), $annotationName . '#' . $this->paramName, stubAnnotation::TARGET_PARAM, $targetName, $ref->getFileName()); 71 } 72 73 /** 74 * return the specified annotation 75 * 76 * @param string $annotationName 77 * @return stubAnnotation 78 * @throws ReflectionException 79 */ 80 public function getAnnotation($annotationName) 81 { 82 if (is_array($this->functionName) === true) { 83 $targetName = $this->functionName[0] . '::' . $this->functionName[1] . '()'; 84 $ref = new stubReflectionMethod($this->functionName[0], $this->functionName[1]); 85 } else { 86 $targetName = $this->functionName; 87 $ref = new stubReflectionFunction($this->functionName); 88 } 89 90 return stubAnnotationFactory::create($ref->getDocComment(), $annotationName . '#' . $this->paramName, stubAnnotation::TARGET_PARAM, $targetName, $ref->getFileName()); 44 91 } 45 92 trunk/src/test/php/net/stubbles/reflection/ReflectionTestSuite.php
r940 r1072 29 29 $this->addTestFile(dirname(__FILE__) . '/annotations/parser/stubAnnotationStateParserTestCase.php'); 30 30 $this->addTestFile(dirname(__FILE__) . '/annotations/parser/state/stubAnnotationAnnotationStateTestCase.php'); 31 $this->addTestFile(dirname(__FILE__) . '/annotations/parser/state/stubAnnotationArgumentStateTestCase.php'); 31 32 $this->addTestFile(dirname(__FILE__) . '/annotations/parser/state/stubAnnotationDocblockStateTestCase.php'); 32 33 $this->addTestFile(dirname(__FILE__) . '/annotations/parser/state/stubAnnotationNameStateTestCase.php'); trunk/src/test/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationAnnotationStateTestCase.php
r454 r1072 29 29 */ 30 30 protected $mockAnnotationParser; 31 31 32 32 /** 33 33 * set up test environment … … 38 38 $this->annotationState = new stubAnnotationAnnotationState($this->mockAnnotationParser); 39 39 } 40 40 41 41 /** 42 42 * test processing a line break … … 47 47 $this->annotationState->process("\n"); 48 48 } 49 49 50 /** 51 * test processing an argument parenthesis 52 */ 53 public function testProcessArgumentParenthesis() 54 { 55 $this->mockAnnotationParser->expectOnce('changeState', array(stubAnnotationState::ARGUMENT)); 56 $this->annotationState->process('{'); 57 } 58 50 59 /** 51 60 * test processing a type parenthesis … … 56 65 $this->annotationState->process('['); 57 66 } 58 67 59 68 /** 60 69 * test processing a value parenthesis … … 65 74 $this->annotationState->process('('); 66 75 } 67 76 68 77 /** 69 78 * test processing a value parenthesis trunk/src/test/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationNameStateTestCase.php
r490 r1072 29 29 */ 30 30 protected $mockAnnotationParser; 31 31 32 32 /** 33 33 * set up test environment … … 38 38 $this->annotationNameState = new stubAnnotationNameState($this->mockAnnotationParser); 39 39 } 40 40 41 41 /** 42 42 * test processing a space element … … 52 52 $this->annotationNameState->process(' '); 53 53 } 54 54 55 55 /** 56 56 * test processing a line break … … 65 65 $this->annotationNameState->process("\n"); 66 66 } 67 67 68 /** 69 * test processing an argument parenthesis 70 */ 71 public function testProcessArgumentParenthesis() 72 { 73 $this->mockAnnotationParser->expectOnce('registerAnnotation', array('a')); 74 $this->mockAnnotationParser->expectOnce('changeState', array(stubAnnotationState::ARGUMENT)); 75 76 $this->annotationNameState->process('a'); 77 $this->annotationNameState->process('{'); 78 79 $this->annotationNameState->selected(); 80 $this->expectException('ReflectionException'); 81 $this->annotationNameState->process('{'); 82 } 83 68 84 /** 69 85 * test processing a type parenthesis … … 81 97 $this->annotationNameState->process('['); 82 98 } 83 99 84 100 /** 85 101 * test processing a value parenthesis … … 138 154 * test processing illegal characters 139 155 */ 156 public function testProcessIllegalCharactersFollowedByArgumentParenthesis() 157 { 158 $this->annotationNameState->process('a'); 159 $this->annotationNameState->process('1'); 160 $this->annotationNameState->process('_'); 161 $this->expectException('ReflectionException'); 162 $this->annotationNameState->process(')'); 163 $this->annotationNameState->process('{'); 164 } 165 166 /** 167 * test processing illegal characters 168 */ 140 169 public function testProcessIllegalCharactersFollowedByTypeParenthesis() 141 170 { trunk/src/test/php/net/stubbles/reflection/annotations/parser/stubAnnotationStateParserTestCase.php
r896 r1072 50 50 } 51 51 MyTestClass::__static(); 52 class MyTestClass2 extends stubBaseObject 53 { 54 /** 55 * a method with an annotation for its parameter 56 * 57 * @param string $bar 58 * @ForArgument1{bar} 59 * @ForArgument2{bar}(key='value') 60 * @MoreArgument1{bar}[Casted] 61 * @MoreArgument2{bar}[Casted](key='value') 62 * @MoreArgument3[CastedAround]{bar} 63 * @MoreArgument4[CastedAround]{bar}(key='value') 64 */ 65 public function foo($bar) { } 66 } 52 67 /** 53 68 * Test for net.stubbles.reflection.annotations.parser.stubAnnotationStateParser. … … 126 141 $this->assertEqual($annotations['WithTypes']['params']['class']->getName(), 'MyTestClass'); 127 142 } 128 143 129 144 /** 130 145 * test that tabs are recognized correctly … … 137 152 $this->assertTrue(isset($annotations['Foo'])); 138 153 } 154 155 /** 156 * test that parameter argumentations are recognized correctly 157 */ 158 public function testArgument() 159 { 160 $method = new ReflectionMethod('MyTestClass2', 'foo'); 161 $annotationStateParser = new stubAnnotationStateParser(); 162 $annotations = $annotationStateParser->parse($method->getDocComment()); 163 $this->assertTrue(isset($annotations['ForArgument1#bar'])); 164 $this->assertEqual($annotations['ForArgument1#bar']['argument'], 'bar'); 165 $this->assertEqual($annotations['ForArgument1#bar']['type'], 'ForArgument1'); 166 $this->assertEqual($annotations['ForArgument1#bar']['params'], array()); 167 $this->assertTrue(isset($annotations['ForArgument2#bar'])); 168 $this->assertEqual($annotations['ForArgument2#bar']['argument'], 'bar'); 169 $this->assertEqual($annotations['ForArgument2#bar']['type'], 'ForArgument2'); 170 $this->assertEqual($annotations['ForArgument2#bar']['params'], array('key' => 'value')); 171 $this->assertTrue(isset($annotations['MoreArgument1#bar'])); 172 $this->assertEqual($annotations['MoreArgument1#bar']['argument'], 'bar'); 173 $this->assertEqual($annotations['MoreArgument1#bar']['type'], 'Casted'); 174 $this->assertEqual($annotations['MoreArgument1#bar']['params'], array()); 175 $this->assertTrue(isset($annotations['MoreArgument2#bar'])); 176 $this->assertEqual($annotations['MoreArgument2#bar']['argument'], 'bar'); 177 $this->assertEqual($annotations['MoreArgument2#bar']['type'], 'Casted'); 178 $this->assertEqual($annotations['MoreArgument2#bar']['params'], array('key' => 'value')); 179 $this->assertTrue(isset($annotations['MoreArgument3#bar'])); 180 $this->assertEqual($annotations['MoreArgument3#bar']['argument'], 'bar'); 181 $this->assertEqual($annotations['MoreArgument3#bar']['type'], 'CastedAround'); 182 $this->assertEqual($annotations['MoreArgument3#bar']['params'], array()); 183 $this->assertTrue(isset($annotations['MoreArgument4#bar'])); 184 $this->assertEqual($annotations['MoreArgument4#bar']['argument'], 'bar'); 185 $this->assertEqual($annotations['MoreArgument4#bar']['type'], 'CastedAround'); 186 $this->assertEqual($annotations['MoreArgument4#bar']['params'], array('key' => 'value')); 187 } 139 188 } 140 189 ?> trunk/src/test/php/net/stubbles/reflection/annotations/stubAnnotationFactoryApplicableTestCase.php
r432 r1072 23 23 */ 24 24 protected $mockStubAnnotation; 25 25 26 26 /** 27 27 * create test environment … … 31 31 $this->mockStubAnnotation = new MockStubAnnotation(); 32 32 } 33 33 34 34 /** 35 35 * check that the applicable check works correct … … 42 42 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 43 43 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 44 } 45 44 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 45 } 46 46 47 /** 47 48 * check that the applicable check works correct … … 54 55 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 55 56 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 56 } 57 57 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 58 } 59 58 60 /** 59 61 * check that the applicable check works correct … … 66 68 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 67 69 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 68 } 69 70 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 71 } 72 70 73 /** 71 74 * check that the applicable check works correct … … 78 81 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 79 82 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 80 } 81 83 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 84 } 85 82 86 /** 83 87 * check that the applicable check works correct … … 90 94 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 91 95 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 92 } 93 96 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 97 } 98 99 /** 100 * check that the applicable check works correct 101 */ 102 public function testIsApplicableForParam() 103 { 104 $this->mockStubAnnotation->setReturnValue('getAnnotationTarget', stubAnnotation::TARGET_PARAM); 105 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_CLASS)); 106 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PROPERTY)); 107 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 108 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 109 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 110 } 111 94 112 /** 95 113 * check that the applicable check works correct … … 102 120 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 103 121 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 104 } 105 122 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 123 } 124 106 125 /** 107 126 * check that the applicable check works correct … … 114 133 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 115 134 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 116 } 117 135 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 136 } 137 118 138 /** 119 139 * check that the applicable check works correct … … 126 146 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 127 147 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 128 } 129 148 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 149 } 150 151 /** 152 * check that the applicable check works correct 153 */ 154 public function testIsApplicableForClassAndParam() 155 { 156 $this->mockStubAnnotation->setReturnValue('getAnnotationTarget', stubAnnotation::TARGET_CLASS + stubAnnotation::TARGET_PARAM); 157 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_CLASS)); 158 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PROPERTY)); 159 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 160 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 161 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 162 } 163 130 164 /** 131 165 * check that the applicable check works correct … … 138 172 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 139 173 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 140 } 141 174 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 175 } 176 142 177 /** 143 178 * check that the applicable check works correct … … 150 185 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 151 186 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 152 } 153 187 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 188 } 189 190 /** 191 * check that the applicable check works correct 192 */ 193 public function testIsApplicableForPropertyAndParam() 194 { 195 $this->mockStubAnnotation->setReturnValue('getAnnotationTarget', stubAnnotation::TARGET_PROPERTY + stubAnnotation::TARGET_PARAM); 196 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_CLASS)); 197 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PROPERTY)); 198 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 199 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 200 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 201 } 202 154 203 /** 155 204 * check that the applicable check works correct … … 162 211 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 163 212 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 164 } 165 213 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 214 } 215 216 /** 217 * check that the applicable check works correct 218 */ 219 public function testIsApplicableForMethodAndParam() 220 { 221 $this->mockStubAnnotation->setReturnValue('getAnnotationTarget', stubAnnotation::TARGET_METHOD + stubAnnotation::TARGET_PARAM); 222 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_CLASS)); 223 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PROPERTY)); 224 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 225 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 226 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 227 } 228 229 /** 230 * check that the applicable check works correct 231 */ 232 public function testIsApplicableForFunctionAndParam() 233 { 234 $this->mockStubAnnotation->setReturnValue('getAnnotationTarget', stubAnnotation::TARGET_FUNCTION + stubAnnotation::TARGET_PARAM); 235 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_CLASS)); 236 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PROPERTY)); 237 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 238 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 239 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 240 } 241 166 242 /** 167 243 * check that the applicable check works correct … … 175 251 $this->assertFalse(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 176 252 } 177 253 178 254 /** 179 255 * check that the applicable check works correct … … 187 263 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 188 264 } 189 265 190 266 /** 191 267 * check that the applicable check works correct … … 199 275 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 200 276 } 201 277 202 278 /** 203 279 * check that the applicable check works correct … … 211 287 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 212 288 } 213 289 290 /** 291 * check that the applicable check works correct 292 */ 293 public function testIsApplicableForAllByAddition() 294 { 295 $this->mockStubAnnotation->setReturnValue('getAnnotationTarget', stubAnnotation::TARGET_CLASS + stubAnnotation::TARGET_PROPERTY + stubAnnotation::TARGET_METHOD + stubAnnotation::TARGET_FUNCTION + stubAnnotation::TARGET_PARAM); 296 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_CLASS)); 297 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PROPERTY)); 298 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 299 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 300 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 301 } 302 214 303 /** 215 304 * check that the applicable check works correct … … 217 306 public function testIsApplicableForAll() 218 307 { 219 $this->mockStubAnnotation->setReturnValue('getAnnotationTarget', stubAnnotation::TARGET_CLASS + stubAnnotation::TARGET_PROPERTY + stubAnnotation::TARGET_METHOD + stubAnnotation::TARGET_FUNCTION); 220 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_CLASS)); 221 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PROPERTY)); 222 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 223 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 308 $this->mockStubAnnotation->setReturnValue('getAnnotationTarget', stubAnnotation::TARGET_ALL); 309 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_CLASS)); 310 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PROPERTY)); 311 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_METHOD)); 312 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_FUNCTION)); 313 $this->assertTrue(stubAnnotationFactory::isApplicable($this->mockStubAnnotation, stubAnnotation::TARGET_PARAM)); 224 314 } 225 315 } trunk/src/test/php/net/stubbles/reflection/annotations/stubAnnotationFactoryTestCase.php
r1069 r1072 121 121 * @access public 122 122 * @MyAnnotation( 123 * foo=AnyTestClass.class 124 * ) 125 */'; 126 protected $commentComplexForArgument = '/** 127 * Foobar bla 128 * 129 * @access public 130 * @MyAnnotation{foo}( 131 * foo="bar", 132 * argh=45, veggie="tomato" 133 * ) 134 * @AnotherAnnotation{foo}(true) 135 * @CastedAnnotation{foo}[AnotherAnnotation](false) 136 * @AnotherAnnotation{bar} 137 * @MyAnnotation{bar}( 123 138 * foo=AnyTestClass.class 124 139 * ) … … 190 205 191 206 /** 207 * test that creating an annotation works as expected 208 */ 209 public function testCreateForArgument() 210 { 211 $myAnnotation = stubAnnotationFactory::create($this->commentComplexForArgument, 'MyAnnotation#foo', stubAnnotation::TARGET_PARAM, 'MyClass::baz()', __FILE__); 212 $this->assertIsA($myAnnotation, 'MyAnnotation'); 213 $this->assertEqual('bar', $myAnnotation->foo); 214 $this->assertEqual('45', $myAnnotation->argh); 215 $this->assertEqual('tomato', $myAnnotation->veggie); 216 217 $anotherAnnotation = stubAnnotationFactory::create($this->commentComplexForArgument, 'AnotherAnnotation#foo', stubAnnotation::TARGET_PARAM, 'MyClass::baz()', __FILE__); 218 $this->assertIsA($anotherAnnotation, 'AnotherAnnotation'); 219 $this->assertEqual('true', $anotherAnnotation->value); 220 221 $castedAnnotation = stubAnnotationFactory::create($this->commentComplexForArgument, 'CastedAnnotation#foo', stubAnnotation::TARGET_PARAM, 'MyClass::baz()', __FILE__); 222 $this->assertIsA($castedAnnotation, 'AnotherAnnotation'); 223 $this->assertFalse($castedAnnotation->value); 224 225 $emptyAnnotation = stubAnnotationFactory::create($this->commentComplexForArgument, 'AnotherAnnotation#bar', stubAnnotation::TARGET_PARAM, 'MyClass::baz()', __FILE__); 226 $this->assertIsA($emptyAnnotation, 'AnotherAnnotation'); 227 228 $myAnnotation = stubAnnotationFactory::create($this->commentComplexForArgument, 'MyAnnotation#bar', stubAnnotation::TARGET_PARAM, 'MyClass::baz()', __FILE__); 229 $this->assertIsA($myAnnotation, 'MyAnnotation'); 230 $this->assertIsA($myAnnotation->foo, 'stubReflectionClass'); 231 232 $this->expectException('ReflectionException'); 233 stubAnnotationFactory::create($this->commentComplexForArgument, 'MyAnnotation#baz', stubAnnotation::TARGET_PARAM, 'MyClass::baz()', __FILE__); 234 } 235 236 /** 192 237 * test that the cache works as expected 193 238 */ trunk/src/test/php/net/stubbles/reflection/stubReflectionParameterTestCase.php
r697 r1072 8 8 */ 9 9 stubClassLoader::load('net.stubbles.reflection.stubReflectionParameter'); 10 /** 11 * annotation for parameters 12 * 13 * @package stubbles 14 * @subpackage reflection_test 15 */ 16 class stubParamAnnoAnnotation extends stubAbstractAnnotation implements stubAnnotation 17 { 18 /** 19 * Returns the target of the annotation as bitmap. 20 * 21 * @return int 22 */ 23 public function getAnnotationTarget() 24 { 25 return stubAnnotation::TARGET_PARAM; 26 } 27 } 28 /** 29 * a function 30 * 31 * @package stubbles 32 * @subpackage reflection_test 33 * @param mixed $param 34 * @ParamAnno{param} 35 */ 10 36 function stubtest_function($param) 11 37 { 12 38 // nothing to do 13 39 } 40 /** 41 * a class for tests 42 * 43 * @package stubbles 44 * @subpackage reflection_test 45 */ 14 46 class stubParamTest 15 47 { 48 /** 49 * a method 50 * 51 * @param mixed $param 52 * @ParamAnno{param} 53 */ 16 54 function paramTest($param) 17 55 { … … 19 57 } 20 58 } 59 /** 60 * another class for tests 61 * 62 * @package stubbles 63 * @subpackage reflection_test 64 */ 21 65 class stubParamTest2 extends stubParamTest 22 66 { 67 /** 68 * another method 69 * 70 * @param stubParamTest $param2 71 * @ParamAnno{param2} 72 */ 23 73 function paramTest2(stubParamTest $param2) 24 74 { 25 75 // nothing to do 26 76 } 27 77 78 /** 79 * one more method 80 * 81 * @param stubParamTest2 $param2 82 * @ParamAnno{param} 83 */ 28 84 function paramTest3(self $param2) 29 85 { … … 80 136 $this->stubRefParamMethod3 = new stubReflectionParameter(array('stubParamTest2', 'paramTest2'), 'param2'); 81 137 $this->stubRefParamMethod4 = new stubReflectionParameter(array('stubParamTest2', 'paramTest3'), 'param2'); 138 } 139 140 /** 141 * assure that annotations are handled correctly 142 */ 143 public function testAnnotations() 144 { 145 $this->assertTrue($this->stubRefParamFunction->hasAnnotation('ParamAnno')); 146 $this->assertIsA($this->stubRefParamFunction->getAnnotation('ParamAnno'), 'stubParamAnnoAnnotation'); 147 $this->assertTrue($this->stubRefParamMethod1->hasAnnotation('ParamAnno')); 148 $this->assertIsA($this->stubRefParamMethod1->getAnnotation('ParamAnno'), 'stubParamAnnoAnnotation'); 149 $this->assertTrue($this->stubRefParamMethod2->hasAnnotation('ParamAnno')); 150 $this->assertIsA($this->stubRefParamMethod2->getAnnotation('ParamAnno'), 'stubParamAnnoAnnotation'); 151 $this->assertTrue($this->stubRefParamMethod3->hasAnnotation('ParamAnno')); 152 $this->assertIsA($this->stubRefParamMethod3->getAnnotation('ParamAnno'), 'stubParamAnnoAnnotation'); 153 $this->assertFalse($this->stubRefParamMethod4->hasAnnotation('ParamAnno')); 154 $this->expectException('ReflectionException'); 155 $this->stubRefParamMethod4->getAnnotation('ParamAnno'); 82 156 } 83 157
