From a5b15dc1e37bdaf0276edd78769e100bef0d37f6 Mon Sep 17 00:00:00 2001 From: James Halsall Date: Sun, 2 Feb 2014 20:55:47 +0000 Subject: [PATCH 1/2] [Security] Adding __toString() method to Role class --- src/Symfony/Component/Security/Core/Role/Role.php | 10 ++++++++++ 1 file changed, 10 insertions(+) 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; + } } From 2eb77539c34ce199e9db95c9af5db5fca27f7231 Mon Sep 17 00:00:00 2001 From: James Halsall Date: Sun, 2 Feb 2014 22:29:24 +0000 Subject: [PATCH 2/2] Adding tests to ensure that Role::__toString() behaves as expected --- .../Security/Tests/Core/Role/RoleTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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') + ); + } }