/** * Validate the getters and setters work as expected. * * @test */ public function validateMappingGettersAndSetters() { $mapping = new FieldMapping(); $this->assertNull($mapping->getAssociation()); $this->assertNull($mapping->getField()); $association = new Association(); $this->assertEquals($mapping, $mapping->setAssociation($association)); $this->assertEquals($association, $mapping->getAssociation()); $field = new Field(); $this->assertEquals($mapping, $mapping->setField($field)); $this->assertEquals($field, $mapping->getField()); }
/** * @param ReflectionProperty $property * @param ArrayCollection $annotations * @return FieldMapping */ public function processFieldAnnotations(ReflectionProperty $property, ArrayCollection $annotations) { $field = new FieldMapping(); foreach ($annotations as $annotation) { if ($annotation instanceof AbstractAnnotation) { $annotation->setReflector($property); if ($annotation instanceof Field) { $field->setField($annotation); continue; } if ($annotation instanceof Association) { $annotation->target = $this->processor->resolveClassMapping($annotation->target, $property->getDeclaringClass()); $field->setAssociation($annotation); continue; } if ($annotation instanceof Pagination) { continue; } throw new \RuntimeException(sprintf('unexpected %s', get_class($annotation))); } } return $field; }
/** * Expect that the given {@link ResourceMapping} should have at most one {@link Field} marked with primary. * * @test */ public function validateResourceHasAtMostOneMappedFieldFlaggedPrimary() { $resource = new ResourceMapping(); $field = new Field(); $field->primary = true; $mapping = new FieldMapping(); $mapping->setField($field); $resource->getFields()->add($mapping); $resource->getFields()->add($mapping); $this->setExpectedException(InvalidMappingException::class, 'resource-field-primary-many'); $this->parser->validateResourceMapping($resource); }