public function testReflectionAnnotatedClass() { $reflection = new ReflectionAnnotatedClass('Example'); $this->assertTrue($reflection->hasAnnotation('FirstAnnotation')); $this->assertTrue($reflection->hasAnnotation('SecondAnnotation')); $this->assertFalse($reflection->hasAnnotation('NonExistentAnnotation')); $this->assertIsA($reflection->getAnnotation('FirstAnnotation'), 'FirstAnnotation'); $this->assertIsA($reflection->getAnnotation('SecondAnnotation'), 'SecondAnnotation'); $annotations = $reflection->getAnnotations(); $this->assertEqual(count($annotations), 2); $this->assertIsA($annotations[0], 'FirstAnnotation'); $this->assertIsA($annotations[1], 'SecondAnnotation'); $this->assertFalse($reflection->getAnnotation('NonExistentAnnotation')); $this->assertIsA($reflection->getConstructor(), 'ReflectionAnnotatedMethod'); $this->assertIsA($reflection->getMethod('exampleMethod'), 'ReflectionAnnotatedMethod'); foreach ($reflection->getMethods() as $method) { $this->assertIsA($method, 'ReflectionAnnotatedMethod'); } $this->assertIsA($reflection->getProperty('exampleProperty'), 'ReflectionAnnotatedProperty'); foreach ($reflection->getProperties() as $property) { $this->assertIsA($property, 'ReflectionAnnotatedProperty'); } foreach ($reflection->getInterfaces() as $interface) { $this->assertIsA($interface, 'ReflectionAnnotatedClass'); } $this->assertIsA($reflection->getParentClass(), 'ReflectionAnnotatedClass'); }
public function testMultiTargetAnnotationThrowsNoErrorWhenOnRightPlace() { $reflection = new ReflectionAnnotatedClass('SuccesfullyAnnotatedClass'); $method = $reflection->getProperty('property2'); $this->assertNoErrors(); }
/** * Define the template according to the class */ public function defineTemplate($class) { if (is_string($class) && class_exists($class)) { $reflection = new ReflectionAnnotatedClass($class); $ret = array(); $ret[] = '(deftemplate ' . $class; foreach (get_class_vars($class) as $slot => $v) { if ($reflection->getProperty($slot)->hasAnnotation('ClipsMulti')) { $ret[] = '(multislot ' . $slot . ')'; } else { $ret[] = '(slot ' . $slot . ')'; } } return implode(' ', $ret) . ')'; } return false; }