-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchemaObjectTest.php
More file actions
67 lines (59 loc) · 2.11 KB
/
SchemaObjectTest.php
File metadata and controls
67 lines (59 loc) · 2.11 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
<?php
namespace Tests\Utopia\Agents;
use PHPUnit\Framework\TestCase;
use Utopia\Agents\Schema\SchemaObject;
class SchemaObjectTest extends TestCase
{
public function testConstructorAndGetProperties(): void
{
$properties = [
'id' => ['type' => SchemaObject::TYPE_STRING],
'age' => ['type' => SchemaObject::TYPE_INTEGER],
];
$object = new SchemaObject($properties);
$this->assertSame($properties, $object->getProperties());
}
public function testGetProperty(): void
{
$object = new SchemaObject([
'id' => ['type' => SchemaObject::TYPE_STRING],
]);
$this->assertSame(['type' => SchemaObject::TYPE_STRING], $object->getProperty('id'));
$this->assertNull($object->getProperty('nonexistent'));
}
public function testAddPropertyAndRemoveProperty(): void
{
$object = new SchemaObject();
$object->addProperty('id', ['type' => SchemaObject::TYPE_STRING]);
$this->assertSame(['id' => ['type' => SchemaObject::TYPE_STRING]], $object->getProperties());
$object->removeProperty('id');
$this->assertSame([], $object->getProperties());
}
public function testAddPropertyInvalidType(): void
{
$object = new SchemaObject();
$this->expectException(\InvalidArgumentException::class);
$object->addProperty('bad', ['type' => 'invalid_type']);
}
public function testGetNames(): void
{
$object = new SchemaObject([
'id' => ['type' => SchemaObject::TYPE_STRING],
'age' => ['type' => SchemaObject::TYPE_INTEGER],
]);
$this->assertSame(['id', 'age'], $object->getNames());
}
public function testGetValidTypes(): void
{
$expected = [
SchemaObject::TYPE_STRING,
SchemaObject::TYPE_ARRAY,
SchemaObject::TYPE_BOOLEAN,
SchemaObject::TYPE_INTEGER,
SchemaObject::TYPE_NUMBER,
SchemaObject::TYPE_OBJECT,
SchemaObject::TYPE_NULL,
];
$this->assertSame($expected, SchemaObject::getValidTypes());
}
}