I am using an ORM-based framework on the Active Recording Image . Every table that I have in my database is tied to a model in my code.
I want to use the unit test for these models, so I started by extracting all the calls to save()and update()from the models, so that changes are made only on the objects, and they are only saved after necessary.
I do not know how I can apply this strategy in this case. I have a model Chatin which a Useris a part, and Usercan add ChatNoteto Chat.
Here's the current implementation:
public function addChatNote($chatNoteContent, Chat $chat)
{
$chatNote = new ChatNote();
$chatNote->content = $chatNoteContent;
$chatNote->save();
$chat->note()->associate($chatNote);
$chat->save();
}
, , , save() .
ChatNote , ? Chat , User - , ChatNote Chat? save()?