Skip to content

Commit 3dcf845

Browse files
committed
feature #1006 allow symfony6 (tacman, weaverryan)
This PR was merged into the 1.0-dev branch. Discussion ---------- allow symfony6 Commits ------- 46d038b Moving php-cs-fixer & twigcs to an independent dependency d12d2de allow symfony6
2 parents 08b370e + 46d038b commit 3dcf845

26 files changed

+831
-186
lines changed

.github/workflows/ci.yaml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,15 @@ jobs:
4646
with:
4747
composer-options: "--no-scripts"
4848

49+
-
50+
name: "Composer install php-cs-fixer"
51+
uses: "ramsey/composer-install@v1"
52+
with:
53+
composer-options: "--no-scripts --working-dir=tools/php-cs-fixer"
54+
4955
-
5056
name: "Run friendsofphp/php-cs-fixer"
51-
run: "vendor/bin/php-cs-fixer fix --dry-run --diff"
57+
run: "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff"
5258

5359
test:
5460
name: "PHP ${{ matrix.php-version }} + symfony/skeleton@${{ matrix.symfony-skeleton-stability }}"
@@ -89,14 +95,12 @@ jobs:
8995
- '7.2'
9096
- '7.3'
9197
- '7.4'
98+
- '8.0'
9299
symfony-skeleton-stability:
93100
- 'stable'
94101
composer-options: ['--no-suggest']
95102
allow-failures: [false]
96103
include:
97-
- php-version: '7.4'
98-
symfony-skeleton-stability: 'dev'
99-
allow-failures: true
100104
- php-version: '8.0'
101105
symfony-skeleton-stability: 'dev'
102106
allow-failures: true
@@ -140,6 +144,16 @@ jobs:
140144
with:
141145
composer-options: "${{ matrix.composer-options }}"
142146

