Skip to content

Commit d6eb1d8

Browse files
authored
[make:controller] drop annotation support (#1264)
1 parent ff78148 commit d6eb1d8

File tree

5 files changed

+23
-41
lines changed

5 files changed

+23
-41
lines changed

src/Maker/MakeController.php

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

1212
namespace Symfony\Bundle\MakerBundle\Maker;
1313

14-
use Doctrine\Common\Annotations\Annotation;
1514
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1615
use Symfony\Bundle\MakerBundle\ConsoleStyle;
1716
use Symfony\Bundle\MakerBundle\DependencyBuilder;
@@ -27,7 +26,6 @@
2726
use Symfony\Component\Console\Input\InputOption;
2827
use Symfony\Component\HttpFoundation\JsonResponse;
2928
use Symfony\Component\HttpFoundation\Response;
30-
use Symfony\Component\HttpKernel\Kernel;
3129
use Symfony\Component\Routing\Annotation\Route;
3230

3331
/**
@@ -115,15 +113,6 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
115113

116114
public function configureDependencies(DependencyBuilder $dependencies): void
117115
{
118-
// @legacy - Remove method when support for Symfony 5.4 is dropped
119-
if (null !== $this->phpCompatUtil && 60000 <= Kernel::VERSION_ID) {
120-
return;
121-
}
122-
123-
$dependencies->addClassDependency(
124-
Annotation::class,
125-
'doctrine/annotations'
126-
);
127116
}
128117

129118
private function isTwigInstalled(): bool

tests/Maker/MakeAuthenticatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private function runLoginTest(MakerTestRunner $runner, string $userIdentifier, b
284284

285285
// @legacy - In 5.4 tests, we need to tell Symfony to look for route attributes in `src/Controller`
286286
if ('60000' > $runner->getSymfonyVersion()) {
287-
$runner->copy('make-auth/annotations.yaml', 'config/routes/annotations.yaml');
287+
$runner->copy('router-annotations.yaml', 'config/routes/annotations.yaml');
288288
}
289289

290290
// plaintext password: needed for entities, simplifies overall

tests/Maker/MakeControllerTest.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Bundle\MakerBundle\Maker\MakeController;
1515
use Symfony\Bundle\MakerBundle\Test\MakerTestCase;
16-
use Symfony\Bundle\MakerBundle\Test\MakerTestDetails;
1716
use Symfony\Bundle\MakerBundle\Test\MakerTestRunner;
1817

1918
class MakeControllerTest extends MakerTestCase
@@ -23,23 +22,9 @@ protected function getMakerClass(): string
2322
return MakeController::class;
2423
}
2524

26-
// @legacy Remove when Symfony 5.4 is no longer supported
27-
private function getControllerTest(): MakerTestDetails
28-
{
29-
return $this
30-
->createMakerTest()
31-
->preRun(function (MakerTestRunner $runner) {
32-
if ($runner->getSymfonyVersion() < 60000) {
33-
// Because MakeController::configureDependencies() is executed in the main thread,
34-
// we need to manually add in `doctrine/annotations` for Symfony 5.4 tests.
35-
$runner->runProcess('composer require doctrine/annotations');
36-
}
37-
});
38-
}
39-
4025
public function getTestDetails(): \Generator
4126
{
42-
yield 'it_generates_a_controller' => [$this->getControllerTest()
27+
yield 'it_generates_a_controller' => [$this->createMakerTest()
4328
->run(function (MakerTestRunner $runner) {
4429
$output = $runner->runMaker([
4530
// controller class name
@@ -52,7 +37,7 @@ public function getTestDetails(): \Generator
5237
}),
5338
];
5439

55-
yield 'it_generates_a_controller_with_twig' => [$this->getControllerTest()
40+
yield 'it_generates_a_controller_with_twig' => [$this->createMakerTest()
5641
->addExtraDependencies('twig')
5742
->run(function (MakerTestRunner $runner) {
5843
$output = $runner->runMaker([
@@ -64,7 +49,7 @@ public function getTestDetails(): \Generator
6449
}),
6550
];
6651

67-
yield 'it_generates_a_controller_with_twig_no_base_template' => [$this->getControllerTest()
52+
yield 'it_generates_a_controller_with_twig_no_base_template' => [$this->createMakerTest()
6853
->addExtraDependencies('twig')
6954
->run(function (MakerTestRunner $runner) {
7055
$runner->deleteFile('templates/base.html.twig');
@@ -78,7 +63,7 @@ public function getTestDetails(): \Generator
7863
}),
7964
];
8065

81-
yield 'it_generates_a_controller_with_without_template' => [$this->getControllerTest()
66+
yield 'it_generates_a_controller_with_without_template' => [$this->createMakerTest()
8267
->addExtraDependencies('twig')
8368
->run(function (MakerTestRunner $runner) {
8469
$runner->deleteFile('templates/base.html.twig');
@@ -95,7 +80,7 @@ public function getTestDetails(): \Generator
9580
}),
9681
];
9782

98-
yield 'it_generates_a_controller_in_sub_namespace' => [$this->getControllerTest()
83+
yield 'it_generates_a_controller_in_sub_namespace' => [$this->createMakerTest()
9984
->run(function (MakerTestRunner $runner) {
10085
$output = $runner->runMaker([
10186
// controller class name
@@ -107,7 +92,7 @@ public function getTestDetails(): \Generator
10792
}),
10893
];
10994

110-
yield 'it_generates_a_controller_in_sub_namespace_with_template' => [$this->getControllerTest()
95+
yield 'it_generates_a_controller_in_sub_namespace_with_template' => [$this->createMakerTest()
11196
->addExtraDependencies('twig')
11297
->run(function (MakerTestRunner $runner) {
11398
$output = $runner->runMaker([
@@ -119,7 +104,7 @@ public function getTestDetails(): \Generator
119104
}),
120105
];
121106

122-
yield 'it_generates_a_controller_with_full_custom_namespace' => [$this->getControllerTest()
107+
yield 'it_generates_a_controller_with_full_custom_namespace' => [$this->createMakerTest()
123108
->addExtraDependencies('twig')
124109
->run(function (MakerTestRunner $runner) {
125110
$output = $runner->runMaker([
@@ -140,6 +125,11 @@ private function runControllerTest(MakerTestRunner $runner, string $filename): v
140125
'tests/GeneratedControllerTest.php'
141126
);
142127

128+
// @legacy - In 5.4 tests, we need to tell Symfony to look for route attributes in `src/Controller`
129+
if ('60000' > $runner->getSymfonyVersion()) {
130+
$runner->copy('router-annotations.yaml', 'config/routes/annotations.yaml');
131+
}
132+
143133
$runner->runTests();
144134
}
145135
}

tests/fixtures/make-auth/annotations.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# @legacy - Can be removed when Symfony 5.4 is no longer supported
2+
# This is needed for controller attributes as we do not install / require
3+
# doctrine/annotations...
4+
controllers:
5+
resource: ../../src/Controller/
6+
type: annotation
7+
8+
kernel:
9+
resource: ../../src/Kernel.php
10+
type: annotation

0 commit comments

Comments
 (0)