Can someone please clarify when "Shadow in the Warp" is used?

I am confused about this because even in the official rules it's hazy. Also, when I check the rules for command phase it says that any other rules get sorted out BEFORE battle-shock. But that would mean that when I pop Shadow it just ends imidietly.

I've played it at home games in a way that made the most sense to me (aka during the battle-shock test) but I am not sure if it's the right way. And since I thought about joining some tournament I thought I'd ask someone more experienced in GW writing.