コード例 #1
0
ファイル: ResourceMappingTest.php プロジェクト: umber-io/rei
 /**
  * Validate the getters and setters work as expected.
  *
  * @test
  */
 public function validateMappingGettersAndSetters()
 {
     $mapping = new ResourceMapping();
     $this->assertNull($mapping->getPrimary());
     $this->assertInstanceOf(ArrayCollection::class, $mapping->getFields());
     $this->assertCount(0, $mapping->getFields());
     $this->assertInstanceOf(ArrayCollection::class, $mapping->getAssociations());
     $this->assertCount(0, $mapping->getAssociations());
     $primary = new FieldMapping();
     $this->assertEquals($mapping, $mapping->setPrimary($primary));
     $this->assertEquals($primary, $mapping->getPrimary());
 }
コード例 #2
0
ファイル: AnnotationParser.php プロジェクト: umber-io/rei
 /**
  * @param ResourceMapping $resource
  *
  * @throws InvalidMappingException when a resource has no field mappings.
  */
 public function validateResourceMapping(ResourceMapping $resource)
 {
     if ($resource->getFields()->count() === 0) {
         throw new InvalidMappingException('resource-fields-missing');
     }
     $primary = false;
     foreach ($resource->getFields() as $field) {
         if ($field->getField()->primary) {
             if (!$primary) {
                 $primary = true;
             } else {
                 throw new InvalidMappingException('resource-field-primary-many');
             }
         }
     }
     if (!$primary) {
         throw new InvalidMappingException('resource-field-primary-missing');
     }
 }
コード例 #3
0
ファイル: AnnotationParserTest.php プロジェクト: umber-io/rei
 /**
  * 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);
 }