Add title, description, and default fields to schema
[MAILPOET-4195]
This commit is contained in:
@@ -35,18 +35,46 @@ class SchemaTest extends MailPoetUnitTest {
|
||||
$this->assertSame('{"type":"test"}', $schema->toString());
|
||||
}
|
||||
|
||||
public function testTitle(): void {
|
||||
$schema = $this->getTestingSchema()->title('Schema title');
|
||||
$this->assertSame(['type' => 'test', 'title' => 'Schema title'], $schema->toArray());
|
||||
$this->assertSame('{"type":"test","title":"Schema title"}', $schema->toString());
|
||||
}
|
||||
|
||||
public function testDescription(): void {
|
||||
$schema = $this->getTestingSchema()->description('Schema description');
|
||||
$this->assertSame(['type' => 'test', 'description' => 'Schema description'], $schema->toArray());
|
||||
$this->assertSame('{"type":"test","description":"Schema description"}', $schema->toString());
|
||||
}
|
||||
|
||||
public function testDefault(): void {
|
||||
$schema = $this->getTestingSchema()->default('Default value');
|
||||
$this->assertSame(['type' => 'test', 'default' => 'Default value'], $schema->toArray());
|
||||
$this->assertSame('{"type":"test","default":"Default value"}', $schema->toString());
|
||||
|
||||
$schema = $this->getTestingSchema()->default(null);
|
||||
$this->assertSame(['type' => 'test', 'default' => null], $schema->toArray());
|
||||
$this->assertSame('{"type":"test","default":null}', $schema->toString());
|
||||
}
|
||||
|
||||
public function testMixedProperties(): void {
|
||||
$schema = $this->getTestingSchema()
|
||||
->required()
|
||||
->nullable();
|
||||
->nullable()
|
||||
->title('Schema title')
|
||||
->description('Schema description')
|
||||
->default('Default value');
|
||||
|
||||
$this->assertSame([
|
||||
'type' => ['test', 'null'],
|
||||
'required' => true,
|
||||
'title' => 'Schema title',
|
||||
'description' => 'Schema description',
|
||||
'default' => 'Default value',
|
||||
], $schema->toArray());
|
||||
|
||||
$this->assertSame(
|
||||
'{"type":["test","null"],"required":true}',
|
||||
'{"type":["test","null"],"required":true,"title":"Schema title","description":"Schema description","default":"Default value"}',
|
||||
$schema->toString()
|
||||
);
|
||||
}
|
||||
@@ -57,6 +85,9 @@ class SchemaTest extends MailPoetUnitTest {
|
||||
$this->assertNotSame($schema->nonNullable(), $schema);
|
||||
$this->assertNotSame($schema->required(), $schema);
|
||||
$this->assertNotSame($schema->optional(), $schema);
|
||||
$this->assertNotSame($schema->title('Title'), $schema);
|
||||
$this->assertNotSame($schema->description('Description'), $schema);
|
||||
$this->assertNotSame($schema->default(null), $schema);
|
||||
}
|
||||
|
||||
private function getTestingSchema(): Schema {
|
||||
|
Reference in New Issue
Block a user