Skip to content

Commit e8fd1b5

Browse files
committed
feature #1010 Refactoring Tests & Various Fixes for Symfony 6 (weaverryan)
This PR was squashed before being merged into the 1.0-dev branch. Discussion ---------- Refactoring Tests & Various Fixes for Symfony 6 Hi! A big, kind of ugly change. Reasons: * We needed a bit more flexibility to tweak the workflow of individual tests for different versions of Symfony * Reduced duplication: the "fixtures" in the tests caused a lot of duplication, which has grown over time. This minimizes that quite a lot. Fixes #1009, fixes #1005, fixes #984, fixes #900 Cheers! Commits ------- ed95e27 Refactoring Tests & Various Fixes for Symfony 6
2 parents 2505831 + ed95e27 commit e8fd1b5

File tree

261 files changed

+3030
-7521
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+3030
-7521
lines changed

.github/workflows/ci.yaml

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
run: "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff"
5858

5959
test:
60-
name: "PHP ${{ matrix.php-version }} + symfony/skeleton@${{ matrix.symfony-skeleton-stability }}"
60+
name: "PHP ${{ matrix.php-version }} + @${{ matrix.symfony-version }} ${{ matrix.dependency-versions }} deps"
6161

6262
runs-on: ubuntu-18.04
6363

@@ -82,28 +82,30 @@ jobs:
8282
ports:
8383
- 1337:1337
8484

85-
continue-on-error: ${{ matrix.allow-failures }}
86-
8785
env:
88-
SYMFONY_SKELETON_STABILITY: ${{ matrix.symfony-skeleton-stability }}
86+
SYMFONY_VERSION: ${{ matrix.symfony-version }}
8987

9088
strategy:
9189
fail-fast: false
9290
matrix:
9391
php-version:
94-
- '7.1.3'
95-
- '7.2'
96-
- '7.3'
97-
- '7.4'
9892
- '8.0'
99-
symfony-skeleton-stability:
100-
- 'stable'
101-
composer-options: ['--no-suggest']
102-
allow-failures: [false]
93+
symfony-version:
94+
- '4.4.*'
95+
- '5.3.*'
96+
- '5.4.x-dev'
97+
- '6.0.x-dev'
98+
dependency-versions: ['highest']
10399
include:
104-
- php-version: '8.0'
105-
symfony-skeleton-stability: 'dev'
106-
allow-failures: true
100+
# testing lowest PHP version with LTS
101+
- php-version: '7.1.3'
102+
symfony-version: '4.4.*'
103+
# not important - does not affect each app's dependencies
104+
dependency-versions: 'highest'
105+
# testing lowest php version with highest 5.x stable
106+
- php-version: '7.2.5'
107+
symfony-version: '5.3.*'
108+
dependency-versions: 'lowest'
107109

108110
steps:
109111
- name: "Checkout code"
@@ -132,17 +134,12 @@ jobs:
132134
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
133135

134136
- name: "Require symfony/flex"
135-
if: contains('stable', env.SYMFONY_SKELETON_STABILITY)
136137
run: composer global require --no-progress --no-scripts --no-plugins symfony/flex
137138

138-
- name: "Require symfony/flex dev-main"
139-
if: contains('dev', env.SYMFONY_SKELETON_STABILITY)
140-
run: composer global require --no-progress --no-scripts --no-plugins symfony/flex dev-main
141-
142139
- name: "Composer install"
143140
uses: "ramsey/composer-install@v1"
144141
with:
145-
composer-options: "${{ matrix.composer-options }}"
142+
dependency-versions: "${{ matrix.dependency-versions }}"
146143

147144
- name: "Composer install php-cs-fixer"
148145
uses: "ramsey/composer-install@v1"

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
->exclude('fixtures')
1212
// the PHP template files are a bit special
1313
->notName('*.tpl.php')
14+
->notPath('src/Console/MigrationDiffFilteredOutput_php8.php')
1415
;
1516

1617
return (new PhpCsFixer\Config())

