An hour before the flight will be ok. I flew to Phuket from Swampy two weeks ago. I got there 90 minutes before flight, and check in etc right up to departure gate took twenty minutes. That doesn't mean it will work that way for every flight, but Swampy is very quiet at the moment so no queues. Coming back took ten mins through Phuket Airport.
Erik Mc Thundersteel. If the airline refuses boarding, they will reschedule the flight and the hotel will reschedule the stay. There is only ever a problem with refunds, not with rescheduling. The test will be done 72 hours prior to the flight, which gives ample time to make changes, and then there's the chance that the test will be negative.
Baron Crowden. You do NOT need a test to leave Thailand. You MAY need a test to satisfy airline requirements AND/OR destination country requirements, so there is no standard answer