55namespace PhpLlm \LlmChain \Tests \Platform \Message ;
66
77use PhpLlm \LlmChain \Platform \Message \AssistantMessage ;
8+ use PhpLlm \LlmChain \Platform \Message \Content \Text ;
89use PhpLlm \LlmChain \Platform \Message \MessageInterface ;
910use PhpLlm \LlmChain \Platform \Message \Role ;
1011use PhpLlm \LlmChain \Platform \Message \SystemMessage ;
1112use PhpLlm \LlmChain \Platform \Message \ToolCallMessage ;
1213use PhpLlm \LlmChain \Platform \Message \UserMessage ;
13- use PhpLlm \LlmChain \Platform \Message \Content \Text ;
1414use PhpLlm \LlmChain \Platform \Response \ToolCall ;
1515use PHPUnit \Framework \TestCase ;
1616use Symfony \Component \Uid \AbstractUid ;
@@ -24,7 +24,7 @@ final class MessageIdTypeTest extends TestCase
2424 public function testAssistantMessageIdImplementsRequiredInterfaces (): void
2525 {
2626 $ message = new AssistantMessage ('test ' );
27-
27+
2828 self ::assertInstanceOf (AbstractUid::class, $ message ->getId ());
2929 self ::assertInstanceOf (TimeBasedUidInterface::class, $ message ->getId ());
3030 self ::assertInstanceOf (Uuid::class, $ message ->getId ());
@@ -34,7 +34,7 @@ public function testAssistantMessageIdImplementsRequiredInterfaces(): void
3434 public function testSystemMessageIdImplementsRequiredInterfaces (): void
3535 {
3636 $ message = new SystemMessage ('test ' );
37-
37+
3838 self ::assertInstanceOf (AbstractUid::class, $ message ->getId ());
3939 self ::assertInstanceOf (TimeBasedUidInterface::class, $ message ->getId ());
4040 self ::assertInstanceOf (Uuid::class, $ message ->getId ());
@@ -44,7 +44,7 @@ public function testSystemMessageIdImplementsRequiredInterfaces(): void
4444 public function testUserMessageIdImplementsRequiredInterfaces (): void
4545 {
4646 $ message = new UserMessage (new Text ('test ' ));
47-
47+
4848 self ::assertInstanceOf (AbstractUid::class, $ message ->getId ());
4949 self ::assertInstanceOf (TimeBasedUidInterface::class, $ message ->getId ());
5050 self ::assertInstanceOf (Uuid::class, $ message ->getId ());
@@ -55,7 +55,7 @@ public function testToolCallMessageIdImplementsRequiredInterfaces(): void
5555 {
5656 $ toolCall = new ToolCall ('test-id ' , 'test-function ' , ['param ' => 'value ' ]);
5757 $ message = new ToolCallMessage ($ toolCall , 'test content ' );
58-
58+
5959 self ::assertInstanceOf (AbstractUid::class, $ message ->getId ());
6060 self ::assertInstanceOf (TimeBasedUidInterface::class, $ message ->getId ());
6161 self ::assertInstanceOf (Uuid::class, $ message ->getId ());
@@ -66,7 +66,7 @@ public function testMessageIdSupportsToRfc4122Method(): void
6666 {
6767 $ message = new AssistantMessage ('test ' );
6868 $ id = $ message ->getId ();
69-
69+
7070 // Test that toRfc4122() method exists and returns a valid UUID string
7171 $ rfc4122 = $ id ->toRfc4122 ();
7272 self ::assertIsString ($ rfc4122 );
@@ -77,11 +77,11 @@ public function testMessageIdSupportsGetDateTimeMethod(): void
7777 {
7878 $ message = new AssistantMessage ('test ' );
7979 $ id = $ message ->getId ();
80-
80+
8181 // Test that getDateTime() method exists and returns a DateTimeImmutable
8282 $ dateTime = $ id ->getDateTime ();
8383 self ::assertInstanceOf (\DateTimeImmutable::class, $ dateTime );
84-
84+
8585 // The timestamp should be recent (within the last minute)
8686 $ now = new \DateTimeImmutable ();
8787 $ diff = $ now ->getTimestamp () - $ dateTime ->getTimestamp ();
@@ -93,26 +93,27 @@ public function testCustomMessageImplementationWithUuid(): void
9393 {
9494 $ customMessage = new class implements MessageInterface {
9595 public AbstractUid &TimeBasedUidInterface $ id ;
96-
97- public function __construct () {
96+
97+ public function __construct ()
98+ {
9899 $ this ->id = Uuid::v7 ();
99100 }
100-
101+
101102 public function getRole (): Role
102103 {
103104 return Role::User;
104105 }
105-
106+
106107 public function getId (): AbstractUid &TimeBasedUidInterface
107108 {
108109 return $ this ->id ;
109110 }
110111 };
111-
112+
112113 self ::assertInstanceOf (AbstractUid::class, $ customMessage ->getId ());
113114 self ::assertInstanceOf (TimeBasedUidInterface::class, $ customMessage ->getId ());
114115 self ::assertInstanceOf (Uuid::class, $ customMessage ->getId ());
115-
116+
116117 // Verify both methods work
117118 self ::assertIsString ($ customMessage ->getId ()->toRfc4122 ());
118119 self ::assertInstanceOf (\DateTimeImmutable::class, $ customMessage ->getId ()->getDateTime ());
@@ -122,30 +123,31 @@ public function testCustomMessageImplementationWithUlid(): void
122123 {
123124 $ customMessage = new class implements MessageInterface {
124125 public AbstractUid &TimeBasedUidInterface $ id ;
125-
126- public function __construct () {
126+
127+ public function __construct ()
128+ {
127129 $ this ->id = new Ulid ();
128130 }
129-
131+
130132 public function getRole (): Role
131133 {
132134 return Role::User;
133135 }
134-
136+
135137 public function getId (): AbstractUid &TimeBasedUidInterface
136138 {
137139 return $ this ->id ;
138140 }
139141 };
140-
142+
141143 self ::assertInstanceOf (AbstractUid::class, $ customMessage ->getId ());
142144 self ::assertInstanceOf (TimeBasedUidInterface::class, $ customMessage ->getId ());
143145 self ::assertInstanceOf (Ulid::class, $ customMessage ->getId ());
144-
146+
145147 // Verify both methods work
146148 self ::assertIsString ($ customMessage ->getId ()->toRfc4122 ());
147149 self ::assertInstanceOf (\DateTimeImmutable::class, $ customMessage ->getId ()->getDateTime ());
148-
150+
149151 // ULID specific: verify it's a valid ULID format
150152 self ::assertMatchesRegularExpression ('/^[0-9A-Z]{26}$/i ' , (string ) $ customMessage ->getId ());
151153 }
@@ -154,48 +156,50 @@ public function testDifferentUidTypesAreInterchangeable(): void
154156 {
155157 $ uuidMessage = new class implements MessageInterface {
156158 public AbstractUid &TimeBasedUidInterface $ id ;
157-
158- public function __construct () {
159+
160+ public function __construct ()
161+ {
159162 $ this ->id = Uuid::v7 ();
160163 }
161-
164+
162165 public function getRole (): Role
163166 {
164167 return Role::Assistant;
165168 }
166-
169+
167170 public function getId (): AbstractUid &TimeBasedUidInterface
168171 {
169172 return $ this ->id ;
170173 }
171174 };
172-
175+
173176 $ ulidMessage = new class implements MessageInterface {
174177 public AbstractUid &TimeBasedUidInterface $ id ;
175-
176- public function __construct () {
178+
179+ public function __construct ()
180+ {
177181 $ this ->id = new Ulid ();
178182 }
179-
183+
180184 public function getRole (): Role
181185 {
182186 return Role::Assistant;
183187 }
184-
188+
185189 public function getId (): AbstractUid &TimeBasedUidInterface
186190 {
187191 return $ this ->id ;
188192 }
189193 };
190-
194+
191195 // Both should be valid MessageInterface implementations
192196 self ::assertInstanceOf (MessageInterface::class, $ uuidMessage );
193197 self ::assertInstanceOf (MessageInterface::class, $ ulidMessage );
194-
198+
195199 // Both should support the same methods
196200 self ::assertIsString ($ uuidMessage ->getId ()->toRfc4122 ());
197201 self ::assertIsString ($ ulidMessage ->getId ()->toRfc4122 ());
198-
202+
199203 self ::assertInstanceOf (\DateTimeImmutable::class, $ uuidMessage ->getId ()->getDateTime ());
200204 self ::assertInstanceOf (\DateTimeImmutable::class, $ ulidMessage ->getId ()->getDateTime ());
201205 }
@@ -204,28 +208,28 @@ public function testMessageIdConversionMethods(): void
204208 {
205209 $ message = new AssistantMessage ('test ' );
206210 $ id = $ message ->getId ();
207-
211+
208212 // Test various AbstractUid conversion methods
209213 self ::assertIsString ($ id ->toBinary ());
210214 self ::assertIsString ($ id ->toBase32 ());
211215 self ::assertIsString ($ id ->toBase58 ());
212216 self ::assertIsString ($ id ->toRfc4122 ());
213-
217+
214218 // Test that conversions produce expected formats
215- self ::assertEquals (16 , strlen ($ id ->toBinary ()));
216- self ::assertEquals (26 , strlen ($ id ->toBase32 ()));
217- self ::assertEquals (22 , strlen ($ id ->toBase58 ()));
218- self ::assertEquals (36 , strlen ($ id ->toRfc4122 ()));
219+ self ::assertEquals (16 , \ strlen ($ id ->toBinary ()));
220+ self ::assertEquals (26 , \ strlen ($ id ->toBase32 ()));
221+ self ::assertEquals (22 , \ strlen ($ id ->toBase58 ()));
222+ self ::assertEquals (36 , \ strlen ($ id ->toRfc4122 ()));
219223 }
220224
221225 public function testMessageIdComparison (): void
222226 {
223227 $ message1 = new AssistantMessage ('test1 ' );
224228 $ message2 = new AssistantMessage ('test2 ' );
225-
229+
226230 // Messages should have different IDs
227231 self ::assertNotEquals ($ message1 ->getId ()->toRfc4122 (), $ message2 ->getId ()->toRfc4122 ());
228-
232+
229233 // But the same message instance should always return the same ID
230234 self ::assertEquals ($ message1 ->getId ()->toRfc4122 (), $ message1 ->getId ()->toRfc4122 ());
231235 }
@@ -235,11 +239,11 @@ public function testMessageIdTimestampOrdering(): void
235239 $ message1 = new AssistantMessage ('first ' );
236240 usleep (1000 ); // Sleep for 1ms to ensure different timestamp
237241 $ message2 = new AssistantMessage ('second ' );
238-
242+
239243 $ time1 = $ message1 ->getId ()->getDateTime ();
240244 $ time2 = $ message2 ->getId ()->getDateTime ();
241-
245+
242246 // Second message should have a later timestamp
243247 self ::assertGreaterThanOrEqual ($ time1 ->getTimestamp (), $ time2 ->getTimestamp ());
244248 }
245- }
249+ }
0 commit comments