How to test for the entity closest to the player?

So I am making a map and I need to be able to test for the CLOSEST entity to the player, is this possible with /testfor yet? /execute @e[type=entity name here] ~ ~ ~ /testfor @p will test for the player closest to an entity, instead of the closest entity to the player. So how do I achieve this? Is it even possible? It's kinda like how if you have Steve and Alex next to a command block with the command /testfor @p will find Steve if Steve is closest and same with Alex, just entities instead of people and relative to me, not a command bock.


Solution 1:

/execute as @e[sort=nearest] run <'whatever'>

for 1.13