composer.json

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,26 @@
1616
"php": ">=7.1.3",
1717
"doctrine/inflector": "^1.2|^2.0",
1818
"nikic/php-parser": "^4.11",
19-
"symfony/config": "^4.0|^5.0|^6.0",
20-
"symfony/console": "^4.0|^5.0|^6.0",
21-
"symfony/dependency-injection": "^4.0|^5.0|^6.0",
19+
"symfony/config": "^4.4|^5.0|^6.0",
20+
"symfony/console": "^4.4|^5.0|^6.0",
21+
"symfony/dependency-injection": "^4.4|^5.0|^6.0",
2222
"symfony/deprecation-contracts": "^2.2",
23-
"symfony/filesystem": "^4.0|^5.0|^6.0",
24-
"symfony/finder": "^4.0|^5.0|^6.0",
25-
"symfony/framework-bundle": "^4.0|^5.0|^6.0",
26-
"symfony/http-kernel": "^4.0|^5.0|^6.0"
23+
"symfony/filesystem": "^4.4|^5.0|^6.0",
24+
"symfony/finder": "^4.4|^5.0|^6.0",
25+
"symfony/framework-bundle": "^4.4|^5.0|^6.0",
26+
"symfony/http-kernel": "^4.4|^5.0|^6.0"
2727
},
2828
"require-dev": {
29-
"composer/semver": "^3.0@dev",
30-
"doctrine/doctrine-bundle": "^1.8|^2.0",
29+
"composer/semver": "^3.0",
30+
"doctrine/doctrine-bundle": "^1.12.3|^2.0",
3131
"doctrine/orm": "^2.3",
32-
"symfony/http-client": "^4.3|^5.0|^6.0",
33-
"symfony/phpunit-bridge": "^4.3|^5.0|^6.0",
34-
"symfony/process": "^4.0|^5.0|^6.0",
35-
"symfony/security-core": "^4.0|^5.0|^6.0",
36-
"symfony/yaml": "^4.0|^5.0|^6.0"
32+
"symfony/http-client": "^4.4|^5.0|^6.0",
33+
"symfony/phpunit-bridge": "^4.4|^5.0|^6.0",
34+
"symfony/polyfill-php80": "^1.16.0",
35+
"symfony/process": "^4.4|^5.0|^6.0",
36+
"symfony/security-core": "^4.4|^5.0|^6.0",
37+
"symfony/yaml": "^4.4|^5.0|^6.0",
38+
"twig/twig": "^2.0|^3.0"
3739
},
3840
"config": {
3941
"preferred-install": "dist",

src/Console/MigrationDiffFilteredOutput.php

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,38 @@
1414
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
1515
use Symfony\Component\Console\Output\OutputInterface;
1616

17-
class MigrationDiffFilteredOutput implements OutputInterface
17+
if (\PHP_VERSION_ID < 80000
18+
// look for the "string|iterable" type on OutputInterface::write()
19+
|| !(new \ReflectionMethod(OutputInterface::class, 'write'))->getParameters()[0]->getType()) {
20+
class MigrationDiffFilteredOutput implements OutputInterface
21+
{
22+
use BaseMakerMigrationDiffFilteredOuputTrait;
23+
24+
public function write($messages, $newline = false, $options = 0)
25+
{
26+
$this->_write($messages, $newline, $options);
27+
}
28+
29+
public function writeln($messages, $options = 0)
30+
{
31+
$this->_writeln($messages, $options);
32+
}
33+
34+
public function setVerbosity($level)
35+
{
36+
$this->output->setVerbosity($level);
37+
}
38+
39+
public function setDecorated($decorated)
40+
{
41+
$this->output->setDecorated($decorated);
42+
}
43+
}
44+
} else {
45+
require __DIR__.'/MigrationDiffFilteredOutput_php8.php';
46+
}
47+
48+
trait BaseMakerMigrationDiffFilteredOuputTrait
1849
{
1950
private $output;
2051
private $buffer = '';
@@ -25,56 +56,46 @@ public function __construct(OutputInterface $output)
2556
$this->output = $output;
2657
}
2758

28-
public function write($messages, $newline = false, $options = 0)
59+
public function _write($messages, bool $newline = false, $options = 0)
2960
{
3061
$messages = $this->filterMessages($messages, $newline);
3162

3263
$this->output->write($messages, $newline, $options);
3364
}
3465

35-
public function writeln($messages, $options = 0)
66+
public function _writeln($messages, int $options = 0)
3667
{
3768
$messages = $this->filterMessages($messages, true);
3869

3970
$this->output->writeln($messages, $options);
4071
}
4172

42-
public function setVerbosity($level)
43-
{
44-
$this->output->setVerbosity($level);
45-
}
46-
47-
public function getVerbosity()
73+
public function getVerbosity(): int
4874
{
4975
return $this->output->getVerbosity();
5076
}
5177

52-
public function isQuiet()
78+
public function isQuiet(): bool
5379
{
5480
return $this->output->isQuiet();
5581
}
5682

57-
public function isVerbose()
83+
public function isVerbose(): bool
5884
{
5985
return $this->output->isVerbose();
6086
}
6187

62-
public function isVeryVerbose()
88+
public function isVeryVerbose(): bool
6389
{
6490
return $this->output->isVeryVerbose();
6591
}
6692

67-
public function isDebug()
93+
public function isDebug(): bool
6894
{
6995
return $this->output->isDebug();
7096
}
7197

72-
public function setDecorated($decorated)
73-
{
74-
$this->output->setDecorated($decorated);
75-
}
76-
77-
public function isDecorated()
98+
public function isDecorated(): bool
7899
{
79100
return $this->output->isDecorated();
80101
}
@@ -84,7 +105,7 @@ public function setFormatter(OutputFormatterInterface $formatter)
84105
$this->output->setFormatter($formatter);
85106
}
86107

