Exemplo n.º 1
0
 public function testReflection()
 {
     //Empty reflection
     $reflection = new Phalcon\Annotations\Reflection();
     $classAnnotations = $reflection->getClassAnnotations();
     $this->assertEquals($classAnnotations, null);
     $methodsAnnotations = $reflection->getMethodsAnnotations();
     $this->assertEquals($methodsAnnotations, null);
     $propertiesAnnotations = $reflection->getPropertiesAnnotations();
     $this->assertEquals($propertiesAnnotations, null);
     //Parsing a real class
     $reader = new Phalcon\Annotations\Reader();
     $parsing = $reader->parse('TestClass');
     $reflection = new Phalcon\Annotations\Reflection($parsing);
     //Annotations in the class' dockblock
     $classAnnotations = $reflection->getClassAnnotations();
     $this->assertEquals(get_class($classAnnotations), 'Phalcon\\Annotations\\Collection');
     $number = 0;
     foreach ($classAnnotations as $annotation) {
         $this->assertEquals(get_class($annotation), 'Phalcon\\Annotations\\Annotation');
         $number++;
     }
     $this->assertEquals($number, 9);
     $this->assertEquals(count($classAnnotations), 9);
     //Annotations in Methods
     $methodsAnnotations = $reflection->getMethodsAnnotations();
     $this->assertEquals(gettype($methodsAnnotations), 'array');
     $this->assertEquals(get_class($methodsAnnotations['testMethod1']), 'Phalcon\\Annotations\\Collection');
     $total = 0;
     foreach ($methodsAnnotations as $method => $annotations) {
         $this->assertEquals(gettype($method), 'string');
         $number = 0;
         foreach ($annotations as $annotation) {
             $this->assertEquals(get_class($annotation), 'Phalcon\\Annotations\\Annotation');
             $number++;
             $total++;
         }
         $this->assertTrue($number > 0);
     }
     $this->assertEquals($total, 14);
     $annotations = $methodsAnnotations['testMethod1'];
     $this->assertTrue($annotations->has('Simple'));
     $this->assertFalse($annotations->has('NoSimple'));
     $annotation = $annotations->get('Simple');
     $this->assertEquals($annotation->getName(), 'Simple');
     $this->assertEquals($annotation->numberArguments(), 0);
     $this->assertEquals($annotation->getArguments(), null);
     $this->assertFalse($annotation->hasArgument('none'));
     $annotation = $annotations->get('NamedMultipleParams');
     $this->assertEquals($annotation->getName(), 'NamedMultipleParams');
     $this->assertEquals($annotation->numberArguments(), 2);
     $this->assertEquals($annotation->getArguments(), array('first' => 'First', 'second' => 'Second'));
     $this->assertTrue($annotation->hasArgument('first'));
     $this->assertEquals($annotation->getArgument('first'), 'First');
     $this->assertFalse($annotation->hasArgument('none'));
     //Annotations in properties
     $propertiesAnnotations = $reflection->getPropertiesAnnotations();
     $this->assertEquals(gettype($propertiesAnnotations), 'array');
     $this->assertEquals(get_class($propertiesAnnotations['testProp1']), 'Phalcon\\Annotations\\Collection');
     $total = 0;
     foreach ($propertiesAnnotations as $property => $annotations) {
         $this->assertEquals(gettype($method), 'string');
         $number = 0;
         foreach ($annotations as $annotation) {
             $this->assertEquals(get_class($annotation), 'Phalcon\\Annotations\\Annotation');
             $number++;
             $total++;
         }
         $this->assertTrue($number > 0);
     }
     $this->assertEquals($total, 10);
 }