8000 [Security] added string representation for core Users · symfony/symfony@722c3a7 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 722c3a7

Browse files
tobiassjostenfabpot
authored andcommitted
[Security] added string representation for core Users
1 parent 1882cb1 commit 722c3a7

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
< 8000 div class="d-flex gap-2 flex-items-center">

src/Symfony/Component/Security/Core/Tests/User/UserTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,13 @@ public function testEraseCredentials()
123123
$user->eraseCredentials();
124124
$this->assertEquals('superpass', $user->getPassword());
125125
}
126+
127+
/**
128+
* @covers Symfony\Component\Security\Core\User\User::__toString
129+
*/
130+
public function testToString()
131+
{
132+
$user = new User('fabien', 'superpass');
133+
$this->assertEquals('fabien', (string) $user);
134+
}
126135
}

src/Symfony/Component/Security/Core/User/User.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public function __construct($username, $password, array $roles = array(), $enabl
4343
$this->roles = $roles;
4444
}
4545

46+
public function __toString()
47+
{
48+
return $this->getUsername();
49+
}
50+
4651
/**
4752
* {@inheritdoc}
4853
*/

0 commit comments

Comments
 (0)
0