147+
- name: "Composer install php-cs-fixer"
148+
uses: "ramsey/composer-install@v1"
149+
with:
150+
composer-options: "--no-scripts --working-dir=tools/php-cs-fixer"
151+
152+
- name: "Composer install twigcs"
153+
uses: "ramsey/composer-install@v1"
154+
with:
155+
composer-options: "--no-scripts --working-dir=tools/twigcs"
156+
143157
- name: "Install PHPUnit"
144158
run: vendor/bin/simple-phpunit install
145159

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
/vendor/
44
/tests/tmp/*
55
/.php-cs-fixer.cache
6+
/tools/*/vendor
7+
/tools/*/composer.lock
68
/.phpunit.result.cache

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ install:
5555
- cd C:\projects\maker-bundle
5656
- composer global require --no-progress --no-scripts --no-plugins symfony/flex
5757
- IF %dependencies%==highest appveyor-retry composer update --no-progress --no-suggest --ansi
58+
- composer install --no-interaction --no-progress --ansi --no-scripts --working-dir=tools/twigcs
59+
- composer install --no-interaction --no-progress --ansi --no-scripts --working-dir=tools/php-cs-fixer
5860
- vendor/bin/simple-phpunit install
5961

6062
test_script:

composer.json

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,24 @@
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",
20-
"symfony/console": "^4.0|^5.0",
21-
"symfony/dependency-injection": "^4.0|^5.0",
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",
2222
"symfony/deprecation-contracts": "^2.2",
23-
"symfony/filesystem": "^4.0|^5.0",
24-
"symfony/finder": "^4.0|^5.0",
25-
"symfony/framework-bundle": "^4.0|^5.0",
26-
"symfony/http-kernel": "^4.0|^5.0"
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"
2727
},
2828
"require-dev": {
2929
"composer/semver": "^3.0@dev",
3030
"doctrine/doctrine-bundle": "^1.8|^2.0",
3131
"doctrine/orm": "^2.3",
32-
"friendsofphp/php-cs-fixer": "^3.0",
33-
"friendsoftwig/twigcs": "^4.1.0|^5.0.0",
34-
"symfony/http-client": "^4.3|^5.0",
35-
"symfony/phpunit-bridge": "^4.3|^5.0",
36-
"symfony/process": "^4.0|^5.0",
37-
"symfony/security-core": "^4.0|^5.0",
38-
"symfony/yaml": "^4.0|^5.0"
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"
3937
},
4038
"config": {
4139
"preferred-install": "dist",

src/Security/UserClassBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ private function addGetUsername(ClassSourceManipulator $manipulator, UserClassCo
100100

101101
// Check if we're using Symfony 5.3+ - UserInterface::getUsername() was replaced with UserInterface::getUserIdentifier()
102102
$symfony53GTE = class_exists(InMemoryUser::class);
103+
$symfony6GTE = !method_exists(UserInterface::class, 'getSalt');
103104
$getterIdentifierName = $symfony53GTE ? 'getUserIdentifier' : 'getUsername';
104105

105106
// define getUsername (if it was defined above, this will override)
@@ -116,7 +117,7 @@ private function addGetUsername(ClassSourceManipulator $manipulator, UserClassCo
116117
true
117118
);
118119

119-
if ($symfony53GTE) {
120+
if ($symfony53GTE && !$symfony6GTE) {
120121
// also add the deprecated getUsername method
121122
$manipulator->addAccessorMethod(
122123
$userClassConfig->getIdentityPropertyName(),

src/Test/MakerTestEnvironment.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,21 @@ public function fileExists(string $file): bool
266266

267267
public function runPhpCSFixer(string $file): MakerTestProcess
268268
{
269-
return MakerTestProcess::create(sprintf('php vendor/bin/php-cs-fixer --config=%s fix --dry-run --diff %s', __DIR__.'/../Resources/test/.php_cs.test', $this->path.'/'.$file), $this->rootPath)
269+
if (!file_exists(__DIR__.'/../../tools/php-cs-fixer/vendor/bin/php-cs-fixer')) {
270+
throw new \Exception('php-cs-fixer not found: run: "composer install --working-dir=tools/php-cs-fixer".');
271+
}
272+
273+
return MakerTestProcess::create(sprintf('php tools/php-cs-fixer/vendor/bin/php-cs-fixer --config=%s fix --dry-run --diff %s', __DIR__.'/../Resources/test/.php_cs.test', $this->path.'/'.$file), $this->rootPath)
270274
->run(true);
271275
}
272276

273277
public function runTwigCSLint(string $file): MakerTestProcess
274278
{
275-
return MakerTestProcess::create(sprintf('php vendor/bin/twigcs --config ./.twig_cs.dist %s', $this->path.'/'.$file), $this->rootPath)
279+
if (!file_exists(__DIR__.'/../../tools/twigcs/vendor/bin/twigcs')) {
280+
throw new \Exception('twigcs not found: run: "composer install --working-dir=tools/twigcs".');
281+
}
282+
283+
return MakerTestProcess::create(sprintf('php tools/twigcs/vendor/bin/twigcs --config ./tools/twigcs/.twig_cs.dist %s', $this->path.'/'.$file), $this->rootPath)
276284
->run(true);
277285
}
278286

src/Test/MakerTestKernel.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Symfony\Component\DependencyInjection\ContainerBuilder;
2121
use Symfony\Component\HttpKernel\Kernel;
2222
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
23-
use Symfony\Component\Routing\RouteCollectionBuilder;
2423

2524
class MakerTestKernel extends Kernel implements CompilerPassInterface
2625
{
@@ -35,15 +34,15 @@ public function __construct(string $environment, bool $debug)
3534
parent::__construct($environment, $debug);
3635
}
3736

38-
public function registerBundles()
37+
public function registerBundles(): iterable
3938
{
4039
return [
4140
new FrameworkBundle(),
4241
new MakerBundle(),
4342
];
4443
}
4544

46-
protected function configureRoutes(RouteCollectionBuilder $routes)
45+
protected function configureRoutes(RoutingConfigurator $routes)
4746
{
4847
}
4948

@@ -61,12 +60,12 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
6160
]);
6261
}
6362

64-
public function getProjectDir()
63+
public function getProjectDir(): string
6564
{
6665
return $this->getRootDir();
6766
}
6867

69-
public function getRootDir()
68+
public function getRootDir(): string
7069
{
7170
return $this->testRootDir;
7271
}

tests/Security/UserClassBuilderTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
use Symfony\Bundle\MakerBundle\Security\UserClassBuilder;
1616
use Symfony\Bundle\MakerBundle\Security\UserClassConfiguration;
1717
use Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator;
18+
use Symfony\Component\Security\Core\User\InMemoryUser;
1819
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
19-
use Symfony\Component\Security\Core\User\User;
20+
use Symfony\Component\Security\Core\User\UserInterface;
2021

2122
class UserClassBuilderTest extends TestCase
2223
{
@@ -34,9 +35,11 @@ public function testAddUserInterfaceImplementation(UserClassConfiguration $userC
3435
$classBuilder = new UserClassBuilder();
3536
$classBuilder->addUserInterfaceImplementation($manipulator, $userClassConfig);
3637

37-
$expectedPath = $this->getExpectedPath($expectedFilename);
38+
$isSymfony5 = method_exists(UserInterface::class, 'getSalt');
39+
$expectedPath = $this->getExpectedPath($expectedFilename, $isSymfony5 ? 'legacy_5_user_class' : null);
40+
$expectedSource = file_get_contents($expectedPath);
3841

39-
self::assertStringEqualsFile($expectedPath, $manipulator->getSourceCode());
42+
self::assertSame($expectedSource, $manipulator->getSourceCode());
4043
}
4144

4245
public function getUserInterfaceTests(): \Generator
@@ -86,7 +89,7 @@ public function getUserInterfaceTests(): \Generator
8689
*/
8790
public function testLegacyUserInterfaceGetUsername(UserClassConfiguration $userClassConfig, string $expectedFilename): void
8891
{
89-
if (method_exists(User::class, 'getUserIdentifier')) {
92+
if (method_exists(InMemoryUser::class, 'getUserIdentifier')) {
9093
self::markTestSkipped();
9194
}
9295

tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ public function getUserIdentifier(): string
6161
return (string) $this->email;
6262
}
6363

64-
/**
65-
* @deprecated since Symfony 5.3, use getUserIdentifier instead
66-
*/
67-
public function getUsername(): string
68-
{
69-
return (string) $this->email;
70-
}
71-
7264
/**
7365
* @see UserInterface
7466
*/
@@ -103,17 +95,6 @@ public function setPassword(string $password): self
10395
return $this;
10496
}
10597

