Well if you tested the battery and it works in a different phone and charges that indicates that your charger and battery are fine.
Probably the port for charging got loosened from wear and tear.
The phone needs to be serviced.
If it is less then a year old and purchased thru T-Mobile , call them and they may be able to ship replacement phone.
My phone is having the same issue and I just got the phone at the beginning of May. I am little perturbed, for one the phone is soo expensive, it should work perfectly! If they want to charge over $500 for it, then there should never be an issue! I think i messed up geting a HTC phone . I have tried to reset it like they suggested, and nothing has changed. Another problem I was experiencing very early was that the phone would get unusually hot as well! Best believe I'll be contacting them first thing in the morning and I want a new phone expedited to me at their expense! Why should I have to pay to have the phone shipped to me, when it's their faulty technology and since I use my phone for work, I can't, not have a cell phone! Its REALLY frustrating!!