87-
public function getFormatter()
108+
public function getFormatter(): OutputFormatterInterface
88109
{
89110
return $this->output->getFormatter();
90111
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony MakerBundle package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\MakerBundle\Console;
13+
14+
use Symfony\Component\Console\Output\OutputInterface;
15+
16+
class MigrationDiffFilteredOutput implements OutputInterface
17+
{
18+
use BaseMakerMigrationDiffFilteredOuputTrait;
19+
20+
public function write($messages, bool $newline = false, $options = 0)
21+
{
22+
$this->_write($messages, $newline, $options);
23+
}
24+
25+
public function writeln($messages, int $options = 0)
26+
{
27+
$this->_writeln($messages, $options);
28+
}
29+
30+
public function setVerbosity(int $level)
31+
{
32+
$this->output->setVerbosity($level);
33+
}
34+
35+
public function setDecorated(bool $decorated)
36+
{
37+
$this->output->setDecorated($decorated);
38+
}
39+
}

src/Maker/MakeAuthenticator.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
use Symfony\Component\Form\Form;
3737
use Symfony\Component\HttpKernel\Kernel;
3838
use Symfony\Component\Security\Guard\Authenticator\AbstractFormLoginAuthenticator;
39+
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
3940
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
41+
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
4042
use Symfony\Component\Yaml\Yaml;
4143

4244
/**
@@ -264,7 +266,10 @@ private function generateAuthenticatorClass(array $securityData, string $authent
264266
$this->generator->generateClass(
265267
$authenticatorClass,
266268
sprintf('authenticator/%sEmptyAuthenticator.tpl.php', $this->useSecurity52 ? 'Security52' : ''),
267-
['provider_key_type_hint' => $this->providerKeyTypeHint()]
269+
[
270+
'provider_key_type_hint' => $this->providerKeyTypeHint(),
271+
'use_legacy_passport_interface' => $this->shouldUseLegacyPassportInterface(),
272+
]
268273
);
269274

270275
return;
@@ -287,6 +292,7 @@ private function generateAuthenticatorClass(array $securityData, string $authent
287292
'user_needs_encoder' => $this->userClassHasEncoder($securityData, $userClass),
288293
'user_is_entity' => $this->doctrineHelper->isClassAMappedEntity($userClass),
289294
'provider_key_type_hint' => $this->providerKeyTypeHint(),
295+
'use_legacy_passport_interface' => $this->shouldUseLegacyPassportInterface(),
290296
]
291297
);
292298
}
@@ -411,4 +417,23 @@ private function providerKeyTypeHint(): string
411417

412418
return sprintf('%s ', $type->getName());
413419
}
420+
421+
private function shouldUseLegacyPassportInterface(): bool
422+
{
423+
// only applies to new authenticator security
424+
if (!$this->useSecurity52) {
425+
return false;
426+
}
427+
428+
// legacy: checking for Symfony 5.2 & 5.3 before PassportInterface deprecation
429+
$class = new \ReflectionClass(AuthenticatorInterface::class);
430+
$method = $class->getMethod('authenticate');
431+
432+
// 5.4 where return type is temporarily removed
433+
if (!$method->getReturnType()) {
434+
return false;
435+
}
436+
437+
return PassportInterface::class === $method->getReturnType()->getName();
438+
}
414439
}

src/Maker/MakeRegistrationForm.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
1515
use Doctrine\Common\Annotations\Annotation;
16+
use Doctrine\ORM\EntityManagerInterface;
1617
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
1718
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
1819
use Symfony\Bundle\MakerBundle\ConsoleStyle;
@@ -47,6 +48,7 @@
4748
use Symfony\Component\Routing\RouterInterface;
4849
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
4950
use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
51+
use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;
5052
use Symfony\Component\Validator\Validation;
5153
use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface;
5254
use SymfonyCasts\Bundle\VerifyEmail\Model\VerifyEmailSignatureComponents;
@@ -78,6 +80,7 @@ final class MakeRegistrationForm extends AbstractMaker
7880
private $firewallName;
7981
private $redirectRouteName;
8082
private $addUniqueEntityConstraint;
83+
private $useNewAuthenticatorSystem = false;
8184

8285
public function __construct(FileManager $fileManager, FormTypeRenderer $formTypeRenderer, RouterInterface $router, DoctrineHelper $doctrineHelper)
8386
{
@@ -116,6 +119,11 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
116119
$securityData = $manipulator->getData();
117120
$providersData = $securityData['security']['providers'] ?? [];
118121

122+
// Determine if we should use new security features introduced in Symfony 5.2
123+
if ($securityData['security']['enable_authenticator_manager'] ?? false) {
124+
$this->useNewAuthenticatorSystem = true;
125+
}
126+
119127
$this->userClass = $interactiveSecurityHelper->guessUserClass(
120128
$io,
121129
$providersData,
@@ -292,6 +300,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
292300
Response::class,
293301
Route::class,
294302
$passwordHasher,
303+
EntityManagerInterface::class,
295304
];
296305

297306
if ($this->willVerifyEmail) {
@@ -307,7 +316,11 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
307316

308317
if ($this->autoLoginAuthenticator) {
309318
$useStatements[] = $this->autoLoginAuthenticator;
310-
$useStatements[] = GuardAuthenticatorHandler::class;
319+
if ($this->useNewAuthenticatorSystem) {
320+
$useStatements[] = UserAuthenticatorInterface::class;
321+
} else {
322+
$useStatements[] = GuardAuthenticatorHandler::class;
323+
}
311324
}
312325

313326
$generator->generateController(
@@ -328,6 +341,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
328341
'email_getter' => $this->emailGetter,
329342
'authenticator_class_name' => $this->autoLoginAuthenticator ? Str::getShortClassName($this->autoLoginAuthenticator) : null,
330343
'authenticator_full_class_name' => $this->autoLoginAuthenticator,
344+
'use_new_authenticator_system' => $this->useNewAuthenticatorSystem,
331345
'firewall_name' => $this->firewallName,
332346
'redirect_route_name' => $this->redirectRouteName,
333347
'password_hasher_class_details' => ($passwordClassDetails = $generator->createClassNameDetails($passwordHasher, '\\')),

0 commit comments

Comments
 (0)