$token =
new ConcreteToken(['ROLE_FOO'
]);
$this->
assertEquals(['ROLE_FOO'
],
$token->
getRoleNames());
} public function testAttributes() { $attributes =
['foo' => 'bar'
];
$token =
new ConcreteToken();
$token->
setAttributes($attributes);
$this->
assertEquals($attributes,
$token->
getAttributes(), '->getAttributes() returns the token attributes'
);
$this->
assertEquals('bar',
$token->
getAttribute('foo'
), '->getAttribute() returns the value of an attribute'
);
$token->
setAttribute('foo', 'foo'
);
$this->
assertEquals('foo',
$token->
getAttribute('foo'
), '->setAttribute() changes the value of an attribute'
);
$this->
assertTrue($token->
hasAttribute('foo'
), '->hasAttribute() returns true if the attribute is defined'
);
$this->
assertFalse($token->
hasAttribute('oof'
), '->hasAttribute() returns false if the attribute is not defined'
);
try { $token->
getAttribute('foobar'
);
$this->
fail('->getAttribute() throws an \InvalidArgumentException exception when the attribute does not exist'
);
} catch (\Exception
$e) { $this->
assertInstanceOf(\InvalidArgumentException::
class,
$e, '->getAttribute() throws an \InvalidArgumentException exception when the attribute does not exist'
);
$this->
assertEquals('This token has no "foobar" attribute.',
$e->
getMessage(), '->getAttribute() throws an \InvalidArgumentException exception when the attribute does not exist'
);
}