106-
/**
107-
* Returning a salt is only needed, if you are not using a modern
108-
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
109-
*
110-
* @see UserInterface
111-
*/
112-
public function getSalt(): ?string
113-
{
114-
return null;
115-
}
116-
11798
/**
11899
* @see UserInterface
119100
*/

tests/Security/fixtures/expected/UserEntityWithPassword.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ public function setUserIdentifier(string $userIdentifier): self
5656
return $this;
5757
}
5858

59-
/**
60-
* @deprecated since Symfony 5.3, use getUserIdentifier instead
61-
*/
62-
public function getUsername(): string
63-
{
64-
return (string) $this->userIdentifier;
65-
}
66-
6759
/**
6860
* @see UserInterface
6961
*/
@@ -98,17 +90,6 @@ public function setPassword(string $password): self
9890
return $this;
9991
}
10092

101-
/**
102-
* Returning a salt is only needed, if you are not using a modern
103-
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
104-
*
105-
* @see UserInterface
106-
*/
107-
public function getSalt(): ?string
108-
{
109-
return null;
110-
}
111-
11293
/**
11394
* @see UserInterface
11495
*/

tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ public function setUserIdentifier(string $user_identifier): self
5656
return $this;
5757
}
5858

59-
/**
60-
* @deprecated since Symfony 5.3, use getUserIdentifier instead
61-
*/
62-
public function getUsername(): string
63-
{
64-
return (string) $this->user_identifier;
65-
}
66-
6759
/**
6860
* @see UserInterface
6961
*/
@@ -98,17 +90,6 @@ public function setPassword(string $password): self
9890
return $this;
9991
}
10092

101-
/**
102-
* Returning a salt is only needed, if you are not using a modern
103-
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
104-
*
105-
* @see UserInterface
106-
*/
107-
public function getSalt(): ?string
108-
{
109-
return null;
110-
}
111-
11293
/**
11394
* @see UserInterface
11495
*/

tests/Security/fixtures/expected/UserEntityWithoutPassword.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace App\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
6-
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
76
use Symfony\Component\Security\Core\User\UserInterface;
87

98
/**
@@ -50,14 +49,6 @@ public function setUserIdentifier(string $userIdentifier): self
5049
return $this;
5150
}
5251

53-
/**
54-
* @deprecated since Symfony 5.3, use getUserIdentifier instead
55-
*/
56-
public function getUsername(): string
57-
{
58-
return (string) $this->userIdentifier;
59-
}
60-
6152
/**
6253
* @see UserInterface
6354
*/
@@ -77,26 +68,6 @@ public function setRoles(array $roles): self
7768
return $this;
7869
}
7970

80-
/**
81-
* This method can be removed in Symfony 6.0 - is not needed for apps that do not check user passwords.
82-
*
83-
* @see PasswordAuthenticatedUserInterface
84-
*/
85-
public function getPassword(): ?string
86-
{
87-
return null;
88-
}
89-
90-
/**
91-
* This method can be removed in Symfony 6.0 - is not needed for apps that do not check user passwords.
92-
*
93-
* @see UserInterface
94-
*/
95-
public function getSalt(): ?string
96-
{
97-
return null;
98-
}
99-
10071
/**
10172
* @see UserInterface
10273
*/

0 commit comments

Comments
 (0)