Skip to content
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

allow symfony6 #1006

Merged
merged 2 commits into from
Nov 13, 2021
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
22 changes: 18 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ jobs:
with:
composer-options: "--no-scripts"

-
name: "Composer install php-cs-fixer"
uses: "ramsey/composer-install@v1"
with:
composer-options: "--no-scripts --working-dir=tools/php-cs-fixer"

-
name: "Run friendsofphp/php-cs-fixer"
run: "vendor/bin/php-cs-fixer fix --dry-run --diff"
run: "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff"

test:
name: "PHP ${{ matrix.php-version }} + symfony/skeleton@${{ matrix.symfony-skeleton-stability }}"
Expand Down Expand Up @@ -89,14 +95,12 @@ jobs:
- '7.2'
- '7.3'
- '7.4'
- '8.0'
symfony-skeleton-stability:
- 'stable'
composer-options: ['--no-suggest']
allow-failures: [false]
include:
- php-version: '7.4'
symfony-skeleton-stability: 'dev'
allow-failures: true
- php-version: '8.0'
symfony-skeleton-stability: 'dev'
allow-failures: true
Expand Down Expand Up @@ -140,6 +144,16 @@ jobs:
with:
composer-options: "${{ matrix.composer-options }}"

- name: "Composer install php-cs-fixer"
uses: "ramsey/composer-install@v1"
with:
composer-options: "--no-scripts --working-dir=tools/php-cs-fixer"

- name: "Composer install twigcs"
uses: "ramsey/composer-install@v1"
with:
composer-options: "--no-scripts --working-dir=tools/twigcs"

