Any well-trained and well-led formation will overcome any other. Pyrrhus actually won enough times against the Romans, but the losses incurred were deemed too great. The training, numbers and capability of the enemy (in his case Rome) also bears a large influence on your success.

Having said that there is also the case where the legion by that time had developed tactics that were merely evolutionarily advanced compared to the phalanx and meant to address it's flaws. Still, that doesn't mean an idiot leading a legion will always win against Alexander, just because the former has legionaries. It is not a "gun vs. spear" sort of matter. All of early Rome's defeats had the matter of combined-arms elements playing a large role (or large presence) in the battles. Hannibal didn't win because he had better or more infantry than the Romans, for example.