Add unit tests for MessageManagerIterator & fix bug with doctrine context and command optimize method