Skip to content
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
34 changes: 25 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
- php-version: "8.4"
symfony-version: "6.4.*"
- php-version: "8.2"
symfony-version: "7.1.*"
symfony-version: "7.4.*"
- php-version: "8.4"
symfony-version: "7.3.*"
symfony-version: "7.4.*"

steps:
- name: "Checkout"
Expand All @@ -38,7 +38,11 @@ jobs:
composer require --no-interaction --no-update \
symfony/framework-bundle:${{ matrix.symfony-version }} \
symfony/validator:${{ matrix.symfony-version }} \
symfony/http-kernel:${{ matrix.symfony-version }}
symfony/http-kernel:${{ matrix.symfony-version }} \
symfony/serializer:${{ matrix.symfony-version }} \
symfony/property-info:${{ matrix.symfony-version }} \
symfony/console:${{ matrix.symfony-version }} \
symfony/routing:${{ matrix.symfony-version }}
composer update --no-interaction --no-progress

- name: "Run tests with phpunit/phpunit"
Expand All @@ -52,7 +56,7 @@ jobs:
matrix:
include:
- php-version: "8.4"
symfony-version: "7.3.*"
symfony-version: "7.4.*"

steps:
- name: "Checkout"
Expand All @@ -69,7 +73,11 @@ jobs:
composer require --no-interaction --no-update \
symfony/framework-bundle:${{ matrix.symfony-version }} \
symfony/validator:${{ matrix.symfony-version }} \
symfony/http-kernel:${{ matrix.symfony-version }}
symfony/http-kernel:${{ matrix.symfony-version }} \
symfony/serializer:${{ matrix.symfony-version }} \
symfony/property-info:${{ matrix.symfony-version }} \
symfony/console:${{ matrix.symfony-version }} \
symfony/routing:${{ matrix.symfony-version }}
composer update --no-interaction --no-progress

- name: "Run tests with phpunit/phpunit"
Expand All @@ -89,7 +97,7 @@ jobs:
matrix:
include:
- php-version: "8.4"
symfony-version: "7.3.*"
symfony-version: "7.4.*"

steps:
- name: "Checkout"
Expand All @@ -106,7 +114,11 @@ jobs:
composer require --no-interaction --no-update \
symfony/framework-bundle:${{ matrix.symfony-version }} \
symfony/validator:${{ matrix.symfony-version }} \
symfony/http-kernel:${{ matrix.symfony-version }}
symfony/http-kernel:${{ matrix.symfony-version }} \
symfony/serializer:${{ matrix.symfony-version }} \
symfony/property-info:${{ matrix.symfony-version }} \
symfony/console:${{ matrix.symfony-version }} \
symfony/routing:${{ matrix.symfony-version }}
composer update --no-interaction --no-progress

- name: "Run static analysis with phpstan/phpstan"
Expand All @@ -120,7 +132,7 @@ jobs:
matrix:
include:
- php-version: "8.4"
symfony-version: "7.3.*"
symfony-version: "7.4.*"

steps:
- name: "Checkout"
Expand All @@ -137,7 +149,11 @@ jobs:
composer require --no-interaction --no-update \
symfony/framework-bundle:${{ matrix.symfony-version }} \
symfony/validator:${{ matrix.symfony-version }} \
symfony/http-kernel:${{ matrix.symfony-version }}
symfony/http-kernel:${{ matrix.symfony-version }} \
symfony/serializer:${{ matrix.symfony-version }} \
symfony/property-info:${{ matrix.symfony-version }} \
symfony/console:${{ matrix.symfony-version }} \
symfony/routing:${{ matrix.symfony-version }}
composer update --no-interaction --no-progress

- name: "Run checkstyle with symplify/easy-coding-standard"
Expand Down
2 changes: 2 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Presta\SonataSavedFiltersBundle\SavedFiltersOwnerAccessor\AuthenticatedUserSavedFiltersOwnerAccessor;
use Presta\SonataSavedFiltersBundle\SavedFiltersOwnerAccessor\SavedFiltersOwnerAccessorInterface;
use Presta\SonataSavedFiltersBundle\Twig\SavedFiltersExtension;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

