-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathBooleanSchemaDefinitionTest.php
More file actions
108 lines (89 loc) · 3.16 KB
/
Copy pathBooleanSchemaDefinitionTest.php
File metadata and controls
108 lines (89 loc) · 3.16 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Tests\Unit\Schema\Elicitation;
use Mcp\Exception\InvalidArgumentException;
use Mcp\Schema\Elicitation\BooleanSchemaDefinition;
use PHPUnit\Framework\TestCase;
final class BooleanSchemaDefinitionTest extends TestCase
{
public function testConstructorWithMinimalParams(): void
{
$schema = new BooleanSchemaDefinition('Confirm');
$this->assertSame('Confirm', $schema->title);
$this->assertNull($schema->description);
$this->assertNull($schema->default);
}
public function testConstructorWithAllParams(): void
{
$schema = new BooleanSchemaDefinition(
title: 'Confirmation',
description: 'Do you confirm this action?',
default: false,
);
$this->assertSame('Confirmation', $schema->title);
$this->assertSame('Do you confirm this action?', $schema->description);
$this->assertFalse($schema->default);
}
public function testConstructorWithTrueDefault(): void
{
$schema = new BooleanSchemaDefinition(
title: 'Subscribe',
default: true,
);
$this->assertTrue($schema->default);
}
public function testFromArrayWithMinimalParams(): void
{
$schema = BooleanSchemaDefinition::fromArray(['title' => 'Confirm']);
$this->assertSame('Confirm', $schema->title);
$this->assertNull($schema->description);
$this->assertNull($schema->default);
}
public function testFromArrayWithAllParams(): void
{
$schema = BooleanSchemaDefinition::fromArray([
'title' => 'Confirmation',
'description' => 'Do you confirm this action?',
'default' => true,
]);
$this->assertSame('Confirmation', $schema->title);
$this->assertSame('Do you confirm this action?', $schema->description);
$this->assertTrue($schema->default);
}
public function testFromArrayWithMissingTitle(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Missing or invalid "title"');
/* @phpstan-ignore argument.type */
BooleanSchemaDefinition::fromArray([]);
}
public function testJsonSerializeWithMinimalParams(): void
{
$schema = new BooleanSchemaDefinition('Confirm');
$this->assertSame([
'type' => 'boolean',
'title' => 'Confirm',
], $schema->jsonSerialize());
}
public function testJsonSerializeWithAllParams(): void
{
$schema = new BooleanSchemaDefinition(
title: 'Confirmation',
description: 'Do you confirm this action?',
default: false,
);
$this->assertSame([
'type' => 'boolean',
'title' => 'Confirmation',
'description' => 'Do you confirm this action?',
'default' => false,
], $schema->jsonSerialize());
}
}