Skip to content

Commit cdf7591

Browse files
committed
[make:user] add class name for UniqueConstraint
1 parent c86da84 commit cdf7591

File tree

7 files changed

+18
-11
lines changed

7 files changed

+18
-11
lines changed

src/Maker/MakeUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
162162

163163
$manipulator->setIo($io);
164164

165-
$this->userClassBuilder->addUserInterfaceImplementation($manipulator, $userClassConfiguration);
165+
$this->userClassBuilder->addUserInterfaceImplementation($manipulator, $userClassConfiguration, $userClassNameDetails->getShortName());
166166

167167
$generator->dumpFile($classPath, $manipulator->getSourceCode());
168168

src/Security/UserClassBuilder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
*/
2727
final class UserClassBuilder
2828
{
29-
public function addUserInterfaceImplementation(ClassSourceManipulator $manipulator, UserClassConfiguration $userClassConfig): void
29+
public function addUserInterfaceImplementation(ClassSourceManipulator $manipulator, UserClassConfiguration $userClassConfig, string $className): void
3030
{
3131
$manipulator->addInterface(UserInterface::class);
3232

33-
$this->addUniqueConstraint($manipulator, $userClassConfig);
33+
$this->addUniqueConstraint($manipulator, $userClassConfig, $className);
3434

3535
$this->addGetUsername($manipulator, $userClassConfig);
3636

@@ -332,7 +332,7 @@ private function addSerialize(ClassSourceManipulator $manipulator): void
332332
$manipulator->addMethodBuilder($builder);
333333
}
334334

335-
private function addUniqueConstraint(ClassSourceManipulator $manipulator, UserClassConfiguration $userClassConfig): void
335+
private function addUniqueConstraint(ClassSourceManipulator $manipulator, UserClassConfiguration $userClassConfig, string $className): void
336336
{
337337
if (!$userClassConfig->isEntity()) {
338338
return;
@@ -341,7 +341,7 @@ private function addUniqueConstraint(ClassSourceManipulator $manipulator, UserCl
341341
$manipulator->addAttributeToClass(
342342
'ORM\\UniqueConstraint',
343343
[
344-
'name' => 'UNIQ_IDENTIFIER_'.strtoupper(Str::asSnakeCase($userClassConfig->getIdentityPropertyName())),
344+
'name' => strtoupper(Str::asSnakeCase($className)).'_UNIQ_IDENTIFIER_'.strtoupper(Str::asSnakeCase($userClassConfig->getIdentityPropertyName())),
345345
'fields' => [$userClassConfig->getIdentityPropertyName()],
346346
]
347347
);

tests/Security/UserClassBuilderTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class UserClassBuilderTest extends TestCase
2323
/**
2424
* @dataProvider getUserInterfaceTests
2525
*/
26-
public function testAddUserInterfaceImplementation(UserClassConfiguration $userClassConfig, string $expectedFilename): void
26+
public function testAddUserInterfaceImplementation(UserClassConfiguration $userClassConfig, string $expectedFilename, string $className): void
2727
{
2828
$manipulator = $this->getClassSourceManipulator($userClassConfig);
2929

3030
$classBuilder = new UserClassBuilder();
31-
$classBuilder->addUserInterfaceImplementation($manipulator, $userClassConfig);
31+
$classBuilder->addUserInterfaceImplementation($manipulator, $userClassConfig, $className);
3232

3333
$expectedPath = $this->getExpectedPath($expectedFilename, null);
3434
$expectedSource = file_get_contents($expectedPath);
@@ -49,36 +49,43 @@ public function getUserInterfaceTests(): \Generator
4949
yield 'entity_with_email_as_identifier' => [
5050
new UserClassConfiguration(true, 'email', true),
5151
'UserEntityWithEmailAsIdentifier.php',
52+
'User',
5253
];
5354

5455
yield 'entity_with_password' => [
5556
new UserClassConfiguration(true, 'userIdentifier', true),
5657
'UserEntityWithPassword.php',
58+
'User',
5759
];
5860

5961
yield 'entity_with_user_identifier_as_identifier' => [
6062
new UserClassConfiguration(true, 'user_identifier', true),
6163
'UserEntityWithUser_IdentifierAsIdentifier.php',
64+
'User',
6265
];
6366

6467
yield 'entity_without_password' => [
6568
new UserClassConfiguration(true, 'userIdentifier', false),
6669
'UserEntityWithoutPassword.php',
70+
'User',
6771
];
6872

6973
yield 'model_with_email_as_identifier' => [
7074
new UserClassConfiguration(false, 'email', true),
7175
'UserModelWithEmailAsIdentifier.php',
76+
'User',
7277
];
7378

7479
yield 'model_with_password' => [
7580
new UserClassConfiguration(false, 'userIdentifier', true),
7681
'UserModelWithPassword.php',
82+
'User',
7783
];
7884

7985
yield 'model_without_password' => [
8086
new UserClassConfiguration(false, 'userIdentifier', false),
8187
'UserModelWithoutPassword.php',
88+
'User',
8289
];
8390
}
8491

tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Symfony\Component\Security\Core\User\UserInterface;
88

99
#[ORM\Entity]
10-
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
10+
#[ORM\UniqueConstraint(name: 'USER_UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
1111
class User implements UserInterface, PasswordAuthenticatedUserInterface
1212
{
1313
#[ORM\Id]

tests/Security/fixtures/expected/UserEntityWithPassword.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Symfony\Component\Security\Core\User\UserInterface;
88

99
#[ORM\Entity]
10-
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_USER_IDENTIFIER', fields: ['userIdentifier'])]
10+
#[ORM\UniqueConstraint(name: 'USER_UNIQ_IDENTIFIER_USER_IDENTIFIER', fields: ['userIdentifier'])]
1111
class User implements UserInterface, PasswordAuthenticatedUserInterface
1212
{
1313
#[ORM\Id]

tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Symfony\Component\Security\Core\User\UserInterface;
88

99
#[ORM\Entity]
10-
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_USER_IDENTIFIER', fields: ['user_identifier'])]
10+
#[ORM\UniqueConstraint(name: 'USER_UNIQ_IDENTIFIER_USER_IDENTIFIER', fields: ['user_identifier'])]
1111
class User implements UserInterface, PasswordAuthenticatedUserInterface
1212
{
1313
#[ORM\Id]

tests/Security/fixtures/expected/UserEntityWithoutPassword.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Symfony\Component\Security\Core\User\UserInterface;
77

88
#[ORM\Entity]
9-
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_USER_IDENTIFIER', fields: ['userIdentifier'])]
9+
#[ORM\UniqueConstraint(name: 'USER_UNIQ_IDENTIFIER_USER_IDENTIFIER', fields: ['userIdentifier'])]
1010
class User implements UserInterface
1111
{
1212
#[ORM\Id]

0 commit comments

Comments
 (0)