17
17
use PHPUnit \Framework \Attributes \UsesClass ;
18
18
use PHPUnit \Framework \TestCase ;
19
19
use Symfony \AI \Platform \Message \AssistantMessage ;
20
+ use Symfony \AI \Platform \Message \Content \ContentInterface ;
20
21
use Symfony \AI \Platform \Message \Content \ImageUrl ;
21
22
use Symfony \AI \Platform \Message \Content \Text ;
22
23
use Symfony \AI \Platform \Message \Message ;
39
40
final class MessageTest extends TestCase
40
41
{
41
42
#[Test]
42
- public function createSystemMessage (): void
43
+ public function createSystemMessageWithString (): void
43
44
{
44
45
$ message = Message::forSystem ('My amazing system prompt. ' );
45
46
46
47
self ::assertSame ('My amazing system prompt. ' , $ message ->content );
47
48
}
48
49
50
+ #[Test]
51
+ public function createSystemMessageWithStringable (): void
52
+ {
53
+ $ message = Message::forSystem (new class implements \Stringable {
54
+ public function __toString (): string
55
+ {
56
+ return 'My amazing system prompt. ' ;
57
+ }
58
+ });
59
+
60
+ self ::assertSame ('My amazing system prompt. ' , $ message ->content );
61
+ }
62
+
49
63
#[Test]
50
64
public function createAssistantMessage (): void
51
65
{
@@ -68,7 +82,7 @@ public function createAssistantMessageWithToolCalls(): void
68
82
}
69
83
70
84
#[Test]
71
- public function createUserMessage (): void
85
+ public function createUserMessageWithString (): void
72
86
{
73
87
$ message = Message::ofUser ('Hi, my name is John. ' );
74
88
@@ -77,6 +91,35 @@ public function createUserMessage(): void
77
91
self ::assertSame ('Hi, my name is John. ' , $ message ->content [0 ]->text );
78
92
}
79
93
94
+ #[Test]
95
+ public function createUserMessageWithStringable (): void
96
+ {
97
+ $ message = Message::ofUser (new class implements \Stringable {
98
+ public function __toString (): string
99
+ {
100
+ return 'Hi, my name is John. ' ;
101
+ }
102
+ });
103
+
104
+ self ::assertCount (1 , $ message ->content );
105
+ self ::assertInstanceOf (Text::class, $ message ->content [0 ]);
106
+ self ::assertSame ('Hi, my name is John. ' , $ message ->content [0 ]->text );
107
+ }
108
+
109
+ #[Test]
110
+ public function createUserMessageContentInterfaceImplementingStringable (): void
111
+ {
112
+ $ message = Message::ofUser (new class implements ContentInterface, \Stringable {
113
+ public function __toString (): string
114
+ {
115
+ return 'I am a ContentInterface! ' ;
116
+ }
117
+ });
118
+
119
+ self ::assertCount (1 , $ message ->content );
120
+ self ::assertInstanceOf (ContentInterface::class, $ message ->content [0 ]);
121
+ }
122
+
80
123
#[Test]
81
124
public function createUserMessageWithTextContent (): void
82
125
{
0 commit comments