Search code examples
phpsymfonytoken

In this Symfony core class, what is the fully qualified class name of the token that's being returned?


I am building some extra unit tests for a Symfony 2.7 application. In order to do that, I need to mock the output of a getToken() method that the application is using.

The getToken method is defined within this short class:

namespace Symfony\Component\Security\Core\Authentication\Token\Storage;

use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

/**
 * TokenStorage contains a TokenInterface.
 *
 * It gives access to the token representing the current user authentication.
 *
 * @author Fabien Potencier <[email protected]>
 * @author Johannes M. Schmitt <[email protected]>
 */
class TokenStorage implements TokenStorageInterface
{
    private $token;

    /**
     * {@inheritdoc}
     */
    public function getToken()
    {
        return $this->token;
    }

    /**
     * {@inheritdoc}
     */
    public function setToken(TokenInterface $token = null)
    {
        $this->token = $token;
    }
}

Now I just need to figure out what type of Token is being returned by the method. Since this is a core part of Symfony, I figured I would ask before spending an afternoon debugging: Does anyone know the full name of the token class off the top of their head?


Solution

  • Pass your object into get_class():

    $fullClassName = get_class($this->token);
    

    http://php.net/manual/en/function.get-class.php