When a lawyer is a witness for his client, except as to merely moral matters, such as the attestation or custody of an instrument and the like, he should leave the trial of the case to other counsel. Except when essential to the ends of justice, a lawyer should avoid testifying in court in behalf of his client.