Skip to content

Commit

Permalink
Updated deps (#321)
Browse files Browse the repository at this point in the history
* Updated deps + fixed references to self::$container

* Fixed login in tests

* Added a composer shortcut to update dev tools: `composer update-tools`

* Bring back support to Sf4.4 to Sf6.x
  • Loading branch information
DamienHarper authored Aug 7, 2022
1 parent 19127a0 commit 687f6c8
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 26 deletions.
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
"matthiasnoback/symfony-dependency-injection-test": "^3.1|^4.0",
"nyholm/symfony-bundle-test": "1.x-dev",
"phpunit/phpunit": "^8.0|^9.0",
"symfony/browser-kit": "^4.0|^5.1",
"symfony/css-selector": "^5.1",
"symfony/framework-bundle": "^4.4|^5.0",
"symfony/var-dumper": "^4.0|^5.0",
"symfony/browser-kit": "^4.0|^5.1|^6.0",
"symfony/css-selector": "^5.1|^6.0",
"symfony/framework-bundle": "^4.4|^5.0|^6.0",
"symfony/var-dumper": "^4.0|^5.0|^6.0",
"symfony/webpack-encore-bundle": "^1.12",
"twig/extensions": "^1.5"
},
Expand All @@ -60,7 +60,8 @@
"phpstan": "tools/phpstan/vendor/bin/phpstan --ansi analyse src",
"setup44": "SYMFONY_REQUIRE='^4.4' composer update --prefer-stable",
"setup54": "SYMFONY_REQUIRE='^5.4' composer update --prefer-stable",
"rector": "tools/rector/vendor/bin/rector process src"
"rector": "tools/rector/vendor/bin/rector process src",
"update-tools": "composer update --working-dir=tools/php-cs-fixer ; composer update --working-dir=tools/phpstan ; composer update --working-dir=tools/rector"
},
"config": {
"sort-packages": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ framework:
router:
utf8: true
session:
storage_id: session.storage.mock_file
storage_id: session.storage.mock_file
7 changes: 7 additions & 0 deletions tests/App/config/packages/sf6/framework.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
framework:
secret: '%env(APP_SECRET)%'
test: true
router:
utf8: true
session:
storage_factory_id: session.storage.factory.mock_file
10 changes: 9 additions & 1 deletion tests/Console/ConsoleUserProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ protected function getBundleClass()

private function createAndInitDoctrineProvider(): void
{
$this->provider = self::$container->get(DoctrineProvider::class);
// TODO: remove following code when min Symfony version supported is >= 5
if (Kernel::MAJOR_VERSION < 5) {
$this->provider = self::$container->get(DoctrineProvider::class);

return;
}

// Symfony >= 5.x only
$this->provider = self::getContainer()->get(DoctrineProvider::class);
}
}
54 changes: 38 additions & 16 deletions tests/Controller/ViewerControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,32 +306,54 @@ public function testShowTransactionHistoryWithRoleNotGrantedForAuthorAuditViewin

private function login(array $roles = []): void
{
$session = self::$container->get('session');
// TODO: remove following code when min Symfony version supported is >= 5
if (Kernel::MAJOR_VERSION < 5) {
$session = self::$container->get('session');
$class = class_exists(User::class) ? User::class : InMemoryUser::class;
$user = new $class(
'dark.vador',
'$argon2id$v=19$m=65536,t=4,p=1$g1yZVCS0GJ32k2fFqBBtqw$359jLODXkhqVWtD/rf+CjiNz9r/kIvhJlenPBnW851Y',
$roles
);
$firewallName = 'main';

if (6 === Kernel::MAJOR_VERSION) {
$token = new UsernamePasswordToken($user, $firewallName, $user->getRoles());
} else {
$token = new UsernamePasswordToken($user, null, $firewallName, $user->getRoles());
}
$session->set('_security_'.$firewallName, serialize($token));
$session->save();

self::$container->get('security.token_storage')->setToken($token);

$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);

return;
}

// Symfony >= 5.x only
$class = class_exists(User::class) ? User::class : InMemoryUser::class;
$user = new $class(
'dark.vador',
'$argon2id$v=19$m=65536,t=4,p=1$g1yZVCS0GJ32k2fFqBBtqw$359jLODXkhqVWtD/rf+CjiNz9r/kIvhJlenPBnW851Y',
$roles
);

$firewallName = 'main';

if (6 === Kernel::MAJOR_VERSION) {
$token = new UsernamePasswordToken($user, $firewallName, $user->getRoles());
} else {
$token = new UsernamePasswordToken($user, null, $firewallName, $user->getRoles());
}
$session->set('_security_'.$firewallName, serialize($token));
$session->save();

self::$container->get('security.token_storage')->setToken($token);

$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);
$this->client->loginUser($user);
}

private function createAndInitDoctrineProvider(): void
{
$this->provider = self::$container->get(DoctrineProvider::class);
// TODO: remove following code when min Symfony version supported is >= 5
if (Kernel::MAJOR_VERSION < 5) {
$this->provider = self::$container->get(DoctrineProvider::class);

return;
}

// Symfony >= 5.x only
$this->provider = self::getContainer()->get(DoctrineProvider::class);
}
}
27 changes: 24 additions & 3 deletions tests/User/UserProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ public function testBlameUser(): void
} else {
$token = new UsernamePasswordToken($user, null, $firewallName, $user->getRoles());
}
self::$container->get('security.token_storage')->setToken($token);

// TODO: remove following code when min Symfony version supported is >= 5
if (Kernel::MAJOR_VERSION < 5) {
self::$container->get('security.token_storage')->setToken($token);
} else {
self::getContainer()->get('security.token_storage')->setToken($token);
}

$post = new Post();
$post
->setTitle('Blameable post')
Expand Down Expand Up @@ -95,7 +102,13 @@ public function testBlameImpersonator(): void
$token = new SwitchUserToken($secondUser, null, $firewallName, $secondUser->getRoles(), $userToken);
}

self::$container->get('security.token_storage')->setToken($token);
// TODO: remove following code when min Symfony version supported is >= 5
if (Kernel::MAJOR_VERSION < 5) {
self::$container->get('security.token_storage')->setToken($token);
} else {
self::getContainer()->get('security.token_storage')->setToken($token);
}

$post = new Post();
$post
->setTitle('Blameable post')
Expand All @@ -116,7 +129,15 @@ protected function getBundleClass()

private function createAndInitDoctrineProvider(): void
{
$this->provider = self::$container->get(DoctrineProvider::class);
// TODO: remove following code when min Symfony version supported is >= 5
if (Kernel::MAJOR_VERSION < 5) {
$this->provider = self::$container->get(DoctrineProvider::class);

return;
}

// Symfony >= 5.x only
$this->provider = self::getContainer()->get(DoctrineProvider::class);
}

private function createUser(string $username): UserInterface
Expand Down

0 comments on commit 687f6c8

Please sign in to comment.