Example #1
0
 public function testAddSchema()
 {
     $schema100 = new SchemaDescriptor('pbj:vendor:package:category:message:1-0-0');
     $schema101 = new SchemaDescriptor('pbj:vendor:package:category:message:1-0-1');
     $schema200 = new SchemaDescriptor('pbj:vendor:package:category:message:2-0-0');
     SchemaStore::addSchema($schema100->getId(), $schema100);
     SchemaStore::addSchema($schema101->getId(), $schema101);
     SchemaStore::addSchema($schema200->getId(), $schema200);
     $this->assertEquals(SchemaStore::getSchemaById('pbj:vendor:package:category:message:1-0-0'), $schema100);
     $this->assertEquals(SchemaStore::getPreviousSchema($schema101->getId()), $schema100);
     $this->assertTrue(SchemaStore::hasOtherSchemaMajorRev($schema100->getId()));
     $this->assertEquals(SchemaStore::getOtherSchemaMajorRev($schema101->getId()), [$schema101, $schema200]);
 }
Example #2
0
 /**
  * Validates a single schema against previous version.
  *
  * @param SchemaDescriptor $schema
  *
  * @throws \RuntimeException
  */
 public function validate(SchemaDescriptor $schema)
 {
     if ($prevSchema = SchemaStore::getPreviousSchema($schema->getId())) {
         if (!$prevSchema instanceof SchemaDescriptor) {
             throw new \RuntimeException(sprintf('Un-parsed schema "%s".', $prevSchema['id']));
         }
         /** @var \Gdbots\Pbjc\Validator\Constraint $constraint */
         foreach ($this->constraints as $constraint) {
             $constraint->validate($prevSchema, $schema);
         }
     }
     $constraint = new Constraint\SchemaDependencyVersion();
     $constraint->validate($schema, $schema);
     $constraint = new Constraint\SchemaInheritanceFields();
     $constraint->validate($schema, $schema);
     $constraint = new Constraint\FieldValidEnumValue();
     $constraint->validate($schema, $schema);
 }