66
77use Illuminate \Database \Capsule \Manager as Capsule ;
88use Illuminate \Database \Eloquent \Model ;
9+ use Illuminate \Database \Schema \Blueprint ;
910use NeuronAI \Chat \History \ChatHistoryInterface ;
1011use NeuronAI \Chat \History \EloquentChatHistory ;
1112use NeuronAI \Chat \Messages \AssistantMessage ;
@@ -32,7 +33,7 @@ public function setUp(): void
3233 $ capsule ->bootEloquent ();
3334
3435 // Create the chat_messages table
35- Capsule::schema ()->create ('chat_messages ' , function ($ table ) {
36+ Capsule::schema ()->create ('chat_messages ' , function (Blueprint $ table ): void {
3637 $ table ->id ();
3738 $ table ->string ('thread_id ' );
3839 $ table ->string ('role ' );
@@ -60,7 +61,6 @@ public function test_creates_chat_history_instance(): void
6061 public function test_starts_with_empty_history (): void
6162 {
6263 $ messages = $ this ->history ->getMessages ();
63- $ this ->assertIsArray ($ messages );
6464 $ this ->assertCount (0 , $ messages );
6565 }
6666
@@ -70,11 +70,11 @@ public function test_adds_message_to_database(): void
7070 $ this ->history ->addMessage ($ message );
7171
7272 // Verify in database
73- $ count = ChatMessage::where ('thread_id ' , $ this ->threadId )->count ();
73+ $ count = ChatMessage::query ()-> where ('thread_id ' , $ this ->threadId )->count ();
7474 $ this ->assertEquals (1 , $ count );
7575
7676 // Verify message content
77- $ record = ChatMessage::where ('thread_id ' , $ this ->threadId )->first ();
77+ $ record = ChatMessage::query ()-> where ('thread_id ' , $ this ->threadId )->first ();
7878 $ this ->assertEquals ('user ' , $ record ->role );
7979 $ this ->assertEquals ('Hello from Eloquent! ' , $ record ->content );
8080 }
@@ -103,7 +103,7 @@ public function test_persists_multiple_messages(): void
103103 $ this ->history ->addMessage (new AssistantMessage ('Message 2 ' ));
104104 $ this ->history ->addMessage (new UserMessage ('Message 3 ' ));
105105
106- $ count = ChatMessage::where ('thread_id ' , $ this ->threadId )->count ();
106+ $ count = ChatMessage::query ()-> where ('thread_id ' , $ this ->threadId )->count ();
107107 $ this ->assertEquals (3 , $ count );
108108
109109 $ messages = $ this ->history ->getMessages ();
@@ -113,12 +113,12 @@ public function test_persists_multiple_messages(): void
113113 public function test_clear_removes_all_messages_from_database (): void
114114 {
115115 $ this ->history ->addMessage (new UserMessage ('Test message ' ));
116- $ this ->assertEquals (1 , ChatMessage::where ('thread_id ' , $ this ->threadId )->count ());
116+ $ this ->assertEquals (1 , ChatMessage::query ()-> where ('thread_id ' , $ this ->threadId )->count ());
117117
118118 $ this ->history ->flushAll ();
119119
120120 // Verify messages are removed from database
121- $ this ->assertEquals (0 , ChatMessage::where ('thread_id ' , $ this ->threadId )->count ());
121+ $ this ->assertEquals (0 , ChatMessage::query ()-> where ('thread_id ' , $ this ->threadId )->count ());
122122
123123 // Verify history is empty
124124 $ this ->assertCount (0 , $ this ->history ->getMessages ());
@@ -202,8 +202,8 @@ public function test_multiple_threads_are_isolated(): void
202202 $ this ->assertEquals ('Message in thread 2 ' , $ reloaded2 ->getMessages ()[0 ]->getContent ());
203203
204204 // Verify database isolation
205- $ this ->assertEquals (1 , ChatMessage::where ('thread_id ' , $ thread1 )->count ());
206- $ this ->assertEquals (1 , ChatMessage::where ('thread_id ' , $ thread2 )->count ());
205+ $ this ->assertEquals (1 , ChatMessage::query ()-> where ('thread_id ' , $ thread1 )->count ());
206+ $ this ->assertEquals (1 , ChatMessage::query ()-> where ('thread_id ' , $ thread2 )->count ());
207207 }
208208
209209 public function test_set_messages_maintains_database_consistency (): void
@@ -212,12 +212,12 @@ public function test_set_messages_maintains_database_consistency(): void
212212 $ this ->history ->addMessage (new UserMessage ('Message 1 ' ));
213213 $ this ->history ->addMessage (new AssistantMessage ('Message 2 ' ));
214214
215- $ this ->assertEquals (2 , ChatMessage::where ('thread_id ' , $ this ->threadId )->count ());
215+ $ this ->assertEquals (2 , ChatMessage::query ()-> where ('thread_id ' , $ this ->threadId )->count ());
216216
217217 // The setMessages method is used internally by addMessage
218218 // Verify that in-memory and database are in sync
219219 $ messages = $ this ->history ->getMessages ();
220- $ dbRecords = ChatMessage::where ('thread_id ' , $ this ->threadId )->orderBy ('id ' )->get ();
220+ $ dbRecords = ChatMessage::query ()-> where ('thread_id ' , $ this ->threadId )->orderBy ('id ' )->get ();
221221
222222 $ this ->assertCount (\count ($ messages ), $ dbRecords );
223223 }
0 commit comments