/** * @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); }
public function testCreateSchema() { $factory = new Factory(); $schema = $factory->createSchema('login_attempts', ['type' => 'assoc', 'properties' => ['username' => ['type' => 'string'], 'active' => ['type' => 'bool'], 'attempt_count' => ['type' => 'int']]]); $this->assertInstanceOf(SchemaInterface::class, $schema); }