Skip to content

Commit

Permalink
Fix Symfony 6 compatibility (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu authored Oct 28, 2021
1 parent c84cfa5 commit c944d22
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
php-version: "8.0"
php-extensions: "redis"
stability: "dev"
- symfony-require: "6.0.*"
php-version: "8.0"
php-extensions: "redis"
stability: "dev"

steps:
- name: "Checkout"
Expand Down Expand Up @@ -64,6 +68,10 @@ jobs:
if: "${{ matrix.stability }}"
run: "composer config minimum-stability ${{ matrix.stability }}"

- name: "Remove symfony/swiftmailer-bundle with symfony 6"
if: "${{ matrix.symfony-require == '6.0.*' }}"
run: "composer remove --dev --no-update symfony/swiftmailer-bundle"

- name: "Install symfony/flex"
run: "composer global require --no-progress --no-scripts --no-plugins symfony/flex"

Expand Down
12 changes: 3 additions & 9 deletions Session/Storage/Handler/RedisSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,8 @@ public function gc($maxlifetime)

/**
* {@inheritdoc}
*
* @return string
*/
protected function doRead($sessionId)
protected function doRead($sessionId): string
{
if ($this->locking && !$this->locked && !$this->lockSession($sessionId)) {
return false;
Expand All @@ -168,10 +166,8 @@ protected function doRead($sessionId)

/**
* {@inheritdoc}
*
* @return bool
*/
protected function doWrite($sessionId, $data)
protected function doWrite($sessionId, $data): bool
{
if (0 < $this->ttl) {
$this->redis->setex($this->getRedisKey($sessionId), $this->ttl, $data);
Expand All @@ -184,10 +180,8 @@ protected function doWrite($sessionId, $data)

/**
* {@inheritdoc}
*
* @return bool
*/
protected function doDestroy($sessionId)
protected function doDestroy($sessionId): bool
{
$this->redis->del($this->getRedisKey($sessionId));
$this->close();
Expand Down
15 changes: 11 additions & 4 deletions Tests/Functional/App/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Snc\RedisBundle\Tests\Functional\App\Controller;

use Doctrine\ORM\EntityManagerInterface;
use Snc\RedisBundle\Tests\Functional\App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand All @@ -25,6 +26,13 @@
*/
class Controller extends AbstractController
{
private $entityManager;

public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}

public function home(Request $request, \Redis $redis)
{
$redis->set('foo', 'bar');
Expand All @@ -41,16 +49,15 @@ public function createUser()
->setEmail('[email protected]')
;

$em = $this->getDoctrine()->getManagerForClass(User::class);
$em->persist($user);
$em->flush();
$this->entityManager->persist($user);
$this->entityManager->flush();

return new JsonResponse(['result' => 'ok']);
}

public function viewUser()
{
$repository = $this->getDoctrine()->getRepository(User::class);
$repository = $this->entityManager->getRepository(User::class);

/** @var User $user */
$user = $repository->findOneBy(['username' => 'foo']);
Expand Down
16 changes: 16 additions & 0 deletions Tests/Functional/App/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
]
]);
}

// Since symfony/framework-bundle 5.3: Not setting the "framework.session.storage_factory_id" configuration option
// is deprecated, it will replace the "framework.session.storage_id" configuration option in version 6.0.
if (self::VERSION_ID >= 50300) {
$container->loadFromExtension('framework', [
'session' => [
'storage_factory_id' => 'session.storage.factory.mock_file',
]
]);
} else {
$container->loadFromExtension('framework', [
'session' => [
'storage_id' => 'session.storage.mock_file',
]
]);
}
}

public function getProjectDir(): string
Expand Down
2 changes: 0 additions & 2 deletions Tests/Functional/App/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ framework:
test: ~
default_locale: en
profiler: { collect: true }
session:
storage_id: session.storage.mock_file

twig:
strict_variables: true
Expand Down

0 comments on commit c944d22

Please sign in to comment.