public function testIfWillRecognizeAnnotationAfterDynamicallyAddingNamespace()
 {
     $model = new ModelWithTwoNsAnnotations();
     $options = new MetaOptions();
     $options->namespaces[] = NamespacedAnnotation::Ns;
     $meta = Meta::create($model, $options)->title;
     $this->assertTrue($meta->namespaced);
     // Not added second namespace
     $this->assertNull($meta->second);
     $this->assertNull($meta->third);
     // Second ns
     $options->namespaces[] = SecondNsAnnotation::Ns;
     $metaContainer2 = Meta::create($model, $options);
     $this->assertNotNull($metaContainer2);
     $meta2 = $metaContainer2->title;
     $this->assertTrue($meta2->namespaced);
     // Added second namespace
     $this->assertTrue($meta2->second, 'That namespace added via options id detected');
     // Third ns
     Addendum::fly()->addNamespace(ThirdNsAnnotation::Ns);
     $meta3 = Meta::create($model, $options)->title;
     $this->assertTrue($meta3->namespaced);
     $this->assertTrue($meta3->second);
     // Added second namespace
     $this->assertTrue($meta3->third, 'That namespace added via Addendum::addNamespace is detected');
 }
Esempio n. 2
0
 public function testIfWillAnnotatateSameAnnotationOnMultipleFields()
 {
     $model = new ModelWithLabels();
     $meta = Meta::create($model);
     $this->assertSame(ModelWithLabels::TitleLabel, $meta->title->label);
     $this->assertSame(ModelWithLabels::StateLabel, $meta->state->label);
 }
Esempio n. 3
0
 public function testIgnoreAnnotationsSurroundedByFence()
 {
     $model = new ModelWithFences();
     $meta = Meta::create($model)->type();
     codecept_debug($meta);
     $this->assertSame('LABEL', $meta->label, 'That @Label was evaluated');
     $this->assertTrue(empty($meta->description), 'That @Description was ignoded');
 }
 private function check($model)
 {
     $meta = Meta::create($model)->published;
     $this->assertNotFalse($meta);
     $this->assertNotNull($meta->decorators);
     $this->assertCount(2, $meta->decorators);
     $this->assertContains(Published::class, $meta->decorators);
     $this->assertContains(CellEnumCss::class, $meta->decorators);
     return $meta;
 }
Esempio n. 5
0
 public function testIfWillConflict()
 {
     $model = new ModelWithConflictedAnnotation();
     try {
         Meta::create($model);
         $this->assertTrue(false);
     } catch (ConflictException $ex) {
         $this->assertTrue(true);
     }
 }
 public function testIfWillReadBasicMethodMetaInformation()
 {
     $meta = Meta::create(ModelWithoutAnnotations::class);
     $this->assertNotNull($meta);
     $method = $meta->method('show');
     $this->assertTrue($method instanceof MetaMethod);
     $this->assertFalse($method->isAbstract);
     $this->assertFalse($method->isStatic);
     $this->assertSame($method->name, 'show');
 }
 /**
  * TODO Does not pass
  */
 public function testIfWillMatchConstant()
 {
     $model = new ModelWithConstantValue();
     $options = new MetaOptions();
     $options->namespaces[] = NamespacedAnnotation::Ns;
     $meta = Meta::create($model, $options);
     // ModelWithConstantLabel defined in ModelWithConstantValue.php
     $this->assertTrue(defined('ModelWithConstantLabel'));
     $this->assertSame(ModelWithConstantLabel, $meta->title->label);
     $this->assertSame(ModelWithConstantValue::NameLabel, $meta->name->label);
 }
 public function testIfWillProperlyGetMetaFromNestedTrait()
 {
     $model = new ModelWithNestedTraits();
     $meta = Meta::create($model);
     $hasLabelMeta = $meta->hasLabel;
     $parentMeta = $meta->parentId;
     codecept_debug($hasLabelMeta);
     codecept_debug($parentMeta);
     $this->assertTrue(!empty($hasLabelMeta->label), 'That @Label is properly configured');
     $this->assertTrue(!empty($parentMeta->label), 'That @Label is detected on nested trait');
 }
Esempio n. 9
0
 public function testIfPropertyAndMethodAreIgnored()
 {
     $model = new ModelWithIgnoredEntities();
     $meta = Meta::create($model);
     // Default behavior
     $this->assertInstanceOf(MetaProperty::class, $meta->title);
     $this->assertInstanceOf(MetaMethod::class, $meta->method('getTitle'));
     // Must not have metadata
     $this->assertFalse($meta->meta);
     $this->assertFalse($meta->method('getMeta'));
     // Must have metadata
     $this->assertInstanceOf(MetaProperty::class, $meta->must);
     $this->assertInstanceOf(MetaMethod::class, $meta->method('getMust'));
 }
Esempio n. 10
0
 public function testIfWillExtractTopValues()
 {
     $model = new ModelWithTopValues();
     // Raw matcher for debug
     $reflection = new ReflectionAnnotatedProperty($model, 'straight');
     $matcher = new AnnotationsMatcher();
     $matcher->setPlugins(new MatcherConfig(['addendum' => new Addendum(), 'reflection' => $reflection]));
     $data = [];
     $comment = Addendum::getDocComment($reflection);
     $matcher->matches($comment, $data);
     $meta = Meta::create($model);
     // All fields have same annotation
     foreach ($meta->fields() as $fieldMeta) {
         $title = sprintf('Annotation is defined on %s', $fieldMeta->name);
         $this->assertSame(ModelWithTopValues::ClassValue, $fieldMeta->class);
         $this->assertSame(ModelWithTopValues::UpdatableValue, $fieldMeta->updatable);
     }
 }
 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');
     }
 }
Esempio n. 12
0
 public function testIfWillResolveSelfConstantValueUsingStaticKeyword()
 {
     $model = new ModelWithRequiredValueValidator();
     $meta = Meta::create($model);
     $this->assertSame(ModelWithRequiredValueValidator::RequiredValue, $meta->loginStatic->requiredValue);
 }
Esempio n. 13
0
 public function testIfSignaledAnnotationIsIncluded()
 {
     $model = new ModelWithSignaledAnnotation();
     $meta = Meta::create($model);
     $this->assertTrue($meta->type()->signaled);
 }
Esempio n. 14
0
 public function testIfWillResolveNonNamespacedAnnotation()
 {
     $model = new ModelWithNonNsAnnotation();
     $meta = Meta::create($model);
     $this->assertTrue($meta->type()->nonNamespaced);
 }
Esempio n. 15
0
 public function testIfHasWrongTargetMethod()
 {
     $model = new ModelWithBadTargetMethod();
     try {
         Meta::create($model);
         $this->assertTrue(false);
     } catch (TargetException $ex) {
         $this->assertTrue(true);
     }
 }
Esempio n. 16
0
 /**
  * Get method meta data
  * @param type $name
  * @return DocumentMethodMeta
  */
 public function method($name)
 {
     return parent::method($name);
 }
Esempio n. 17
0
 /**
  * Get document type meta
  * @return DocumentTypeMeta
  */
 public function type()
 {
     return parent::type();
 }