Skip to content

Commit 2d9312e

Browse files
committed
Fix tests
1 parent bd55d19 commit 2d9312e

8 files changed

+70
-15
lines changed

src/Security/UserClassBuilder.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,9 @@ private function addGetUsername(ClassSourceManipulator $manipulator, UserClassCo
9898
);
9999
}
100100

101-
$getterIdentifierName = 'getUsername';
102-
103101
// Check if we're using Symfony 5.3+ - UserInterface::getUsername() was replaced with UserInterface::getUserIdentifier()
104-
if (class_exists(InMemoryUser::class)) {
105-
$getterIdentifierName = 'getUserIdentifier';
106-
107-
// also add the deprecated getUsername method
108-
$manipulator->addAccessorMethod(
109-
$userClassConfig->getIdentityPropertyName(),
110-
'getUsername',
111-
'string',
112-
false,
113-
['@deprecated since Symfony 5.3, use getUserIdentifier instead'],
114-
true
115-
);
116-
}
102+
$symfony53GTE = class_exists(InMemoryUser::class);
103+
$getterIdentifierName = $symfony53GTE ? 'getUserIdentifier' : 'getUsername';
117104

118105
// define getUsername (if it was defined above, this will override)
119106
$manipulator->addAccessorMethod(
@@ -128,6 +115,18 @@ private function addGetUsername(ClassSourceManipulator $manipulator, UserClassCo
128115
],
129116
true
130117
);
118+
119+
if ($symfony53GTE) {
120+
// also add the deprecated getUsername method
121+
$manipulator->addAccessorMethod(
122+
$userClassConfig->getIdentityPropertyName(),
123+
'getUsername',
124+
'string',
125+
false,
126+
['@deprecated since Symfony 5.3, use getUserIdentifier instead'],
127+
true
128+
);
129+
}
131130
}
132131

133132
private function addGetRoles(ClassSourceManipulator $manipulator, UserClassConfiguration $userClassConfig)

tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ public function getUserIdentifier(): string
6161
return (string) $this->email;
6262
}
6363

64+
/**
65+
* @deprecated since Symfony 5.3, use getUserIdentifier instead
66+
*/
67+
public function getUsername(): string
68+
{
69+
return (string) $this->email;
70+
}
71+
6472
/**
6573
* @see UserInterface
6674
*/

tests/Security/fixtures/expected/UserEntityWithPassword.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ public function setUserIdentifier(string $userIdentifier): self
5656
return $this;
5757
}
5858

59+
/**
60+
* @deprecated since Symfony 5.3, use getUserIdentifier instead
61+
*/
62+
public function getUsername(): string
63+
{
64+
return (string) $this->userIdentifier;
65+
}
66+
5967
/**
6068
* @see UserInterface
6169
*/

tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ public function setUserIdentifier(string $user_identifier): self
5656
return $this;
5757
}
5858

59+
/**
60+
* @deprecated since Symfony 5.3, use getUserIdentifier instead
61+
*/
62+
public function getUsername(): string
63+
{
64+
return (string) $this->user_identifier;
65+
}
66+
5967
/**
6068
* @see UserInterface
6169
*/

tests/Security/fixtures/expected/UserEntityWithoutPassword.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ public function setUserIdentifier(string $userIdentifier): self
5050
return $this;
5151
}
5252

53+
/**
54+
* @deprecated since Symfony 5.3, use getUserIdentifier instead
55+
*/
56+
public function getUsername(): string
57+
{
58+
return (string) $this->userIdentifier;
59+
}
60+
5361
/**
5462
* @see UserInterface
5563
*/

tests/Security/fixtures/expected/UserModelWithEmailAsIdentifier.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public function getUserIdentifier(): string
3838
return (string) $this->email;
3939
}
4040

41+
/**
42+
* @deprecated since Symfony 5.3, use getUserIdentifier instead
43+
*/
44+
public function getUsername(): string
45+
{
46+
return (string) $this->email;
47+
}
48+
4149
/**
4250
* @see UserInterface
4351
*/

tests/Security/fixtures/expected/UserModelWithPassword.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public function setUserIdentifier(string $userIdentifier): self
3333
return $this;
3434
}
3535

36+
/**
37+
* @deprecated since Symfony 5.3, use getUserIdentifier instead
38+
*/
39+
public function getUsername(): string
40+
{
41+
return (string) $this->userIdentifier;
42+
}
43+
3644
/**
3745
* @see UserInterface
3846
*/

tests/Security/fixtures/expected/UserModelWithoutPassword.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ public function setUserIdentifier(string $userIdentifier): self
2828
return $this;
2929
}
3030

31+
/**
32+
* @deprecated since Symfony 5.3, use getUserIdentifier instead
33+
*/
34+
public function getUsername(): string
35+
{
36+
return (string) $this->userIdentifier;
37+
}
38+
3139
/**
3240
* @see UserInterface
3341
*/

0 commit comments

Comments
 (0)