How to save an information in the customer session?

An example from the core:

Actually the session has no setBeforeAuthUrl method and the magic __call method is called:

A usage example

1. Setting an information to the customer session:

/** @var \Magento\Framework\App\ObjectManager $om */
$om = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Customer\Model\Session $session */
$session = $om->get('Magento\Customer\Model\Session');
$session->setTestKey('test value');

2. Getting an information from the customer session:

/** @var \Magento\Framework\App\ObjectManager $om */
$om = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Customer\Model\Session $session */
$session = $om->get('Magento\Customer\Model\Session');
echo $session->getTestKey();

See also: