Example #1
0
 /**
  * Tests parsing class annotations
  *
  * @author Serghei Iakovlev <*****@*****.**>
  * @since  2016-01-26
  */
 public function testClassAnnotations()
 {
     $this->specify('Reflection does not parse annotations correctly', function () {
         $reader = new Reader();
         $reflection = new Reflection($reader->parse('TestClass'));
         $methodsAnnotations = $reflection->getMethodsAnnotations();
         expect(gettype($methodsAnnotations))->equals('array');
         expect(get_class($methodsAnnotations['testMethod1']))->equals('Phalcon\\Annotations\\Collection');
         $total = 0;
         foreach ($methodsAnnotations as $method => $annotations) {
             expect(gettype($method))->equals('string');
             $number = 0;
             foreach ($annotations as $annotation) {
                 expect(get_class($annotation))->equals('Phalcon\\Annotations\\Annotation');
                 $number++;
                 $total++;
             }
             expect($number > 0)->true();
         }
         expect($total)->equals(14);
         /** @var \Phalcon\Annotations\Collection $annotations */
         $annotations = $methodsAnnotations['testMethod1'];
         expect($annotations->has('Simple'))->true();
         expect($annotations->has('NoSimple'))->false();
         $annotation = $annotations->get('Simple');
         expect($annotation->getName())->equals('Simple');
         expect($annotation->getArguments())->equals(null);
         expect($annotation->numberArguments())->equals(0);
         expect($annotation->hasArgument('none'))->false();
         $annotation = $annotations->get('NamedMultipleParams');
         expect($annotation->getName())->equals('NamedMultipleParams');
         expect($annotation->numberArguments())->equals(2);
         expect($annotation->getArguments())->equals(['first' => 'First', 'second' => 'Second']);
         expect($annotation->hasArgument('first'))->true();
         expect($annotation->getArgument('first'))->equals('First');
         expect($annotation->hasArgument('none'))->false();
         $propertiesAnnotations = $reflection->getPropertiesAnnotations();
         expect(is_array($propertiesAnnotations))->true();
         expect(get_class($propertiesAnnotations['testProp1']))->equals('Phalcon\\Annotations\\Collection');
         $total = 0;
         foreach ($propertiesAnnotations as $property => $annotations) {
             expect(get_class($propertiesAnnotations['testProp1']))->equals('Phalcon\\Annotations\\Collection');
             $number = 0;
             foreach ($annotations as $annotation) {
                 expect(get_class($annotation))->equals('Phalcon\\Annotations\\Annotation');
                 $number++;
                 $total++;
             }
             expect($number > 0)->true();
         }
         expect($total)->equals(10);
     });
 }
Example #2
0
 public static function parseDocBlock($docBlock, $file = null, $line = null)
 {
     return parent::parseDocBlock($docBlock, $file, $line);
 }