Skip to content

Commit 04f1fdf

Browse files
committed
Fix InteractiveSecurityHelper constructor calls
1 parent 543a1cb commit 04f1fdf

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

config/makers.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<argument type="service" id="maker.file_manager" />
8484
<argument type="service" id="maker.renderer.form_type_renderer" />
8585
<argument type="service" id="maker.doctrine_helper" />
86+
<argument type="service" id="maker.namespaces_helper" />
8687
<argument type="service" id="router" on-invalid="ignore" />
8788
<tag name="maker.command" />
8889
</service>
@@ -160,6 +161,7 @@
160161
<argument type="service" id="maker.file_manager" />
161162
<argument type="service" id="maker.security_config_updater" />
162163
<argument type="service" id="maker.security_controller_builder" />
164+
<argument type="service" id="maker.namespaces_helper" />
163165
<tag name="maker.command" />
164166
</service>
165167

src/Maker/MakeAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function ($answer) {
151151
);
152152
$input->setArgument('authenticator-class', $io->askQuestion($questionAuthenticatorClass));
153153

154-
$interactiveSecurityHelper = new InteractiveSecurityHelper();
154+
$interactiveSecurityHelper = new InteractiveSecurityHelper($this->generator->getNamespacesHelper());
155155
$command->addOption('firewall-name', null, InputOption::VALUE_OPTIONAL);
156156
$input->setOption('firewall-name', $interactiveSecurityHelper->guessFirewallName($io, $securityData));
157157

src/Maker/MakeRegistrationForm.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use Symfony\Bundle\MakerBundle\Util\ClassNameDetails;
3838
use Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator;
3939
use Symfony\Bundle\MakerBundle\Util\CliOutputHelper;
40+
use Symfony\Bundle\MakerBundle\Util\NamespacesHelper;
4041
use Symfony\Bundle\MakerBundle\Util\UseStatementGenerator;
4142
use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator;
4243
use Symfony\Bundle\MakerBundle\Validator;
@@ -91,6 +92,7 @@ public function __construct(
9192
private FileManager $fileManager,
9293
private FormTypeRenderer $formTypeRenderer,
9394
private DoctrineHelper $doctrineHelper,
95+
private NamespacesHelper $namespacesHelper,
9496
private ?RouterInterface $router = null,
9597
) {
9698
}
@@ -116,7 +118,7 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
116118