return static function (ContainerConfigurator $containerConfigurator): void {
Expand Down Expand Up @@ -47,6 +48,7 @@
->set(AuthenticatedUserSavedFiltersOwnerAccessor::class)
->args([
service(TokenStorageInterface::class),
service(KernelInterface::class),
])

->set(RemoveOrphanedSavedFiltersListener::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,33 @@
namespace Presta\SonataSavedFiltersBundle\SavedFiltersOwnerAccessor;

use Presta\SonataSavedFiltersBundle\Entity\SavedFiltersOwnerInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

final class AuthenticatedUserSavedFiltersOwnerAccessor implements SavedFiltersOwnerAccessorInterface
{
public function __construct(
private readonly TokenStorageInterface $tokenStorage,
private readonly KernelInterface $kernel,
) {
}

public function get(): SavedFiltersOwnerInterface
{
$user = $this->tokenStorage->getToken()?->getUser();
if ($user === null) {

if (null === $user) {
// In CLI, there is no authenticated user.
// Only return a dummy object if not in test environment.
if (PHP_SAPI === 'cli' && 'test' !== $this->kernel->getEnvironment()) {
// Return a dummy object that satisfies the interface to prevent commands from crashing.
return new class() implements SavedFiltersOwnerInterface {
};
}

throw new CannotAccessSavedFiltersOwnerException('Missing authenticated user.');
}

if (!$user instanceof SavedFiltersOwnerInterface) {
throw new CannotAccessSavedFiltersOwnerException(
\sprintf('Authenticated user %s does not implements %s', $user::class, SavedFiltersOwnerInterface::class),
Expand Down
49 changes: 26 additions & 23 deletions tests/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,37 @@ protected function configureContainer(ContainerConfigurator $container): void
],
],
]);
$ormConfig = [
'naming_strategy' => 'doctrine.orm.naming_strategy.underscore',
'mappings' => [
'PrestaSonataSavedFiltersBundle' => [
'is_bundle' => true,
'type' => 'attribute',
'dir' => 'src/Entity',
'prefix' => 'Presta\\SonataSavedFiltersBundle\\Entity',
'alias' => 'PrestaSonataSavedFiltersBundle',
],
'Tests' => [
'is_bundle' => false,
'type' => 'attribute',
'dir' => 'tests/App',
'prefix' => 'Presta\\SonataSavedFiltersBundle\\Tests\\App',
'alias' => 'Tests',
],
],
'resolve_target_entities' => [
SavedFiltersOwnerInterface::class => User::class,
],
];
if (\PHP_VERSION_ID < 80400) {
$ormConfig['auto_generate_proxy_classes'] = true;
}
$container->extension('doctrine', [
'dbal' => [
'url' => 'sqlite:///%kernel.project_dir%/var/database.sqlite',
'logging' => false,
],
'orm' => [
'auto_generate_proxy_classes' => true,
'naming_strategy' => 'doctrine.orm.naming_strategy.underscore',
'mappings' => [
'PrestaSonataSavedFiltersBundle' => [
'is_bundle' => true,
'type' => 'attribute',
'dir' => 'src/Entity',
'prefix' => 'Presta\\SonataSavedFiltersBundle\\Entity',
'alias' => 'PrestaSonataSavedFiltersBundle',
],
'Tests' => [
'is_bundle' => false,
'type' => 'attribute',
'dir' => 'tests/App',
'prefix' => 'Presta\\SonataSavedFiltersBundle\\Tests\\App',
'alias' => 'Tests',
],
],
'resolve_target_entities' => [
SavedFiltersOwnerInterface::class => User::class,
],
],
'orm' => $ormConfig,
]);
$container->extension('twig', [
'default_path' => __DIR__ . '/App/templates',
Expand Down