Skip to content

[make:controller] doctrine/annotations is not needed #1264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/Maker/MakeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Bundle\MakerBundle\Maker;

use Doctrine\Common\Annotations\Annotation;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
Expand All @@ -27,7 +26,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Annotation\Route;

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

public function configureDependencies(DependencyBuilder $dependencies): void
{
// @legacy - Remove method when support for Symfony 5.4 is dropped
if (null !== $this->phpCompatUtil && 60000 <= Kernel::VERSION_ID) {
return;
}

$dependencies->addClassDependency(
Annotation::class,
'doctrine/annotations'
);
}

private function isTwigInstalled(): bool
Expand Down
2 changes: 1 addition & 1 deletion tests/Maker/MakeAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private function runLoginTest(MakerTestRunner $runner, string $userIdentifier, b

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

// plaintext password: needed for entities, simplifies overall
Expand Down
34 changes: 12 additions & 22 deletions tests/Maker/MakeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Bundle\MakerBundle\Maker\MakeController;
use Symfony\Bundle\MakerBundle\Test\MakerTestCase;
use Symfony\Bundle\MakerBundle\Test\MakerTestDetails;
use Symfony\Bundle\MakerBundle\Test\MakerTestRunner;

class MakeControllerTest extends MakerTestCase
Expand All @@ -23,23 +22,9 @@ protected function getMakerClass(): string
return MakeController::class;
}

// @legacy Remove when Symfony 5.4 is no longer supported
private function getControllerTest(): MakerTestDetails
{
return $this
->createMakerTest()
->preRun(function (MakerTestRunner $runner) {
if ($runner->getSymfonyVersion() < 60000) {
// Because MakeController::configureDependencies() is executed in the main thread,
// we need to manually add in `doctrine/annotations` for Symfony 5.4 tests.
$runner->runProcess('composer require doctrine/annotations');
}
});
}

public function getTestDetails(): \Generator
{
yield 'it_generates_a_controller' => [$this->getControllerTest()
yield 'it_generates_a_controller' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
$output = $runner->runMaker([
// controller class name
Expand All @@ -52,7 +37,7 @@ public function getTestDetails(): \Generator
}),
];

yield 'it_generates_a_controller_with_twig' => [$this->getControllerTest()
yield 'it_generates_a_controller_with_twig' => [$this->createMakerTest()
->addExtraDependencies('twig')
->run(function (MakerTestRunner $runner) {
$output = $runner->runMaker([
Expand All @@ -64,7 +49,7 @@ public function getTestDetails(): \Generator
}),
];

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

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

yield 'it_generates_a_controller_in_sub_namespace' => [$this->getControllerTest()
yield 'it_generates_a_controller_in_sub_namespace' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
$output = $runner->runMaker([
// controller class name
Expand All @@ -107,7 +92,7 @@ public function getTestDetails(): \Generator
}),
];

yield 'it_generates_a_controller_in_sub_namespace_with_template' => [$this->getControllerTest()
yield 'it_generates_a_controller_in_sub_namespace_with_template' => [$this->createMakerTest()
->addExtraDependencies('twig')
->run(function (MakerTestRunner $runner) {
$output = $runner->runMaker([
Expand All @@ -119,7 +104,7 @@ public function getTestDetails(): \Generator
}),
];

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

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

$runner->runTests();
}
}
7 changes: 0 additions & 7 deletions tests/fixtures/make-auth/annotations.yaml

This file was deleted.

10 changes: 10 additions & 0 deletions tests/fixtures/router-annotations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# @legacy - Can be removed when Symfony 5.4 is no longer supported
# This is needed for controller attributes as we do not install / require
# doctrine/annotations...
controllers:
resource: ../../src/Controller/
type: annotation

kernel:
resource: ../../src/Kernel.php
type: annotation