/** * @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); }
/** * @expectedException \Shrink0r\PhpSchema\Exception * @expectedExceptionMessage Given property type 'foo' has not been registered. */ public function testCreatePropertyWithNonRegisteredType() { $factory = new Factory(); $mockSchema = $this->getMockBuilder(SchemaInterface::class)->getMock(); $factory->createProperty(['type' => 'foo', 'name' => 'bar'], $mockSchema); }