Contao\CoreBundle\Test\Monolog\ContaoTableProcessorTest::testUsername PHP Method

testUsername() public method

Tests that the username is added.
public testUsername ( )
    public function testUsername()
    {
        $token = $this->getMock('Contao\\CoreBundle\\Security\\Authentication\\ContaoToken', [], [], '', false);
        $token->expects($this->any())->method('getUsername')->willReturn('k.jones');
        $tokenStorage = new TokenStorage();
        $tokenStorage->setToken($token);
        $processor = $this->createContaoTableProcessor(null, $tokenStorage);
        /** @var ContaoContext $context */
        $context = $processor(['context' => ['contao' => new ContaoContext(__METHOD__, null, 'foobar')]])['extra']['contao'];
        $this->assertEquals('foobar', $context->getUsername());
        /** @var ContaoContext $context */
        $context = $processor(['context' => ['contao' => new ContaoContext(__METHOD__)]])['extra']['contao'];
        $this->assertEquals('k.jones', $context->getUsername());
        $tokenStorage->setToken(null);
        /** @var ContaoContext $context */
        $context = $processor(['context' => ['contao' => new ContaoContext(__METHOD__)]])['extra']['contao'];
        $this->assertEquals('N/A', $context->getUsername());
    }