How can one simulate being logged in as a different user in Joomla using PHP?

To simulate being logged in as a different user in Joomla using PHP, you can use Joomla's `JFactory::getUser()` method to load the user object of the desired user and then set this user object as the current user using Joomla's `JFactory::getApplication()->setUser()` method.

// Load the desired user object
$user = JFactory::getUser($userId);

// Set the loaded user object as the current user
JFactory::getApplication()->setUser($user);