diff --git a/src/Symfony/Component/Security/Core/Role/Role.php b/src/Symfony/Component/Security/Core/Role/Role.php index 5b50981fe1a78..67d2734e0bd2b 100644 --- a/src/Symfony/Component/Security/Core/Role/Role.php +++ b/src/Symfony/Component/Security/Core/Role/Role.php @@ -38,4 +38,14 @@ public function getRole() { return $this->role; } + + /** + * Returns a string representation of the role + * + * @return string + */ + public function __toString() + { + return $this->role; + } } diff --git a/src/Symfony/Component/Security/Tests/Core/Role/RoleTest.php b/src/Symfony/Component/Security/Tests/Core/Role/RoleTest.php index e2e7ca86b637f..73ada996a31c3 100644 --- a/src/Symfony/Component/Security/Tests/Core/Role/RoleTest.php +++ b/src/Symfony/Component/Security/Tests/Core/Role/RoleTest.php @@ -21,4 +21,20 @@ public function testGetRole() $this->assertEquals('FOO', $role->getRole()); } + + /** + * @dataProvider getToStringFixtures + */ + public function testToString($role, $expected) + { + $this->assertEquals($role, $expected); + } + + public function getToStringFixtures() + { + return array( + array(new Role(null), ''), + array(new Role('FOO'), 'FOO') + ); + } }