I’ve created several helper methods for Database class:
I’ve also created base class DatabaseBaseTest which uses those methods heavily.
As for unit testing, I’ve impelented SyslogSessionMapper tests for several methods, but refactoring base classes have taken too much time.
save() method internally uses insertSession() and updateSession() (for non-persistent / persistent sessions accodingly ). First method is tested, second my is my future plan. I also need to unit test save() method.
As for delete() method — there will be some difficulties. Before I delete session object I have to delete all related syslog messages (by session_id foreign key in “syslog” db table). Currently SyslogMessageMapper isn’t implemented, so I need manually insert records into syslog messages table for unit testing delete() method
Additionally we do need getLatestSession() method which will retrieved latest session object from database. SQL will looks like:
select id,max(start_date),end_date from syslog_sessions