Skip to content

Commit 0b8ed5d

Browse files
committed
[make:test*] use sorted use statements
1 parent 56aeee3 commit 0b8ed5d

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

src/Maker/MakeFunctionalTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\MakerBundle\Maker;
1313

1414
use Symfony\Bundle\FrameworkBundle\Test\WebTestAssertionsTrait;
15+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1516
use Symfony\Bundle\MakerBundle\ConsoleStyle;
1617
use Symfony\Bundle\MakerBundle\DependencyBuilder;
1718
use Symfony\Bundle\MakerBundle\Generator;
@@ -21,6 +22,7 @@
2122
use Symfony\Component\Console\Input\InputArgument;
2223
use Symfony\Component\Console\Input\InputInterface;
2324
use Symfony\Component\CssSelector\CssSelectorConverter;
25+
use Symfony\Component\Panther\PantherTestCase;
2426
use Symfony\Component\Panther\PantherTestCaseTrait;
2527

2628
trigger_deprecation('symfony/maker-bundle', '1.29', 'The "%s" class is deprecated, use "%s" instead.', MakeFunctionalTest::class, MakeTest::class);
@@ -43,28 +45,35 @@ public static function getCommandDescription(): string
4345
return 'Creates a new functional test class';
4446
}
4547

46-
public function configureCommand(Command $command, InputConfiguration $inputConf)
48+
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
4749
{
4850
$command
4951
->addArgument('name', InputArgument::OPTIONAL, 'The name of the functional test class (e.g. <fg=yellow>DefaultControllerTest</>)')
5052
->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeFunctionalTest.txt'))
5153
;
5254
}
5355

54-
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator)
56+
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
5557
{
5658
$testClassNameDetails = $generator->createClassNameDetails(
5759
$input->getArgument('name'),
5860
'Tests\\',
5961
'Test'
6062
);
6163

64+
$pantherAvailable = trait_exists(PantherTestCaseTrait::class);
65+
66+
$this->useStatements = [
67+
($pantherAvailable ? PantherTestCase::class : WebTestCase::class),
68+
];
69+
6270
$generator->generateClass(
6371
$testClassNameDetails->getFullName(),
6472
'test/Functional.tpl.php',
6573
[
74+
'use_statements' => $this->getFormattedUseStatements(),
6675
'web_assertions_are_available' => trait_exists(WebTestAssertionsTrait::class),
67-
'panther_is_available' => trait_exists(PantherTestCaseTrait::class),
76+
'panther_is_available' => $pantherAvailable,
6877
]
6978
);
7079

@@ -78,7 +87,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
7887
]);
7988
}
8089

81-
public function configureDependencies(DependencyBuilder $dependencies)
90+
public function configureDependencies(DependencyBuilder $dependencies): void
8291
{
8392
$dependencies->addClassDependency(
8493
History::class,

src/Maker/MakeTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static function getCommandDescription(): string
7070
return 'Creates a new test class';
7171
}
7272

73-
public function configureCommand(Command $command, InputConfiguration $inputConf)
73+
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
7474
{
7575
$typesDesc = [];
7676
$typesHelp = [];
@@ -84,11 +84,11 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
8484
->addArgument('name', InputArgument::OPTIONAL, 'The name of the test class (e.g. <fg=yellow>BlogPostTest</>)')
8585
->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeTest.txt').implode("\n", $typesHelp));
8686

87-
$inputConf->setArgumentAsNonInteractive('name');
88-
$inputConf->setArgumentAsNonInteractive('type');
87+
$inputConfig->setArgumentAsNonInteractive('name');
88+
$inputConfig->setArgumentAsNonInteractive('type');
8989
}
9090

91-
public function interact(InputInterface $input, ConsoleStyle $io, Command $command)
91+
public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void
9292
{
9393
/* @deprecated remove the following block when removing make:unit-test and make:functional-test */
9494
$this->handleDeprecatedMakerCommands($input, $io);
@@ -133,7 +133,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
133133
}
134134
}
135135

136-
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator)
136+
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
137137
{
138138
$testClassNameDetails = $generator->createClassNameDetails(
139139
$input->getArgument('name'),

src/Maker/MakeUnitTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\MakerBundle\Maker;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Bundle\MakerBundle\ConsoleStyle;
1516
use Symfony\Bundle\MakerBundle\DependencyBuilder;
1617
use Symfony\Bundle\MakerBundle\Generator;
@@ -39,26 +40,28 @@ public static function getCommandDescription(): string
3940
return 'Creates a new unit test class';
4041
}
4142

42-
public function configureCommand(Command $command, InputConfiguration $inputConf)
43+
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
4344
{
4445
$command
4546
->addArgument('name', InputArgument::OPTIONAL, 'The name of the unit test class (e.g. <fg=yellow>UtilTest</>)')
4647
->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeUnitTest.txt'))
4748
;
4849
}
4950

50-
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator)
51+
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
5152
{
5253
$testClassNameDetails = $generator->createClassNameDetails(
5354
$input->getArgument('name'),
5455
'Tests\\',
5556
'Test'
5657
);
5758

59+
$this->useStatements = [TestCase::class];
60+
5861
$generator->generateClass(
5962
$testClassNameDetails->getFullName(),
6063
'test/Unit.tpl.php',
61-
[]
64+
['use_statements' => $this->getFormattedUseStatements()]
6265
);
6366

6467
$generator->writeChanges();
@@ -71,7 +74,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
7174
]);
7275
}
7376

74-
public function configureDependencies(DependencyBuilder $dependencies)
77+
public function configureDependencies(DependencyBuilder $dependencies): void
7578
{
7679
}
7780
}

src/Resources/skeleton/test/Functional.tpl.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33

44
namespace <?= $namespace; ?>;
55

6-
<?php if ($panther_is_available): ?>
7-
use Symfony\Component\Panther\PantherTestCase;
8-
<?php else: ?>
9-
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
10-
<?php endif ?>
6+
<?= $use_statements ?>
117

128
class <?= $class_name ?> extends <?= $panther_is_available ? 'PantherTestCase' : 'WebTestCase' ?><?= "\n" ?>
139
{

src/Resources/skeleton/test/Unit.tpl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace <?= $namespace; ?>;
55

6-
use PHPUnit\Framework\TestCase;
6+
<?= $use_statements; ?>
77

88
class <?= $class_name ?> extends TestCase
99
{

0 commit comments

Comments
 (0)