And the LORD was with Joseph… – Genesis 39:2, 21
And the patriarchs, moved with envy, sold Joseph into Egypt: but God was with him… – Acts 7:9
Joseph learned in his trial much that was good for present use. For instance, he found by sweet experience that the divine presence can cheer us anywhere. If he had always been at home with his father, always his fathers darling, he would have known that the love of God is sweet to a favored youth, but no one would have been astonished at that. Even Satan would have said, “Well may he rejoice in thee, O Lord. Hast thou not set a hedge about him and all that he hath?” But he learned that God could be with him when he was sold for the price of a slave: with him when led as a captive across the desert, when he walked wearily by the camel’s side with the Ishmaelites: with him in the slave mart to find him a master who might appreciate him; with him when he became a servant in the house, by blessing him, prospering him, and causing him to find favor in the eyes of his master till he became overseer of all that Potiphar had: and then, best of all, though some would say worst of all, he learned that God could be with him in a dungeon. He could not have known that if he had stayed at home, he must be brought into the thick darkness, that the brightness of the divine presence might be the more fully seen. There is nothing in this world so delightful as the light of God’s countenance when all around is dark. You may tell me that the presence of Jesus is glorious upon Tabor’s glorious mount, and I will not contradict you…but give me the soft subdued light of God’s love in adversity; Christ on the stormy waters for me: Christ in the midst of the furnace with His persecuted ones. Never does the Lord’s love taste so sweet as when all the world is wormwood and gall…It was worthwhile, I say, for Joseph to be falsely accused, and to be laid in irons, to learn experimentally the supporting power of the heavenly Father’s smile. ~ C.H. Spurgeon
https://www.blueletterbible.org/Comm/spurgeon_charles/sermons/1277.cfm