-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSchemaTest.php
More file actions
70 lines (59 loc) · 2.06 KB
/
SchemaTest.php
File metadata and controls
70 lines (59 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Tests\Utopia\Agents;
use PHPUnit\Framework\TestCase;
use Utopia\Agents\Schema;
use Utopia\Agents\Schema\SchemaObject;
class SchemaTest extends TestCase
{
private Schema $schema;
private SchemaObject $object;
private string $name = 'TestSchema';
private string $description = 'A test schema.';
/**
* @var array<int, string>
*/
private array $required = ['id', 'name'];
protected function setUp(): void
{
$this->object = new SchemaObject([
'id' => [
'type' => SchemaObject::TYPE_STRING,
'description' => 'The ID of the user',
],
'name' => [
'type' => SchemaObject::TYPE_STRING,
'description' => 'The name of the user',
],
'age' => [
'type' => SchemaObject::TYPE_INTEGER,
'description' => 'The age of the user',
],
]);
$this->schema = new Schema(
$this->name,
$this->description,
$this->object,
$this->required
);
}
public function testConstructorAndGetters(): void
{
$this->assertSame($this->name, $this->schema->getName());
$this->assertSame($this->description, $this->schema->getDescription());
$this->assertSame($this->object, $this->schema->getObject());
$this->assertSame($this->required, $this->schema->getRequired());
}
public function testToJson(): void
{
$json = $this->schema->toJson();
$this->assertIsString($json);
$jsonArray = json_decode($json, true);
$this->assertIsArray($jsonArray);
$this->assertArrayHasKey('id', $jsonArray);
$this->assertArrayHasKey('name', $jsonArray);
$this->assertArrayHasKey('age', $jsonArray);
$this->assertSame('The ID of the user (string)', $jsonArray['id']);
$this->assertSame('The name of the user (string)', $jsonArray['name']);
$this->assertSame('The age of the user (integer)', $jsonArray['age']);
}
}