Example #1
0
 /**
  * @param string $name The name of the schema.
  * @param mixed[] $schema Must contain keys for 'type', 'properties' and 'customTypes'.
  * @param FactoryInterface $factory Will be used to create objects while processing the given schema.
  * @param PropertyInterface $parent If created below a prop (assoc, etc.) this will hold that property.
  */
 public function __construct($name, array $schema, FactoryInterface $factory, PropertyInterface $parent = null)
 {
     $this->name = $name;
     $this->parent = $parent;
     $this->factory = $factory;
     $this->type = $schema['type'];
     list($customTypes, $properties) = $this->verifySchema($schema);
     foreach ($customTypes as $typeName => $definition) {
         $this->customTypes[$typeName] = $this->factory->createSchema($typeName, $definition, $parent);
     }
     $this->properties = $this->factory->createProperties($properties, $this, $parent);
 }
Example #2
0
 public function testCreateProperies()
 {
     $factory = new Factory();
     $mockSchema = $this->getMockBuilder(SchemaInterface::class)->getMock();
     $properties = $factory->createProperties(['username' => ['type' => 'string'], 'active' => ['type' => 'bool'], 'login_attempts' => ['type' => 'int']], $mockSchema);
     $this->assertCount(3, $properties);
     $this->assertInstanceOf(StringProperty::class, $properties['username']);
     $this->assertInstanceOf(BoolProperty::class, $properties['active']);
     $this->assertInstanceOf(IntProperty::class, $properties['login_attempts']);
 }