- name: "Install PHPUnit"
run: vendor/bin/simple-phpunit install

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
/vendor/
/tests/tmp/*
/.php-cs-fixer.cache
/tools/*/vendor
/tools/*/composer.lock
/.phpunit.result.cache
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ install:
- cd C:\projects\maker-bundle
- composer global require --no-progress --no-scripts --no-plugins symfony/flex
- IF %dependencies%==highest appveyor-retry composer update --no-progress --no-suggest --ansi
- composer install --no-interaction --no-progress --ansi --no-scripts --working-dir=tools/twigcs
- composer install --no-interaction --no-progress --ansi --no-scripts --working-dir=tools/php-cs-fixer
- vendor/bin/simple-phpunit install

test_script:
Expand Down
26 changes: 12 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,24 @@
"php": ">=7.1.3",
"doctrine/inflector": "^1.2|^2.0",
"nikic/php-parser": "^4.11",
"symfony/config": "^4.0|^5.0",
"symfony/console": "^4.0|^5.0",
"symfony/dependency-injection": "^4.0|^5.0",
"symfony/config": "^4.0|^5.0|^6.0",
"symfony/console": "^4.0|^5.0|^6.0",
"symfony/dependency-injection": "^4.0|^5.0|^6.0",
"symfony/deprecation-contracts": "^2.2",
"symfony/filesystem": "^4.0|^5.0",
"symfony/finder": "^4.0|^5.0",
"symfony/framework-bundle": "^4.0|^5.0",
"symfony/http-kernel": "^4.0|^5.0"
"symfony/filesystem": "^4.0|^5.0|^6.0",
"symfony/finder": "^4.0|^5.0|^6.0",
"symfony/framework-bundle": "^4.0|^5.0|^6.0",
"symfony/http-kernel": "^4.0|^5.0|^6.0"
},
"require-dev": {
"composer/semver": "^3.0@dev",
"doctrine/doctrine-bundle": "^1.8|^2.0",
"doctrine/orm": "^2.3",
"friendsofphp/php-cs-fixer": "^3.0",
"friendsoftwig/twigcs": "^4.1.0|^5.0.0",
"symfony/http-client": "^4.3|^5.0",
"symfony/phpunit-bridge": "^4.3|^5.0",
"symfony/process": "^4.0|^5.0",
"symfony/security-core": "^4.0|^5.0",
"symfony/yaml": "^4.0|^5.0"
"symfony/http-client": "^4.3|^5.0|^6.0",
"symfony/phpunit-bridge": "^4.3|^5.0|^6.0",
"symfony/process": "^4.0|^5.0|^6.0",
"symfony/security-core": "^4.0|^5.0|^6.0",
"symfony/yaml": "^4.0|^5.0|^6.0"
},
"config": {
"preferred-install": "dist",
Expand Down
3 changes: 2 additions & 1 deletion src/Security/UserClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private function addGetUsername(ClassSourceManipulator $manipulator, UserClassCo

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

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

if ($symfony53GTE) {
if ($symfony53GTE && !$symfony6GTE) {
// also add the deprecated getUsername method
$manipulator->addAccessorMethod(
$userClassConfig->getIdentityPropertyName(),
Expand Down
12 changes: 10 additions & 2 deletions src/Test/MakerTestEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,21 @@ public function fileExists(string $file): bool

public function runPhpCSFixer(string $file): MakerTestProcess
{
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)
if (!file_exists(__DIR__.'/../../tools/php-cs-fixer/vendor/bin/php-cs-fixer')) {
throw new \Exception('php-cs-fixer not found: run: "composer install --working-dir=tools/php-cs-fixer".');
}

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)
->run(true);
}

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

return MakerTestProcess::create(sprintf('php tools/twigcs/vendor/bin/twigcs --config ./tools/twigcs/.twig_cs.dist %s', $this->path.'/'.$file), $this->rootPath)
->run(true);
}

Expand Down
9 changes: 4 additions & 5 deletions src/Test/MakerTestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Symfony\Component\Routing\RouteCollectionBuilder;

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

public function registerBundles()
public function registerBundles(): iterable
{
return [
new FrameworkBundle(),
new MakerBundle(),
];
}

protected function configureRoutes(RouteCollectionBuilder $routes)
protected function configureRoutes(RoutingConfigurator $routes)
{
}

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

public function getProjectDir()
public function getProjectDir(): string
{
return $this->getRootDir();
}

public function getRootDir()
public function getRootDir(): string
{
return $this->testRootDir;
}
Expand Down
11 changes: 7 additions & 4 deletions tests/Security/UserClassBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
use Symfony\Bundle\MakerBundle\Security\UserClassBuilder;
use Symfony\Bundle\MakerBundle\Security\UserClassConfiguration;
use Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator;
use Symfony\Component\Security\Core\User\InMemoryUser;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\User;
use Symfony\Component\Security\Core\User\UserInterface;

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

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

self::assertStringEqualsFile($expectedPath, $manipulator->getSourceCode());
self::assertSame($expectedSource, $manipulator->getSourceCode());
}

public function getUserInterfaceTests(): \Generator
Expand Down Expand Up @@ -86,7 +89,7 @@ public function getUserInterfaceTests(): \Generator
*/
public function testLegacyUserInterfaceGetUsername(UserClassConfiguration $userClassConfig, string $expectedFilename): void
{
if (method_exists(User::class, 'getUserIdentifier')) {
if (method_exists(InMemoryUser::class, 'getUserIdentifier')) {
self::markTestSkipped();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ public function getUserIdentifier(): string
return (string) $this->email;
}

/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->email;
}

/**
* @see UserInterface
*/
Expand Down Expand Up @@ -103,17 +95,6 @@ public function setPassword(string $password): self
return $this;
}

/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}

/**
* @see UserInterface
*/
Expand Down
19 changes: 0 additions & 19 deletions tests/Security/fixtures/expected/UserEntityWithPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ public function setUserIdentifier(string $userIdentifier): self
return $this;
}

/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->userIdentifier;
}

/**
* @see UserInterface
*/
Expand Down Expand Up @@ -98,17 +90,6 @@ public function setPassword(string $password): self
return $this;
}

/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}

/**
* @see UserInterface
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ public function setUserIdentifier(string $user_identifier): self
return $this;
}

/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->user_identifier;
}

/**
* @see UserInterface
*/
Expand Down Expand Up @@ -98,17 +90,6 @@ public function setPassword(string $password): self
return $this;
}

/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}

/**
* @see UserInterface
*/
Expand Down
29 changes: 0 additions & 29 deletions tests/Security/fixtures/expected/UserEntityWithoutPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;

/**
Expand Down Expand Up @@ -50,14 +49,6 @@ public function setUserIdentifier(string $userIdentifier): self
return $this;
}

/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->userIdentifier;
}

/**
* @see UserInterface
*/
Expand All @@ -77,26 +68,6 @@ public function setRoles(array $roles): self
return $this;
}

/**
* This method can be removed in Symfony 6.0 - is not needed for apps that do not check user passwords.
*
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): ?string
{
return null;
}

/**
* This method can be removed in Symfony 6.0 - is not needed for apps that do not check user passwords.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}

/**
* @see UserInterface
*/
Expand Down
Loading