Matthew doesn’t tell us how or when Joseph discovered that Mary was pregnant. Still, it must have been shocking news resulting in many sleepless nights as he wrestled with his love for Mary on one hand, and the letter of law on the other hand, which said he could make a public example of her and humiliate her for what appeared to be her unfaithfulness. Verse 20 says that as Joseph was wrestling with his emotions and the decisions he had to make, he had a dream.