Example #1
0
 public function testIfHasPropertyAnnotationFromUsedTrait()
 {
     // Check trait first
     $info = new ReflectionAnnotatedProperty(BaseTraitWithLabel::class, 'title');
     $has = $info->hasAnnotation('Label');
     $this->assertTrue($has);
     // Check inherited model model
     $model = new ModelWithInheritedLabelFromTrait();
     $info = new ReflectionAnnotatedProperty($model, 'title');
     $has = $info->hasAnnotation('Label');
     $this->assertTrue($has);
 }
Example #2
0
 /**
  * Get reflection class.
  * @param ReflectionAnnotatedClass|ReflectionAnnotatedProperty|ReflectionAnnotatedMethod $reflection Reflection
  * @return ReflectionAnnotatedClass
  * @throws Exception
  */
 public static function getReflectionClass($reflection)
 {
     if (null === $reflection) {
         throw new Exception(sprintf('No reflection class for matcher `%s`', get_class($this)));
     }
     if ($reflection instanceof ReflectionAnnotatedMethod) {
         return $reflection->getDeclaringClass();
     }
     if ($reflection instanceof ReflectionAnnotatedProperty) {
         return $reflection->getDeclaringClass();
     }
     return $reflection;
 }
Example #3
0
 public function testIfHasPropertyAnnotationFromParentClassParent()
 {
     // Check base model first
     $model = new BaseModelWithLabel();
     $info = new ReflectionAnnotatedProperty($model, 'title');
     $has = $info->hasAnnotation('Label');
     $this->assertTrue($has);
     // Check inherited model model
     $model = new ModelWithInheritedLabelDeep();
     $info = new ReflectionAnnotatedProperty($model, 'title');
     $has = $info->hasAnnotation('Label');
     $this->assertTrue($has);
 }
 public function testIfWillProperlyGetMetaFromTrait()
 {
     $model = new ModelWithSimpleTree();
     // Parse error in annotation
     try {
         $infoBad = new ReflectionAnnotatedProperty(SimpleTreeTrait::class, 'children');
         $relatedBad = $infoBad->getAnnotation('RelatedArray');
         $this->fail('Should throw exception');
     } catch (ParseException $e) {
         $this->assertTrue(true);
         codecept_debug('Exception was thrown properly');
     }
     $info = new ReflectionAnnotatedProperty(SimpleTreeTraitProper::class, 'children');
     $related = $info->getAnnotation('RelatedArray');
     $this->assertInstanceOf(RelatedArrayAnnotation::class, $related);
     $this->assertNotNull($related->value);
     try {
         $meta = Meta::create($model);
         $this->fail('Should throw exception');
     } catch (ParseException $e) {
         $this->assertTrue(true);
         codecept_debug('Exception was thrown properly');
     }
 }