117119
public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void
118120
{
119-
$interactiveSecurityHelper = new InteractiveSecurityHelper();
121+
$interactiveSecurityHelper = new InteractiveSecurityHelper($this->namespacesHelper);
120122

121123
if (null === $this->router) {
122124
throw new RuntimeCommandException('Router have been explicitly disabled in your configuration. This command needs to use the router.');

src/Maker/Security/MakeFormLogin.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Symfony\Bundle\MakerBundle\Security\SecurityControllerBuilder;
3030
use Symfony\Bundle\MakerBundle\Str;
3131
use Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator;
32+
use Symfony\Bundle\MakerBundle\Util\NamespacesHelper;
3233
use Symfony\Bundle\MakerBundle\Util\UseStatementGenerator;
3334
use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator;
3435
use Symfony\Bundle\MakerBundle\Validator;
@@ -67,6 +68,7 @@ public function __construct(
6768
private FileManager $fileManager,
6869
private SecurityConfigUpdater $securityConfigUpdater,
6970
private SecurityControllerBuilder $securityControllerBuilder,
71+
private NamespacesHelper $namespacesHelper,
7072
) {
7173
}
7274

@@ -126,7 +128,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
126128
Validator::validateClassName(...)
127129
);
128130

129-
$securityHelper = new InteractiveSecurityHelper();
131+
$securityHelper = new InteractiveSecurityHelper($this->namespacesHelper);
130132
$this->firewallToUpdate = $securityHelper->guessFirewallName($io, $securityData);
131133
$this->userClass = $securityHelper->guessUserClass($io, $securityData['security']['providers']);
132134
$this->userNameField = $securityHelper->guessUserNameField($io, $this->userClass, $securityData['security']['providers']);

tests/Security/InteractiveSecurityHelperTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\MakerBundle\Security\InteractiveSecurityHelper;
1616
use Symfony\Bundle\MakerBundle\Security\Model\Authenticator;
1717
use Symfony\Bundle\MakerBundle\Security\Model\AuthenticatorType;
18+
use Symfony\Bundle\MakerBundle\Util\NamespacesHelper;
1819
use Symfony\Component\Console\Style\SymfonyStyle;
1920

2021
class InteractiveSecurityHelperTest extends TestCase
@@ -30,7 +31,7 @@ public function testGuessFirewallName(array $securityData, string $expectedFirew
3031
->method('choice')
3132
->willReturn($expectedFirewallName);
3233

33-
$helper = new InteractiveSecurityHelper();
34+
$helper = new InteractiveSecurityHelper(new NamespacesHelper());
3435
$this->assertEquals(
3536
$expectedFirewallName,
3637
$helper->guessFirewallName($io, $securityData)
@@ -88,7 +89,7 @@ public function testGuessUserClass(array $securityData, string $expectedUserClas
8889
->method('ask')
8990
->willReturn($expectedUserClass);
9091

91-
$helper = new InteractiveSecurityHelper();
92+
$helper = new InteractiveSecurityHelper(new NamespacesHelper());
9293
$this->assertEquals(
9394
$expectedUserClass,
9495
$helper->guessUserClass($io, $securityData)
@@ -128,7 +129,7 @@ public function testGuessUserNameField(array $providers, string $expectedUsernam
128129
->with(\sprintf('Which field on your <fg=yellow>%s</> class will people enter when logging in?', $class), $choices, 'username')
129130
->willReturn($expectedUsernameField);
130131

131-
$interactiveSecurityHelper = new InteractiveSecurityHelper();
132+
$interactiveSecurityHelper = new InteractiveSecurityHelper(new NamespacesHelper());
132133
$this->assertEquals(
133134
$expectedUsernameField,
134135
$interactiveSecurityHelper->guessUserNameField($io, $class, $providers)
@@ -185,7 +186,7 @@ public function testGuessEmailField(string $expectedEmailField, bool $fieldAutom
185186
->with(\sprintf('Which field on your <fg=yellow>%s</> class holds the email address?', $class), $choices, null)
186187
->willReturn($expectedEmailField);
187188

188-
$interactiveSecurityHelper = new InteractiveSecurityHelper();
189+
$interactiveSecurityHelper = new InteractiveSecurityHelper(new NamespacesHelper());
189190
$this->assertEquals(
190191
$expectedEmailField,
191192
$interactiveSecurityHelper->guessEmailField($io, $class)
@@ -211,7 +212,7 @@ public function guessEmailFieldTest()
211212
/** @dataProvider authenticatorClassProvider */
212213
public function testGetAuthenticatorsFromConfig(array $firewalls, array $expectedResults): void
213214
{
214-
$helper = new InteractiveSecurityHelper();
215+
$helper = new InteractiveSecurityHelper(new NamespacesHelper());
215216
$result = $helper->getAuthenticatorsFromConfig($firewalls);
216217

217218
self::assertEquals($expectedResults, $result);
@@ -287,7 +288,7 @@ public function testGuessPasswordSetter(string $expectedPasswordSetter, bool $au
287288
->with(\sprintf('Which method on your <fg=yellow>%s</> class can be used to set the encoded password (e.g. setPassword())?', $class), $choices, null)
288289
->willReturn($expectedPasswordSetter);
289290

290-
$interactiveSecurityHelper = new InteractiveSecurityHelper();
291+
$interactiveSecurityHelper = new InteractiveSecurityHelper(new NamespacesHelper());
291292
$this->assertEquals(
292293
$expectedPasswordSetter,
293294
$interactiveSecurityHelper->guessPasswordSetter($io, $class)
@@ -322,7 +323,7 @@ public function testGuessEmailGetter(string $expectedEmailGetter, string $emailA
322323
->with(\sprintf('Which method on your <fg=yellow>%s</> class can be used to get the email address (e.g. getEmail())?', $class), $choices, null)
323324
->willReturn($expectedEmailGetter);
324325

325-
$interactiveSecurityHelper = new InteractiveSecurityHelper();
326+
$interactiveSecurityHelper = new InteractiveSecurityHelper(new NamespacesHelper());
326327
$this->assertEquals(
327328
$expectedEmailGetter,
328329
$interactiveSecurityHelper->guessEmailGetter($io, $class, $emailAttribute)

0 commit comments

Comments
 (0)