From f8022f6c39aa9eacfe8c055b21a4c45f666ae7e1 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Sun, 17 Jul 2022 09:25:50 +0200 Subject: [PATCH] Mark classes as final (#1463) --- UPGRADE-4.0.md | 4 + src/Admin/BlockAdmin.php | 4 +- .../CreateSnapshotAdminExtension.php | 5 +- src/Admin/PageAdmin.php | 4 +- src/Admin/SharedBlockAdmin.php | 4 +- src/Admin/SiteAdmin.php | 4 +- src/Admin/SnapshotAdmin.php | 4 +- src/Block/BlockContextManager.php | 4 +- src/Block/BreadcrumbBlockService.php | 4 +- src/CmsManager/CmsManagerSelector.php | 6 +- src/CmsManager/CmsPageManager.php | 4 +- src/CmsManager/CmsSnapshotManager.php | 4 +- src/CmsManager/DecoratorStrategy.php | 10 +- src/Command/CleanupSnapshotsCommand.php | 4 +- src/Command/CreateSiteCommand.php | 4 +- src/Command/CreateSnapshotsCommand.php | 4 +- src/Command/DumpPageCommand.php | 4 +- .../MigrateBlockNameSettingCommand.php | 4 +- src/Command/MigrateToJsonTypeCommand.php | 5 +- src/Command/RenderBlockCommand.php | 4 +- src/Command/UpdateCoreRoutesCommand.php | 4 +- src/Controller/AjaxController.php | 10 +- src/Controller/BlockAdminController.php | 4 +- src/Controller/BlockController.php | 4 +- src/Controller/PageAdminController.php | 4 +- src/Controller/PageController.php | 4 +- src/Controller/SiteAdminController.php | 4 +- src/Controller/SnapshotAdminController.php | 4 +- .../Compiler/GlobalVariablesCompilerPass.php | 4 +- .../Compiler/PageServiceCompilerPass.php | 8 +- src/DependencyInjection/Configuration.php | 6 +- src/Entity/BlockInteractor.php | 10 +- src/Entity/BlockManager.php | 4 +- src/Entity/PageManager.php | 4 +- src/Entity/SiteManager.php | 4 +- src/Entity/SnapshotManager.php | 6 +- src/Entity/Transformer.php | 20 ++- src/Exception/InternalErrorException.php | 4 +- src/Exception/PageNotFoundException.php | 4 +- src/Form/Type/CreateSnapshotType.php | 4 +- src/Form/Type/PageSelectorType.php | 4 +- src/Form/Type/PageTypeChoiceType.php | 4 +- src/Form/Type/TemplateChoiceType.php | 4 +- src/Generator/Mustache.php | 4 +- src/Listener/RequestListener.php | 10 +- src/Model/PageManagerInterface.php | 5 + src/Model/SnapshotPageProxy.php | 4 +- src/Model/Template.php | 14 +- src/Page/PageServiceManager.php | 12 +- src/Page/Service/DefaultPageService.php | 4 +- src/Request/RequestFactory.php | 5 +- src/Request/SiteRequest.php | 6 +- src/Request/SiteRequestContext.php | 10 +- src/Route/CmsPageRouter.php | 29 ++-- src/Route/RoutePageGenerator.php | 14 +- src/Service/CleanupSnapshotService.php | 11 +- src/Service/CreateSnapshotService.php | 12 +- src/Site/HostByLocaleSiteSelector.php | 6 +- src/Site/HostPathByLocaleSiteSelector.php | 6 +- src/Template/Matrix/Parser.php | 4 +- src/Twig/GlobalVariables.php | 8 +- tests/Command/BaseCommandTest.php | 4 +- .../CreateBlockContainerCommandTest.php | 18 +-- tests/Entity/SnapshotManagerTest.php | 126 +++++++----------- tests/Form/Type/TemplateChoiceTypeTest.php | 13 +- tests/Listener/ExceptionListenerTest.php | 2 +- tests/Page/TemplateManagerTest.php | 25 ++-- tests/Route/RoutePageGeneratorTest.php | 4 +- tests/Service/CleanupSnapshotServiceTest.php | 8 +- tests/Service/CreateSnapshotServiceTest.php | 8 +- tests/Site/BaseLocaleSiteSelectorTest.php | 24 ---- tests/Site/HostByLocaleSiteSelectorTest.php | 33 +++-- .../Site/HostPathByLocaleSiteSelectorTest.php | 33 +++-- tests/Site/SubRequestsSiteSelectorTest.php | 47 ++++--- 74 files changed, 279 insertions(+), 448 deletions(-) diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 63b275819..bceaa9c42 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -1,6 +1,10 @@ UPGRADE FROM 3.x to 4.0 ======================= +## Final classes + +All classes that were marked as final in 3.x are now marked final in 4.0. + ## Deprecations All the deprecated code introduced on 3.x is removed on 4.0. diff --git a/src/Admin/BlockAdmin.php b/src/Admin/BlockAdmin.php index afa039c6c..f3ce15c75 100644 --- a/src/Admin/BlockAdmin.php +++ b/src/Admin/BlockAdmin.php @@ -32,10 +32,8 @@ * Admin class for the Block model. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class BlockAdmin extends BaseBlockAdmin +final class BlockAdmin extends BaseBlockAdmin { /** * @var array diff --git a/src/Admin/Extension/CreateSnapshotAdminExtension.php b/src/Admin/Extension/CreateSnapshotAdminExtension.php index cc74357fe..ed788f8a8 100644 --- a/src/Admin/Extension/CreateSnapshotAdminExtension.php +++ b/src/Admin/Extension/CreateSnapshotAdminExtension.php @@ -19,10 +19,7 @@ use Sonata\PageBundle\Model\PageInterface; use Sonata\PageBundle\Service\Contract\CreateSnapshotByPageInterface; -/** - * @final since sonata-project/page-bundle 3.26 - */ -class CreateSnapshotAdminExtension extends AbstractAdminExtension +final class CreateSnapshotAdminExtension extends AbstractAdminExtension { protected CreateSnapshotByPageInterface $createSnapshotByPage; diff --git a/src/Admin/PageAdmin.php b/src/Admin/PageAdmin.php index 524f26cdf..e0f55b8a4 100644 --- a/src/Admin/PageAdmin.php +++ b/src/Admin/PageAdmin.php @@ -39,10 +39,8 @@ * Admin definition for the Page class. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class PageAdmin extends AbstractAdmin +final class PageAdmin extends AbstractAdmin { protected $classnameLabel = 'Page'; diff --git a/src/Admin/SharedBlockAdmin.php b/src/Admin/SharedBlockAdmin.php index 95e11cf71..4dd445365 100644 --- a/src/Admin/SharedBlockAdmin.php +++ b/src/Admin/SharedBlockAdmin.php @@ -26,10 +26,8 @@ * Admin class for shared Block model. * * @author Romain Mouillard - * - * @final since sonata-project/page-bundle 3.26 */ -class SharedBlockAdmin extends BaseBlockAdmin +final class SharedBlockAdmin extends BaseBlockAdmin { /** * @var string diff --git a/src/Admin/SiteAdmin.php b/src/Admin/SiteAdmin.php index 15b69d474..43f0c1cf2 100644 --- a/src/Admin/SiteAdmin.php +++ b/src/Admin/SiteAdmin.php @@ -28,10 +28,8 @@ * Admin definition for the Site class. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class SiteAdmin extends AbstractAdmin +final class SiteAdmin extends AbstractAdmin { protected $classnameLabel = 'Site'; diff --git a/src/Admin/SnapshotAdmin.php b/src/Admin/SnapshotAdmin.php index c841e956a..aa82cdcd1 100644 --- a/src/Admin/SnapshotAdmin.php +++ b/src/Admin/SnapshotAdmin.php @@ -23,10 +23,8 @@ * Admin definition for the Snapshot class. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class SnapshotAdmin extends AbstractAdmin +final class SnapshotAdmin extends AbstractAdmin { protected $classnameLabel = 'Snapshot'; diff --git a/src/Block/BlockContextManager.php b/src/Block/BlockContextManager.php index 2368df378..8e08fab59 100644 --- a/src/Block/BlockContextManager.php +++ b/src/Block/BlockContextManager.php @@ -22,10 +22,8 @@ * * @psalm-suppress InvalidExtendClass * @phpstan-ignore-next-line - * - * @final since sonata-project/page-bundle 3.26 */ -class BlockContextManager extends BaseBlockContextManager +final class BlockContextManager extends BaseBlockContextManager { protected function configureSettings(OptionsResolver $optionsResolver, BlockInterface $block): void { diff --git a/src/Block/BreadcrumbBlockService.php b/src/Block/BreadcrumbBlockService.php index ceb4739d9..3b0769ee5 100644 --- a/src/Block/BreadcrumbBlockService.php +++ b/src/Block/BreadcrumbBlockService.php @@ -27,10 +27,8 @@ * BlockService for homepage breadcrumb. * * @author Sylvain Deloux - * - * @final since sonata-project/page-bundle 3.26 */ -class BreadcrumbBlockService extends BaseBreadcrumbMenuBlockService +final class BreadcrumbBlockService extends BaseBreadcrumbMenuBlockService { /** * @var CmsManagerSelectorInterface diff --git a/src/CmsManager/CmsManagerSelector.php b/src/CmsManager/CmsManagerSelector.php index be9db91f6..32b4b676f 100644 --- a/src/CmsManager/CmsManagerSelector.php +++ b/src/CmsManager/CmsManagerSelector.php @@ -27,15 +27,13 @@ * - sonata.page.cms.snapshot if the user is a standard user. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class CmsManagerSelector implements CmsManagerSelectorInterface, LogoutHandlerInterface +final class CmsManagerSelector implements CmsManagerSelectorInterface, LogoutHandlerInterface { /** * @var ContainerInterface */ - protected $container; + private $container; /** * @psalm-suppress ContainerDependency diff --git a/src/CmsManager/CmsPageManager.php b/src/CmsManager/CmsPageManager.php index 323506fd1..f05de68a8 100644 --- a/src/CmsManager/CmsPageManager.php +++ b/src/CmsManager/CmsPageManager.php @@ -24,10 +24,8 @@ * The CmsPageManager class is in charge of retrieving the correct page (cms page or action page). * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class CmsPageManager extends BaseCmsPageManager +final class CmsPageManager extends BaseCmsPageManager { /** * @var BlockInteractorInterface diff --git a/src/CmsManager/CmsSnapshotManager.php b/src/CmsManager/CmsSnapshotManager.php index 4a702c6d7..966d2ec59 100644 --- a/src/CmsManager/CmsSnapshotManager.php +++ b/src/CmsManager/CmsSnapshotManager.php @@ -26,10 +26,8 @@ * The CmsSnapshotManager class is in charge of retrieving the correct page (cms page or action page). * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class CmsSnapshotManager extends BaseCmsPageManager +final class CmsSnapshotManager extends BaseCmsPageManager { /** * @var SnapshotManagerInterface diff --git a/src/CmsManager/DecoratorStrategy.php b/src/CmsManager/DecoratorStrategy.php index e09fa6a34..48c261365 100644 --- a/src/CmsManager/DecoratorStrategy.php +++ b/src/CmsManager/DecoratorStrategy.php @@ -22,25 +22,23 @@ * on the current request. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class DecoratorStrategy implements DecoratorStrategyInterface +final class DecoratorStrategy implements DecoratorStrategyInterface { /** * @var array */ - protected $ignoreRoutes; + private $ignoreRoutes; /** * @var array */ - protected $ignoreRoutePatterns; + private $ignoreRoutePatterns; /** * @var array */ - protected $ignoreUriPatterns; + private $ignoreUriPatterns; public function __construct(array $ignoreRoutes, array $ignoreRoutePatterns, array $ignoreUriPatterns) { diff --git a/src/Command/CleanupSnapshotsCommand.php b/src/Command/CleanupSnapshotsCommand.php index 6cb19a6f7..dfa2be728 100644 --- a/src/Command/CleanupSnapshotsCommand.php +++ b/src/Command/CleanupSnapshotsCommand.php @@ -20,10 +20,8 @@ /** * Cleanups the deprecated snapshots. - * - * @final since sonata-project/page-bundle 3.26 */ -class CleanupSnapshotsCommand extends BaseCommand +final class CleanupSnapshotsCommand extends BaseCommand { protected static $defaultName = 'sonata:page:cleanup-snapshots'; diff --git a/src/Command/CreateSiteCommand.php b/src/Command/CreateSiteCommand.php index ac048a9b8..c52a6495f 100644 --- a/src/Command/CreateSiteCommand.php +++ b/src/Command/CreateSiteCommand.php @@ -23,10 +23,8 @@ * Create a site. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class CreateSiteCommand extends BaseCommand +final class CreateSiteCommand extends BaseCommand { public function configure(): void { diff --git a/src/Command/CreateSnapshotsCommand.php b/src/Command/CreateSnapshotsCommand.php index 1f9e67460..d44f0293f 100644 --- a/src/Command/CreateSnapshotsCommand.php +++ b/src/Command/CreateSnapshotsCommand.php @@ -23,10 +23,8 @@ * Create snapshots for a site. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class CreateSnapshotsCommand extends BaseCommand +final class CreateSnapshotsCommand extends BaseCommand { protected static $defaultName = 'sonata:page:create-snapshots'; diff --git a/src/Command/DumpPageCommand.php b/src/Command/DumpPageCommand.php index 884c035cb..d6bfd2bf1 100644 --- a/src/Command/DumpPageCommand.php +++ b/src/Command/DumpPageCommand.php @@ -23,13 +23,11 @@ /** * Migrates the name setting of all blocks into a code setting. * - * @final since sonata-project/page-bundle 3.26 - * * NEXT_MAJOR: Remove this class * * @deprecated since 3.27, and it will be removed in 4.0. */ -class DumpPageCommand extends BaseCommand +final class DumpPageCommand extends BaseCommand { public function configure(): void { diff --git a/src/Command/MigrateBlockNameSettingCommand.php b/src/Command/MigrateBlockNameSettingCommand.php index 396fa2550..58ad2b49a 100644 --- a/src/Command/MigrateBlockNameSettingCommand.php +++ b/src/Command/MigrateBlockNameSettingCommand.php @@ -22,10 +22,8 @@ /** * Migrates the name setting of all blocks into a code setting. - * - * @final since sonata-project/page-bundle 3.26 */ -class MigrateBlockNameSettingCommand extends BaseCommand +final class MigrateBlockNameSettingCommand extends BaseCommand { public const CONTAINER_TYPE = 'sonata.page.block.container'; diff --git a/src/Command/MigrateToJsonTypeCommand.php b/src/Command/MigrateToJsonTypeCommand.php index 97dbd561d..8d5d8f574 100644 --- a/src/Command/MigrateToJsonTypeCommand.php +++ b/src/Command/MigrateToJsonTypeCommand.php @@ -17,10 +17,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -/** - * @final since sonata-project/page-bundle 3.26 - */ -class MigrateToJsonTypeCommand extends BaseCommand +final class MigrateToJsonTypeCommand extends BaseCommand { public function configure(): void { diff --git a/src/Command/RenderBlockCommand.php b/src/Command/RenderBlockCommand.php index f266de7af..dcd448e94 100644 --- a/src/Command/RenderBlockCommand.php +++ b/src/Command/RenderBlockCommand.php @@ -22,13 +22,11 @@ /** * Migrates the name setting of all blocks into a code setting. * - * @final since sonata-project/page-bundle 3.26 - * * NEXT_MAJOR: Remove this class * * @deprecated since 3.27, and it will be removed in 4.0. */ -class RenderBlockCommand extends BaseCommand +final class RenderBlockCommand extends BaseCommand { public function configure(): void { diff --git a/src/Command/UpdateCoreRoutesCommand.php b/src/Command/UpdateCoreRoutesCommand.php index 728daee89..05348a858 100644 --- a/src/Command/UpdateCoreRoutesCommand.php +++ b/src/Command/UpdateCoreRoutesCommand.php @@ -24,10 +24,8 @@ * Update core routes by reading routing information. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class UpdateCoreRoutesCommand extends BaseCommand +final class UpdateCoreRoutesCommand extends BaseCommand { public function configure(): void { diff --git a/src/Controller/AjaxController.php b/src/Controller/AjaxController.php index 083819c92..7d82d7b65 100644 --- a/src/Controller/AjaxController.php +++ b/src/Controller/AjaxController.php @@ -25,25 +25,23 @@ * Render a block in ajax. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class AjaxController +final class AjaxController { /** * @var CmsManagerSelectorInterface */ - protected $cmsManagerSelector; + private $cmsManagerSelector; /** * @var BlockRendererInterface */ - protected $blockRenderer; + private $blockRenderer; /** * @var BlockContextManagerInterface */ - protected $contextManager; + private $contextManager; /** * @param CmsManagerSelectorInterface $cmsManagerSelector CMS Manager selector diff --git a/src/Controller/BlockAdminController.php b/src/Controller/BlockAdminController.php index 0ad1b6a80..7daa27689 100644 --- a/src/Controller/BlockAdminController.php +++ b/src/Controller/BlockAdminController.php @@ -25,10 +25,8 @@ * Block Admin Controller. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class BlockAdminController extends Controller +final class BlockAdminController extends Controller { /** * @throws AccessDeniedException diff --git a/src/Controller/BlockController.php b/src/Controller/BlockController.php index 5c1747630..4d18badaa 100644 --- a/src/Controller/BlockController.php +++ b/src/Controller/BlockController.php @@ -20,10 +20,8 @@ * Block controller. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class BlockController extends Controller +final class BlockController extends Controller { /** * @return Response diff --git a/src/Controller/PageAdminController.php b/src/Controller/PageAdminController.php index 9a3574527..2b2d78429 100644 --- a/src/Controller/PageAdminController.php +++ b/src/Controller/PageAdminController.php @@ -26,10 +26,8 @@ * Page Admin Controller. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class PageAdminController extends Controller +final class PageAdminController extends Controller { /** * @throws AccessDeniedException diff --git a/src/Controller/PageController.php b/src/Controller/PageController.php index ea3cd2b52..515cd98a5 100644 --- a/src/Controller/PageController.php +++ b/src/Controller/PageController.php @@ -28,10 +28,8 @@ * Page controller. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class PageController extends Controller +final class PageController extends Controller { /** * @throws AccessDeniedException diff --git a/src/Controller/SiteAdminController.php b/src/Controller/SiteAdminController.php index 0951fea48..c41bf9c44 100644 --- a/src/Controller/SiteAdminController.php +++ b/src/Controller/SiteAdminController.php @@ -23,10 +23,8 @@ * Site Admin controller. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class SiteAdminController extends Controller +final class SiteAdminController extends Controller { /** * @throws NotFoundHttpException diff --git a/src/Controller/SnapshotAdminController.php b/src/Controller/SnapshotAdminController.php index 555cc6fc8..28da31e56 100644 --- a/src/Controller/SnapshotAdminController.php +++ b/src/Controller/SnapshotAdminController.php @@ -23,10 +23,8 @@ * Snapshot Admin Controller. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class SnapshotAdminController extends Controller +final class SnapshotAdminController extends Controller { public function createAction(?Request $request = null) { diff --git a/src/DependencyInjection/Compiler/GlobalVariablesCompilerPass.php b/src/DependencyInjection/Compiler/GlobalVariablesCompilerPass.php index f7979a421..9297ea4f7 100644 --- a/src/DependencyInjection/Compiler/GlobalVariablesCompilerPass.php +++ b/src/DependencyInjection/Compiler/GlobalVariablesCompilerPass.php @@ -21,10 +21,8 @@ * GlobalVariablesCompilerPass. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class GlobalVariablesCompilerPass implements CompilerPassInterface +final class GlobalVariablesCompilerPass implements CompilerPassInterface { public function process(ContainerBuilder $container): void { diff --git a/src/DependencyInjection/Compiler/PageServiceCompilerPass.php b/src/DependencyInjection/Compiler/PageServiceCompilerPass.php index 7ecef5698..7dc99dc04 100644 --- a/src/DependencyInjection/Compiler/PageServiceCompilerPass.php +++ b/src/DependencyInjection/Compiler/PageServiceCompilerPass.php @@ -21,20 +21,18 @@ * Inject page services into page service manager. * * @author Olivier Paradis - * - * @final since sonata-project/page-bundle 3.26 */ -class PageServiceCompilerPass implements CompilerPassInterface +final class PageServiceCompilerPass implements CompilerPassInterface { /** * @var string */ - protected $manager = 'sonata.page.page_service_manager'; + private $manager = 'sonata.page.page_service_manager'; /** * @var string */ - protected $tagName = 'sonata.page'; + private $tagName = 'sonata.page'; public function process(ContainerBuilder $container): void { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index c264af332..2b92f6fbd 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -26,10 +26,8 @@ * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class Configuration implements ConfigurationInterface +final class Configuration implements ConfigurationInterface { public function getConfigTreeBuilder() { @@ -315,7 +313,7 @@ public function getConfigTreeBuilder() return $treeBuilder; } - protected function getDeprecationMessage($message, $version): array + private function getDeprecationMessage($message, $version): array { if (method_exists(BaseNode::class, 'getDeprecation')) { return [ diff --git a/src/Entity/BlockInteractor.php b/src/Entity/BlockInteractor.php index 75dfa7c24..29d22719c 100644 --- a/src/Entity/BlockInteractor.php +++ b/src/Entity/BlockInteractor.php @@ -23,25 +23,23 @@ * This class interacts with blocks. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class BlockInteractor implements BlockInteractorInterface +final class BlockInteractor implements BlockInteractorInterface { /** * @var bool[] */ - protected $pageBlocksLoaded = []; + private $pageBlocksLoaded = []; /** * @var ManagerRegistry */ - protected $registry; + private $registry; /** * @var ManagerInterface */ - protected $blockManager; + private $blockManager; /** * @param ManagerRegistry $registry Doctrine registry diff --git a/src/Entity/BlockManager.php b/src/Entity/BlockManager.php index 8ba3d6909..3d0c50765 100644 --- a/src/Entity/BlockManager.php +++ b/src/Entity/BlockManager.php @@ -20,10 +20,8 @@ * This class manages BlockInterface persistency with the Doctrine ORM. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class BlockManager extends BaseEntityManager implements BlockManagerInterface +final class BlockManager extends BaseEntityManager implements BlockManagerInterface { public function save($entity, $andFlush = true) { diff --git a/src/Entity/PageManager.php b/src/Entity/PageManager.php index 3bd31a02d..d28232c7b 100644 --- a/src/Entity/PageManager.php +++ b/src/Entity/PageManager.php @@ -24,10 +24,8 @@ * This class manages PageInterface persistency with the Doctrine ORM. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class PageManager extends BaseEntityManager implements PageManagerInterface +final class PageManager extends BaseEntityManager implements PageManagerInterface { /** * @var array diff --git a/src/Entity/SiteManager.php b/src/Entity/SiteManager.php index 3004fba62..603e9f185 100644 --- a/src/Entity/SiteManager.php +++ b/src/Entity/SiteManager.php @@ -20,10 +20,8 @@ * This class manages SiteInterface persistency with the Doctrine ORM. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class SiteManager extends BaseEntityManager implements SiteManagerInterface +final class SiteManager extends BaseEntityManager implements SiteManagerInterface { public function save($entity, $andFlush = true) { diff --git a/src/Entity/SnapshotManager.php b/src/Entity/SnapshotManager.php index cce447218..50d994ae3 100644 --- a/src/Entity/SnapshotManager.php +++ b/src/Entity/SnapshotManager.php @@ -27,10 +27,8 @@ * This class manages SnapshotInterface persistency with the Doctrine ORM. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class SnapshotManager extends BaseEntityManager implements SnapshotManagerInterface +final class SnapshotManager extends BaseEntityManager implements SnapshotManagerInterface { /** * @var array @@ -285,7 +283,7 @@ public function cleanup(PageInterface $page, $keep) throw new \RuntimeException(sprintf('The %s database platform has not been tested yet. Please report us if it works and feel free to create a pull request to handle it ;-)', $platform)); } - final public function createSnapshotPageProxy(TransformerInterface $transformer, SnapshotInterface $snapshot) + public function createSnapshotPageProxy(TransformerInterface $transformer, SnapshotInterface $snapshot) { return $this->snapshotPageProxyFactory ->create($this, $transformer, $snapshot); diff --git a/src/Entity/Transformer.php b/src/Entity/Transformer.php index cfd65d355..64c619e25 100644 --- a/src/Entity/Transformer.php +++ b/src/Entity/Transformer.php @@ -27,35 +27,33 @@ /** * This class transform a SnapshotInterface into PageInterface. - * - * @final since sonata-project/page-bundle 3.26 */ -class Transformer implements TransformerInterface +final class Transformer implements TransformerInterface { /** * @var SnapshotManagerInterface */ - protected $snapshotManager; + private $snapshotManager; /** * @var PageManagerInterface */ - protected $pageManager; + private $pageManager; /** * @var ManagerInterface */ - protected $blockManager; + private $blockManager; /** * @var BlockInterface[] */ - protected $children = []; + private $children = []; /** * @var ManagerRegistry */ - protected $registry; + private $registry; public function __construct(SnapshotManagerInterface $snapshotManager, PageManagerInterface $pageManager, ManagerInterface $blockManager, ManagerRegistry $registry) { @@ -238,7 +236,7 @@ public function getChildren(PageInterface $page) /** * @return array */ - protected function fixPageContent(array $content) + private function fixPageContent(array $content) { if (!\array_key_exists('title', $content)) { $content['title'] = null; @@ -250,7 +248,7 @@ protected function fixPageContent(array $content) /** * @return array */ - protected function fixBlockContent(array $content) + private function fixBlockContent(array $content) { if (!\array_key_exists('name', $content)) { $content['name'] = null; @@ -262,7 +260,7 @@ protected function fixBlockContent(array $content) /** * @return array */ - protected function createBlocks(BlockInterface $block) + private function createBlocks(BlockInterface $block) { $content = []; $content['id'] = $block->getId(); diff --git a/src/Exception/InternalErrorException.php b/src/Exception/InternalErrorException.php index b3952c30c..d46427aaf 100644 --- a/src/Exception/InternalErrorException.php +++ b/src/Exception/InternalErrorException.php @@ -17,9 +17,7 @@ * Exception used to raise an internal error. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class InternalErrorException extends \RuntimeException +final class InternalErrorException extends \RuntimeException { } diff --git a/src/Exception/PageNotFoundException.php b/src/Exception/PageNotFoundException.php index 13481b189..67122e3a0 100644 --- a/src/Exception/PageNotFoundException.php +++ b/src/Exception/PageNotFoundException.php @@ -19,9 +19,7 @@ * Exception used to handle a page not found situation. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class PageNotFoundException extends NotFoundHttpException +final class PageNotFoundException extends NotFoundHttpException { } diff --git a/src/Form/Type/CreateSnapshotType.php b/src/Form/Type/CreateSnapshotType.php index 86ac3fa95..26244e48e 100644 --- a/src/Form/Type/CreateSnapshotType.php +++ b/src/Form/Type/CreateSnapshotType.php @@ -20,10 +20,8 @@ * Select a Page. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class CreateSnapshotType extends AbstractType +final class CreateSnapshotType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options): void { diff --git a/src/Form/Type/PageSelectorType.php b/src/Form/Type/PageSelectorType.php index c662aa755..89f9e41a8 100644 --- a/src/Form/Type/PageSelectorType.php +++ b/src/Form/Type/PageSelectorType.php @@ -26,10 +26,8 @@ * Select a page. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class PageSelectorType extends AbstractType +final class PageSelectorType extends AbstractType { /** * @var PageManagerInterface diff --git a/src/Form/Type/PageTypeChoiceType.php b/src/Form/Type/PageTypeChoiceType.php index 8f2a97e36..b448738e9 100644 --- a/src/Form/Type/PageTypeChoiceType.php +++ b/src/Form/Type/PageTypeChoiceType.php @@ -23,10 +23,8 @@ * Select a page type. * * @author Olivier Paradis - * - * @final since sonata-project/page-bundle 3.26 */ -class PageTypeChoiceType extends AbstractType +final class PageTypeChoiceType extends AbstractType { /** * @var PageServiceManagerInterface diff --git a/src/Form/Type/TemplateChoiceType.php b/src/Form/Type/TemplateChoiceType.php index d48024374..683db42ff 100644 --- a/src/Form/Type/TemplateChoiceType.php +++ b/src/Form/Type/TemplateChoiceType.php @@ -23,10 +23,8 @@ * Select a template. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class TemplateChoiceType extends AbstractType +final class TemplateChoiceType extends AbstractType { /** * @var TemplateManagerInterface diff --git a/src/Generator/Mustache.php b/src/Generator/Mustache.php index 41259f68a..8a5ed046e 100644 --- a/src/Generator/Mustache.php +++ b/src/Generator/Mustache.php @@ -18,13 +18,11 @@ * * @author Thomas Rabaix * - * @final since sonata-project/page-bundle 3.26 - * * @deprecated since 3.27, and it will be removed in 4.0. * * NEXT_MAJOR: Remove this class. */ -class Mustache +final class Mustache { public function __construct() { diff --git a/src/Listener/RequestListener.php b/src/Listener/RequestListener.php index 9945fd917..4103ff97b 100644 --- a/src/Listener/RequestListener.php +++ b/src/Listener/RequestListener.php @@ -27,25 +27,23 @@ * cms manager upon user permission. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class RequestListener +final class RequestListener { /** * @var CmsManagerSelectorInterface */ - protected $cmsSelector; + private $cmsSelector; /** * @var SiteSelectorInterface */ - protected $siteSelector; + private $siteSelector; /** * @var DecoratorStrategyInterface */ - protected $decoratorStrategy; + private $decoratorStrategy; /** * @param CmsManagerSelectorInterface $cmsSelector Cms manager selector diff --git a/src/Model/PageManagerInterface.php b/src/Model/PageManagerInterface.php index 7a1243e22..c1e4c02a2 100644 --- a/src/Model/PageManagerInterface.php +++ b/src/Model/PageManagerInterface.php @@ -38,5 +38,10 @@ public function getPageByUrl(SiteInterface $site, $url); */ public function loadPages(SiteInterface $site); + /** + * @return PageInterface[] + */ + public function getHybridPages(SiteInterface $site); + public function fixUrl(PageInterface $page); } diff --git a/src/Model/SnapshotPageProxy.php b/src/Model/SnapshotPageProxy.php index 1cf194a01..3be28ced3 100644 --- a/src/Model/SnapshotPageProxy.php +++ b/src/Model/SnapshotPageProxy.php @@ -17,10 +17,8 @@ * SnapshotPageProxy. * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class SnapshotPageProxy implements SnapshotPageProxyInterface +final class SnapshotPageProxy implements SnapshotPageProxyInterface { /** * @var SnapshotManagerInterface diff --git a/src/Model/Template.php b/src/Model/Template.php index 8a366bc3c..bd7db98a1 100644 --- a/src/Model/Template.php +++ b/src/Model/Template.php @@ -14,13 +14,9 @@ namespace Sonata\PageBundle\Model; /** - * Template. - * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class Template +final class Template { public const TYPE_STATIC = 1; @@ -28,17 +24,17 @@ class Template /** * @var string */ - protected $path; + private $path; /** * @var string */ - protected $name; + private $name; /** * @var array */ - protected $containers; + private $containers; /** * @param string $name @@ -109,7 +105,7 @@ public function getPath() /** * @return array */ - protected function normalize(array $meta) + private function normalize(array $meta) { return [ 'name' => $meta['name'] ?? 'n/a', diff --git a/src/Page/PageServiceManager.php b/src/Page/PageServiceManager.php index bd83fc4d1..0695b32ed 100644 --- a/src/Page/PageServiceManager.php +++ b/src/Page/PageServiceManager.php @@ -26,25 +26,23 @@ * to handle the page rendering but it may also implement an alternate rendering method. * * @author Olivier Paradis - * - * @final since sonata-project/page-bundle 3.26 */ -class PageServiceManager implements PageServiceManagerInterface +final class PageServiceManager implements PageServiceManagerInterface { /** * @var PageServiceInterface[] */ - protected $services = []; + private $services = []; /** * @var PageServiceInterface|null */ - protected $default; + private $default; /** * @var RouterInterface */ - protected $router; + private $router; /** * @param RouterInterface $router Router @@ -109,7 +107,7 @@ public function execute(PageInterface $page, Request $request, array $parameters * * @return Response */ - protected function createResponse(PageInterface $page) + private function createResponse(PageInterface $page) { if ($page->getTarget()) { $page->addHeader('Location', $this->router->generate($page->getTarget())); diff --git a/src/Page/Service/DefaultPageService.php b/src/Page/Service/DefaultPageService.php index 810308602..166e86a57 100644 --- a/src/Page/Service/DefaultPageService.php +++ b/src/Page/Service/DefaultPageService.php @@ -25,10 +25,8 @@ * Note: this service is backward-compatible and functions like the old page renderer class. * * @author Olivier Paradis - * - * @final since sonata-project/page-bundle 3.26 */ -class DefaultPageService extends BasePageService +final class DefaultPageService extends BasePageService { /** * @var TemplateManagerInterface diff --git a/src/Request/RequestFactory.php b/src/Request/RequestFactory.php index c4a48bf24..60ff8be51 100644 --- a/src/Request/RequestFactory.php +++ b/src/Request/RequestFactory.php @@ -15,10 +15,7 @@ use Symfony\Component\HttpFoundation\Request; -/** - * @final since sonata-project/page-bundle 3.26 - */ -class RequestFactory +final class RequestFactory { private static $types = [ 'host' => Request::class, diff --git a/src/Request/SiteRequest.php b/src/Request/SiteRequest.php index 270cf0cd2..c193c1cb8 100644 --- a/src/Request/SiteRequest.php +++ b/src/Request/SiteRequest.php @@ -16,13 +16,9 @@ use Symfony\Component\HttpFoundation\Request as BaseRequest; /** - * SiteRequest. - * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class SiteRequest extends BaseRequest implements SiteRequestInterface +final class SiteRequest extends BaseRequest implements SiteRequestInterface { public function setPathInfo($pathInfo): void { diff --git a/src/Request/SiteRequestContext.php b/src/Request/SiteRequestContext.php index 5572a1482..f1eac59a2 100644 --- a/src/Request/SiteRequestContext.php +++ b/src/Request/SiteRequestContext.php @@ -18,13 +18,9 @@ use Symfony\Component\Routing\RequestContext; /** - * SiteRequestContext. - * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class SiteRequestContext extends RequestContext implements SiteRequestContextInterface +final class SiteRequestContext extends RequestContext implements SiteRequestContextInterface { /** * @var SiteSelectorInterface @@ -73,12 +69,12 @@ public function getBaseUrl() return parent::getBaseUrl(); } - final public function setSite(SiteInterface $site): void + public function setSite(SiteInterface $site): void { $this->site = $site; } - final public function getSite() + public function getSite() { if (!$this->site instanceof SiteInterface) { $this->site = $this->selector->retrieve(); diff --git a/src/Route/CmsPageRouter.php b/src/Route/CmsPageRouter.php index 2561de089..25579caef 100644 --- a/src/Route/CmsPageRouter.php +++ b/src/Route/CmsPageRouter.php @@ -29,30 +29,27 @@ use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\RouterInterface; -/** - * @final since sonata-project/page-bundle 3.26 - */ -class CmsPageRouter implements ChainedRouterInterface +final class CmsPageRouter implements ChainedRouterInterface { /** * @var RequestContext */ - protected $context; + private $context; /** * @var CmsManagerSelectorInterface */ - protected $cmsSelector; + private $cmsSelector; /** * @var SiteSelectorInterface */ - protected $siteSelector; + private $siteSelector; /** * @var RouterInterface */ - protected $router; + private $router; /** * @param CmsManagerSelectorInterface $cmsSelector Cms manager selector @@ -180,7 +177,7 @@ public function match($pathinfo) * * @return string */ - protected function generateFromPage(PageInterface $page, array $parameters = [], $referenceType = self::ABSOLUTE_PATH) + private function generateFromPage(PageInterface $page, array $parameters = [], $referenceType = self::ABSOLUTE_PATH) { // hybrid pages use, by definition, the default routing mechanism if ($page->isHybrid()) { @@ -225,7 +222,7 @@ protected function generateFromPage(PageInterface $page, array $parameters = [], * * @return string */ - protected function generateFromPageSlug(array $parameters = [], $referenceType = self::ABSOLUTE_PATH) + private function generateFromPageSlug(array $parameters = [], $referenceType = self::ABSOLUTE_PATH) { if (!isset($parameters['path'])) { throw new \RuntimeException('Please provide a `path` parameters'); @@ -248,7 +245,7 @@ protected function generateFromPageSlug(array $parameters = [], $referenceType = * * @return string */ - protected function decorateUrl($url, array $parameters = [], $referenceType = self::ABSOLUTE_PATH) + private function decorateUrl($url, array $parameters = [], $referenceType = self::ABSOLUTE_PATH) { if (!$this->context) { throw new \RuntimeException('No context associated to the CmsPageRouter'); @@ -288,7 +285,7 @@ protected function decorateUrl($url, array $parameters = [], $referenceType = se * * @return string The relative target path */ - protected function getRelativePath($basePath, $targetPath) + private function getRelativePath($basePath, $targetPath) { return UrlGenerator::getRelativePath($basePath, $targetPath); } @@ -302,7 +299,7 @@ protected function getRelativePath($basePath, $targetPath) * * @return \Sonata\PageBundle\Model\PageInterface|null */ - protected function getPageByPageAlias($alias) + private function getPageByPageAlias($alias) { $site = $this->siteSelector->retrieve(); @@ -320,7 +317,7 @@ protected function getPageByPageAlias($alias) * * @return string */ - protected function getUrlFromPage(PageInterface $page) + private function getUrlFromPage(PageInterface $page) { return $page->getCustomUrl() ?: $page->getUrl(); } @@ -332,7 +329,7 @@ protected function getUrlFromPage(PageInterface $page) * * @return bool */ - protected function isPageAlias($name) + private function isPageAlias($name) { return \is_string($name) && '_page_alias_' === substr($name, 0, 12); } @@ -344,7 +341,7 @@ protected function isPageAlias($name) * * @return bool */ - protected function isPageSlug($name) + private function isPageSlug($name) { return \is_string($name) && PageInterface::PAGE_ROUTE_CMS_NAME === $name; } diff --git a/src/Route/RoutePageGenerator.php b/src/Route/RoutePageGenerator.php index a69bcb426..dd9e68e08 100644 --- a/src/Route/RoutePageGenerator.php +++ b/src/Route/RoutePageGenerator.php @@ -25,30 +25,28 @@ * This is the page generator service from existing routes. * * @author Vincent Composieux - * - * @final since sonata-project/page-bundle 3.26 */ -class RoutePageGenerator +final class RoutePageGenerator { /** * @var RouterInterface */ - protected $router; + private $router; /** * @var PageManagerInterface */ - protected $pageManager; + private $pageManager; /** * @var DecoratorStrategyInterface */ - protected $decoratorStrategy; + private $decoratorStrategy; /** * @var ExceptionListener */ - protected $exceptionListener; + private $exceptionListener; /** * @param RouterInterface $router A Symfony router service @@ -239,7 +237,7 @@ public function update(SiteInterface $site, ?OutputInterface $output = null, $cl * @param OutputInterface|null $output A Symfony console output instance * @param string $message A string message to output */ - protected function writeln(?OutputInterface $output, $message): void + private function writeln(?OutputInterface $output, $message): void { if ($output instanceof OutputInterface) { $output->writeln($message); diff --git a/src/Service/CleanupSnapshotService.php b/src/Service/CleanupSnapshotService.php index b1e35059e..4c1fa00f3 100644 --- a/src/Service/CleanupSnapshotService.php +++ b/src/Service/CleanupSnapshotService.php @@ -13,6 +13,7 @@ namespace Sonata\PageBundle\Service; +use Sonata\Doctrine\Entity\BaseEntityManager; use Sonata\PageBundle\Model\PageManagerInterface; use Sonata\PageBundle\Model\SiteInterface; use Sonata\PageBundle\Model\SnapshotManagerInterface; @@ -21,6 +22,7 @@ final class CleanupSnapshotService implements CleanupSnapshotBySiteInterface { private SnapshotManagerInterface $snapshotManager; + private PageManagerInterface $pageManager; public function __construct(SnapshotManagerInterface $snapshotManager, PageManagerInterface $pageManager) @@ -31,15 +33,18 @@ public function __construct(SnapshotManagerInterface $snapshotManager, PageManag public function cleanupBySite(SiteInterface $site, int $keepSnapshots): void { - $entityManager = $this->snapshotManager->getEntityManager(); $pages = $this->pageManager->findBy(['site' => $site->getId()]); - $entityManager->beginTransaction(); + if ($this->snapshotManager instanceof BaseEntityManager) { + $this->snapshotManager->getEntityManager()->beginTransaction(); + } foreach ($pages as $page) { $this->snapshotManager->cleanup($page, $keepSnapshots); } - $entityManager->commit(); + if ($this->snapshotManager instanceof BaseEntityManager) { + $this->snapshotManager->getEntityManager()->commit(); + } } } diff --git a/src/Service/CreateSnapshotService.php b/src/Service/CreateSnapshotService.php index c3a092d68..4827ba5ac 100644 --- a/src/Service/CreateSnapshotService.php +++ b/src/Service/CreateSnapshotService.php @@ -13,6 +13,7 @@ namespace Sonata\PageBundle\Service; +use Sonata\Doctrine\Entity\BaseEntityManager; use Sonata\PageBundle\Model\PageInterface; use Sonata\PageBundle\Model\PageManagerInterface; use Sonata\PageBundle\Model\SiteInterface; @@ -42,18 +43,19 @@ public function __construct( public function createBySite(SiteInterface $site): void { - $entityManager = $this->snapshotManager->getEntityManager(); $pages = $this->pageManager->findBy(['site' => $site->getId()]); - // start a transaction - $entityManager->beginTransaction(); + if ($this->snapshotManager instanceof BaseEntityManager) { + $this->snapshotManager->getEntityManager()->beginTransaction(); + } foreach ($pages as $page) { $this->createByPage($page); } - // commit the changes - $entityManager->commit(); + if ($this->snapshotManager instanceof BaseEntityManager) { + $this->snapshotManager->getEntityManager()->beginTransaction(); + } } public function createByPage(PageInterface $page): SnapshotInterface diff --git a/src/Site/HostByLocaleSiteSelector.php b/src/Site/HostByLocaleSiteSelector.php index c816b85f5..c570af5e4 100644 --- a/src/Site/HostByLocaleSiteSelector.php +++ b/src/Site/HostByLocaleSiteSelector.php @@ -16,13 +16,9 @@ use Symfony\Component\HttpKernel\Event\GetResponseEvent; /** - * HostByLocaleSiteSelector. - * * @author Rémi Marseille - * - * @final since sonata-project/page-bundle 3.26 */ -class HostByLocaleSiteSelector extends BaseSiteSelector +final class HostByLocaleSiteSelector extends BaseSiteSelector { public function handleKernelRequest(GetResponseEvent $event): void { diff --git a/src/Site/HostPathByLocaleSiteSelector.php b/src/Site/HostPathByLocaleSiteSelector.php index f13069138..f346a1c19 100644 --- a/src/Site/HostPathByLocaleSiteSelector.php +++ b/src/Site/HostPathByLocaleSiteSelector.php @@ -18,13 +18,9 @@ use Symfony\Component\HttpKernel\Event\GetResponseEvent; /** - * HostPathByLocaleSiteSelector. - * * @author Rémi Marseille - * - * @final since sonata-project/page-bundle 3.26 */ -class HostPathByLocaleSiteSelector extends HostPathSiteSelector +final class HostPathByLocaleSiteSelector extends HostPathSiteSelector { public function handleKernelRequest(GetResponseEvent $event): void { diff --git a/src/Template/Matrix/Parser.php b/src/Template/Matrix/Parser.php index 69d96e309..012cef1ae 100644 --- a/src/Template/Matrix/Parser.php +++ b/src/Template/Matrix/Parser.php @@ -18,10 +18,8 @@ * computes string based template matrix to position/sise. * * @author Raphaël Benitte - * - * @final since sonata-project/page-bundle 3.26 */ -class Parser +final class Parser { /** * @param string $matrix diff --git a/src/Twig/GlobalVariables.php b/src/Twig/GlobalVariables.php index 8e7f9c584..806aadcdc 100644 --- a/src/Twig/GlobalVariables.php +++ b/src/Twig/GlobalVariables.php @@ -18,18 +18,14 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** - * GlobalVariables. - * * @author Thomas Rabaix - * - * @final since sonata-project/page-bundle 3.26 */ -class GlobalVariables +final class GlobalVariables { /** * @var ContainerInterface */ - protected $container; + private $container; /** * @psalm-suppress ContainerDependency diff --git a/tests/Command/BaseCommandTest.php b/tests/Command/BaseCommandTest.php index 260a2e6eb..67af5f0f1 100644 --- a/tests/Command/BaseCommandTest.php +++ b/tests/Command/BaseCommandTest.php @@ -15,7 +15,7 @@ use PHPUnit\Framework\TestCase; use Sonata\PageBundle\Command\BaseCommand; -use Sonata\PageBundle\Entity\SiteManager; +use Sonata\PageBundle\Model\SiteManagerInterface; use Symfony\Component\Console\Input\InputInterface; /** @@ -48,7 +48,7 @@ public function testGetSites(): void $method->setAccessible(true); $input = $this->createMock(InputInterface::class); - $siteManager = $this->createMock(SiteManager::class); + $siteManager = $this->createMock(SiteManagerInterface::class); $this->command->method('getSiteManager')->willReturn($siteManager); diff --git a/tests/Command/CreateBlockContainerCommandTest.php b/tests/Command/CreateBlockContainerCommandTest.php index d0a30c100..6cfcc5150 100644 --- a/tests/Command/CreateBlockContainerCommandTest.php +++ b/tests/Command/CreateBlockContainerCommandTest.php @@ -16,10 +16,10 @@ use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; use Sonata\PageBundle\Command\CreateBlockContainerCommand; -use Sonata\PageBundle\Entity\BlockInteractor; -use Sonata\PageBundle\Entity\BlockManager; -use Sonata\PageBundle\Entity\PageManager; +use Sonata\PageBundle\Model\BlockInteractorInterface; +use Sonata\PageBundle\Model\BlockManagerInterface; use Sonata\PageBundle\Model\PageBlockInterface; +use Sonata\PageBundle\Model\PageManagerInterface; use Sonata\PageBundle\Tests\Model\Page; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -33,17 +33,17 @@ final class CreateBlockContainerCommandTest extends TestCase { /** - * @var Stub&BlockInteractor + * @var Stub&BlockInteractorInterface */ protected $blockInteractor; /** - * @var Stub&PageManager + * @var Stub&PageManagerInterface */ protected $pageManager; /** - * @var Stub&BlockManager + * @var Stub&BlockManagerInterface */ protected $blockManager; @@ -54,9 +54,9 @@ final class CreateBlockContainerCommandTest extends TestCase protected function setUp(): void { - $this->blockInteractor = $this->createStub(BlockInteractor::class); - $this->pageManager = $this->createStub(PageManager::class); - $this->blockManager = $this->createStub(BlockManager::class); + $this->blockInteractor = $this->createStub(BlockInteractorInterface::class); + $this->pageManager = $this->createStub(PageManagerInterface::class); + $this->blockManager = $this->createStub(BlockManagerInterface::class); $this->container = $this->createStub(ContainerInterface::class); $this->container->method('get')->willReturnMap([ diff --git a/tests/Entity/SnapshotManagerTest.php b/tests/Entity/SnapshotManagerTest.php index c40c6eb08..bbc95bd6a 100644 --- a/tests/Entity/SnapshotManagerTest.php +++ b/tests/Entity/SnapshotManagerTest.php @@ -15,84 +15,75 @@ use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\Persistence\ManagerRegistry; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; use Sonata\PageBundle\Entity\BaseSnapshot; use Sonata\PageBundle\Entity\SnapshotManager; use Sonata\PageBundle\Model\PageInterface; use Sonata\PageBundle\Model\SnapshotInterface; +use Sonata\PageBundle\Model\SnapshotPageProxy; +use Sonata\PageBundle\Model\SnapshotPageProxyFactory; use Sonata\PageBundle\Model\SnapshotPageProxyFactoryInterface; use Sonata\PageBundle\Model\SnapshotPageProxyInterface; use Sonata\PageBundle\Model\TransformerInterface; final class SnapshotManagerTest extends TestCase { - public function testSetTemplates(): void - { - $manager = $this->getMockBuilder(SnapshotManager::class) - // we need to set at least one method, which does not need to exist! - // otherwise all methods will be mocked and could not be used! - // we need the real 'setTemplates' method here! - ->setMethods([ - 'fooBar', - ]) - ->disableOriginalConstructor() - ->getMock(); + /** + * @var Stub&ManagerRegistry + */ + private $managerRegistry; - static::assertSame([], $manager->getTemplates()); + /** + * @var MockObject&EntityManagerInterface + */ + private $entityManager; - $manager->setTemplates(['foo' => 'bar']); + /** + * @var SnapshotManager + */ + private $manager; + + protected function setUp(): void + { + $this->managerRegistry = $this->createStub(ManagerRegistry::class); + $this->entityManager = $this->createMock(EntityManagerInterface::class); + + $this->managerRegistry->method('getManagerForClass')->willReturn($this->entityManager); - static::assertSame(['foo' => 'bar'], $manager->getTemplates()); + $this->manager = new SnapshotManager( + BaseSnapshot::class, + $this->managerRegistry, + [], + new SnapshotPageProxyFactory(SnapshotPageProxy::class) + ); } - public function testGetTemplates(): void + public function testSetTemplates(): void { - $manager = $this->getMockBuilder(SnapshotManager::class) - ->setMethods([ - 'setTemplates', - ]) - ->disableOriginalConstructor() - ->getMock(); + static::assertSame([], $this->manager->getTemplates()); - $managerReflection = new \ReflectionClass($manager); - $templates = $managerReflection->getProperty('templates'); - $templates->setAccessible(true); - $templates->setValue($manager, ['foo' => 'bar']); + $this->manager->setTemplates(['foo' => 'bar']); - static::assertSame(['foo' => 'bar'], $manager->getTemplates()); + static::assertSame(['foo' => 'bar'], $this->manager->getTemplates()); } public function testGetTemplate(): void { - $manager = $this->getMockBuilder(SnapshotManager::class) - ->setMethods([ - 'setTemplates', - ]) - ->disableOriginalConstructor() - ->getMock(); + $this->manager->setTemplates(['foo' => 'bar']); - $managerReflection = new \ReflectionClass($manager); - $templates = $managerReflection->getProperty('templates'); - $templates->setAccessible(true); - $templates->setValue($manager, ['foo' => 'bar']); - - static::assertSame('bar', $manager->getTemplate('foo')); + static::assertSame('bar', $this->manager->getTemplate('foo')); } public function testGetTemplatesException(): void { - $manager = $this->getMockBuilder(SnapshotManager::class) - ->setMethods([ - 'setTemplates', - ]) - ->disableOriginalConstructor() - ->getMock(); - $this->expectException('RuntimeException'); $this->expectExceptionMessage('No template references with the code : foo'); - $manager->getTemplate('foo'); + $this->manager->getTemplate('foo'); } /** @@ -122,36 +113,28 @@ public function testEnableSnapshots(): void $date->format('Y-m-d H:i:s') )); - $em = $this->createMock(EntityManagerInterface::class); - - $em->expects(static::once())->method('persist')->with($snapshot); - $em->expects(static::once())->method('flush'); - $em->expects(static::once())->method('getConnection')->willReturn($connection); + $metadata = new ClassMetadataInfo(BaseSnapshot::class); + $metadata->table['name'] = 'page_snapshot'; - $manager = $this->getMockBuilder(SnapshotManager::class) - ->disableOriginalConstructor() - ->setMethods(['getEntityManager', 'getTableName']) - ->getMock(); - - $manager->expects(static::exactly(3))->method('getEntityManager')->willReturn($em); - $manager->expects(static::once())->method('getTableName')->willReturn('page_snapshot'); + $this->entityManager->expects(static::once())->method('getClassMetadata')->willReturn($metadata); + $this->entityManager->expects(static::once())->method('persist')->with($snapshot); + $this->entityManager->expects(static::once())->method('flush'); + $this->entityManager->expects(static::once())->method('getConnection')->willReturn($connection); // When calling method, expects calls - $manager->enableSnapshots([$snapshot], $date); + $this->manager->enableSnapshots([$snapshot], $date); } public function testCreateSnapshotPageProxy(): void { $proxyInterface = $this->createMock(SnapshotPageProxyInterface::class); - $snapshotProxyFactory = $this->createMock(SnapshotPageProxyFactoryInterface::class); - $registry = $this->createMock(ManagerRegistry::class); - $manager = new SnapshotManager(BaseSnapshot::class, $registry, [], $snapshotProxyFactory); - $transformer = $this->createMock(TransformerInterface::class); $snapshot = $this->createMock(SnapshotInterface::class); + $manager = new SnapshotManager(BaseSnapshot::class, $registry, [], $snapshotProxyFactory); + $snapshotProxyFactory->expects(static::once())->method('create') ->with($manager, $transformer, $snapshot) ->willReturn($proxyInterface); @@ -167,20 +150,11 @@ public function testEnableSnapshotsWhenNoSnapshots(): void $connection = $this->createMock(Connection::class); $connection->expects(static::never())->method('query'); - $em = $this->createMock(EntityManagerInterface::class); - $em->expects(static::never())->method('persist'); - $em->expects(static::never())->method('flush'); - $em->expects(static::never())->method('getConnection'); - - $manager = $this->getMockBuilder(SnapshotManager::class) - ->disableOriginalConstructor() - ->setMethods(['getEntityManager', 'getTableName']) - ->getMock(); - - $manager->expects(static::never())->method('getEntityManager'); - $manager->expects(static::never())->method('getTableName'); + $this->entityManager->expects(static::never())->method('persist'); + $this->entityManager->expects(static::never())->method('flush'); + $this->entityManager->expects(static::never())->method('getConnection'); // When calling method, do not expects any calls - $manager->enableSnapshots([]); + $this->manager->enableSnapshots([]); } } diff --git a/tests/Form/Type/TemplateChoiceTypeTest.php b/tests/Form/Type/TemplateChoiceTypeTest.php index c0b2e536b..71cf3e451 100644 --- a/tests/Form/Type/TemplateChoiceTypeTest.php +++ b/tests/Form/Type/TemplateChoiceTypeTest.php @@ -47,7 +47,7 @@ protected function setUp(): void public function testGetOptions(): void { $this->manager->expects(static::atLeastOnce())->method('getAll')->willReturn([ - 'my_template' => $this->getMockTemplate('Template 1'), + 'my_template' => $this->getTemplate('Template 1'), ]); $this->type->configureOptions(new OptionsResolver()); @@ -60,15 +60,8 @@ public function testGetOptions(): void ); } - /** - * Returns the mock template. - */ - protected function getMockTemplate(string $name, string $path = 'path/to/file'): MockObject + private function getTemplate(string $name, string $path = 'path/to/file'): Template { - $template = $this->createMock(Template::class); - $template->method('getName')->willReturn($name); - $template->method('getPath')->willReturn($path); - - return $template; + return new Template($name, $path); } } diff --git a/tests/Listener/ExceptionListenerTest.php b/tests/Listener/ExceptionListenerTest.php index be249d814..8ce97eb67 100644 --- a/tests/Listener/ExceptionListenerTest.php +++ b/tests/Listener/ExceptionListenerTest.php @@ -104,7 +104,7 @@ protected function setUp(): void */ public function testInternalException(): void { - $exception = $this->createMock(InternalErrorException::class); + $exception = new InternalErrorException(); $event = $this->getMockEvent($exception); $this->logger->expects(static::once())->method('error'); diff --git a/tests/Page/TemplateManagerTest.php b/tests/Page/TemplateManagerTest.php index 7471e9583..c1626de3c 100644 --- a/tests/Page/TemplateManagerTest.php +++ b/tests/Page/TemplateManagerTest.php @@ -13,7 +13,6 @@ namespace Sonata\PageBundle\Tests\Page; -use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Sonata\PageBundle\Model\Template; use Sonata\PageBundle\Page\TemplateManager; @@ -26,8 +25,7 @@ final class TemplateManagerTest extends TestCase */ public function testAddSingleTemplate(): void { - /** @var Template|MockObject $template */ - $template = $this->getMockTemplate('template'); + $template = $this->getTemplate('template'); $twig = $this->createMock(Environment::class); $manager = new TemplateManager($twig); @@ -45,8 +43,8 @@ public function testSetAllTemplates(): void $manager = new TemplateManager($twig); $templates = [ - 'test1' => $this->getMockTemplate('template'), - 'test2' => $this->getMockTemplate('template'), + 'test1' => $this->getTemplate('template'), + 'test2' => $this->getTemplate('template'), ]; $manager->setAll($templates); @@ -74,7 +72,7 @@ public function testSetDefaultTemplateCode(): void */ public function testRenderResponse(): void { - $template = $this->getMockTemplate('template', 'path/to/template'); + $template = $this->getTemplate('template', 'path/to/template'); $twig = $this->createMock(Environment::class); $twig @@ -120,7 +118,7 @@ public function testRenderResponseWithoutCode(): void ->with(static::equalTo('path/to/default')) ->willReturn('response'); - $template = $this->getMockTemplate('template', 'path/to/default'); + $template = $this->getTemplate('template', 'path/to/default'); $manager = new TemplateManager($twig); $manager->add('default', $template); $manager->setDefaultTemplateCode('default'); @@ -137,7 +135,7 @@ public function testRenderResponseWithoutCode(): void */ public function testRenderResponseWithDefaultParameters(): void { - $template = $this->getMockTemplate('template', 'path/to/template'); + $template = $this->getTemplate('template', 'path/to/template'); $twig = $this->createMock(Environment::class); $twig->expects(static::once())->method('render') @@ -159,15 +157,8 @@ public function testRenderResponseWithDefaultParameters(): void ); } - /** - * Returns the mock template. - */ - protected function getMockTemplate(string $name, string $path = 'path/to/file'): MockObject + private function getTemplate(string $name, string $path = 'path/to/file'): Template { - $template = $this->createMock(Template::class); - $template->method('getName')->willReturn($name); - $template->method('getPath')->willReturn($path); - - return $template; + return new Template($name, $path); } } diff --git a/tests/Route/RoutePageGeneratorTest.php b/tests/Route/RoutePageGeneratorTest.php index afaa84cc8..6f70edc88 100644 --- a/tests/Route/RoutePageGeneratorTest.php +++ b/tests/Route/RoutePageGeneratorTest.php @@ -17,8 +17,8 @@ use Psr\Log\LoggerInterface; use Sonata\PageBundle\CmsManager\CmsManagerSelectorInterface; use Sonata\PageBundle\CmsManager\DecoratorStrategy; -use Sonata\PageBundle\Entity\PageManager; use Sonata\PageBundle\Listener\ExceptionListener; +use Sonata\PageBundle\Model\PageManagerInterface; use Sonata\PageBundle\Model\SiteInterface; use Sonata\PageBundle\Page\PageServiceManagerInterface; use Sonata\PageBundle\Route\RoutePageGenerator; @@ -160,7 +160,7 @@ protected function getRoutePageGenerator(): RoutePageGenerator { $router = $this->getRouterMock(); - $pageManager = $this->createMock(PageManager::class); + $pageManager = $this->createMock(PageManagerInterface::class); $pageManager->method('create')->willReturn(new Page()); $hybridPageNotExists = new Page(); diff --git a/tests/Service/CleanupSnapshotServiceTest.php b/tests/Service/CleanupSnapshotServiceTest.php index 1017caffe..c5b1bd903 100644 --- a/tests/Service/CleanupSnapshotServiceTest.php +++ b/tests/Service/CleanupSnapshotServiceTest.php @@ -13,12 +13,11 @@ namespace Sonata\PageBundle\Tests\Service; -use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; -use Sonata\PageBundle\Entity\SnapshotManager; use Sonata\PageBundle\Model\PageInterface; use Sonata\PageBundle\Model\PageManagerInterface; use Sonata\PageBundle\Model\Site; +use Sonata\PageBundle\Model\SnapshotManagerInterface; use Sonata\PageBundle\Service\CleanupSnapshotService; class CleanupSnapshotServiceTest extends TestCase @@ -29,10 +28,7 @@ class CleanupSnapshotServiceTest extends TestCase public function testCallCleanupQuery(): void { //Mock - $snapshotManagerMock = $this->createMock(SnapshotManager::class); - $snapshotManagerMock - ->method('getEntityManager') - ->willReturn($this->createMock(EntityManagerInterface::class)); + $snapshotManagerMock = $this->createMock(SnapshotManagerInterface::class); $snapshotManagerMock ->expects(static::once()) diff --git a/tests/Service/CreateSnapshotServiceTest.php b/tests/Service/CreateSnapshotServiceTest.php index 0f2993eea..42bea40ad 100644 --- a/tests/Service/CreateSnapshotServiceTest.php +++ b/tests/Service/CreateSnapshotServiceTest.php @@ -13,13 +13,12 @@ namespace Sonata\PageBundle\Tests\Service; -use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; -use Sonata\PageBundle\Entity\SnapshotManager; use Sonata\PageBundle\Model\PageInterface; use Sonata\PageBundle\Model\PageManagerInterface; use Sonata\PageBundle\Model\SiteInterface; use Sonata\PageBundle\Model\SnapshotInterface; +use Sonata\PageBundle\Model\SnapshotManagerInterface; use Sonata\PageBundle\Model\TransformerInterface; use Sonata\PageBundle\Service\CreateSnapshotService; @@ -28,10 +27,7 @@ final class CreateSnapshotServiceTest extends TestCase public function testCreateBySite(): void { //Mocks - $snapshotManagerMock = $this->createMock(SnapshotManager::class); - $snapshotManagerMock - ->method('getEntityManager') - ->willReturn($this->createMock(EntityManagerInterface::class)); + $snapshotManagerMock = $this->createMock(SnapshotManagerInterface::class); $pageManagerMock = $this->createMock(PageManagerInterface::class); $pageManagerMock diff --git a/tests/Site/BaseLocaleSiteSelectorTest.php b/tests/Site/BaseLocaleSiteSelectorTest.php index fddd2639d..5648a8e7a 100644 --- a/tests/Site/BaseLocaleSiteSelectorTest.php +++ b/tests/Site/BaseLocaleSiteSelectorTest.php @@ -15,7 +15,6 @@ use PHPUnit\Framework\TestCase; use Sonata\PageBundle\Entity\BaseSite; -use Sonata\PageBundle\Site\SiteSelectorInterface; /** * @author Rémi Marseille @@ -23,21 +22,6 @@ abstract class BaseLocaleSiteSelectorTest extends TestCase { /** - * @var SiteSelectorInterface - */ - protected $siteSelector; - - /** - * Cleanups the site selector. - */ - protected function tearDown(): void - { - unset($this->siteSelector); - } - - /** - * Gets fixtures of sites. - * * @return Site[] */ protected function getSites(): array @@ -60,14 +44,6 @@ protected function getSites(): array return $sites; } - - /** - * Gets the site from site selector. - */ - protected function getSite(): ?Site - { - return $this->siteSelector->retrieve(); - } } final class Site extends BaseSite diff --git a/tests/Site/HostByLocaleSiteSelectorTest.php b/tests/Site/HostByLocaleSiteSelectorTest.php index dbbfa5a54..81e31ba52 100644 --- a/tests/Site/HostByLocaleSiteSelectorTest.php +++ b/tests/Site/HostByLocaleSiteSelectorTest.php @@ -13,6 +13,7 @@ namespace Sonata\PageBundle\Tests\Site; +use PHPUnit\Framework\MockObject\MockObject; use Sonata\PageBundle\CmsManager\DecoratorStrategyInterface; use Sonata\PageBundle\Model\SiteManagerInterface; use Sonata\PageBundle\Request\SiteRequest; @@ -26,16 +27,24 @@ */ final class HostByLocaleSiteSelectorTest extends BaseLocaleSiteSelectorTest { + /** + * @var MockObject&SiteManagerInterface + */ + private $siteManager; + + private HostByLocaleSiteSelector $siteSelector; + protected function setUp(): void { - $siteManager = $this->createMock(SiteManagerInterface::class); + $this->siteManager = $this->createMock(SiteManagerInterface::class); $decoratorStrategy = $this->createMock(DecoratorStrategyInterface::class); $seoPage = $this->createMock(SeoPageInterface::class); - $this->siteSelector = $this->getMockBuilder(HostByLocaleSiteSelector::class) - ->setConstructorArgs([$siteManager, $decoratorStrategy, $seoPage]) - ->setMethods(['getSites']) - ->getMock(); + $this->siteSelector = new HostByLocaleSiteSelector( + $this->siteManager, + $decoratorStrategy, + $seoPage + ); } /** @@ -51,10 +60,9 @@ public function testHandleKernelRequestSelectsEn(): void $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $this->siteSelector + $this->siteManager ->expects(static::once()) - ->method('getSites') - ->with($request) + ->method('findBy') ->willReturn($this->getSites()); $this->siteSelector->handleKernelRequest($event); @@ -62,7 +70,7 @@ public function testHandleKernelRequestSelectsEn(): void // Ensure request locale is en static::assertSame('en', $request->attributes->get('_locale')); - $site = $this->getSite(); + $site = $this->siteSelector->retrieve(); // Ensure we retrieved the site "/en" static::assertSame('/en', $site->getRelativePath()); @@ -83,10 +91,9 @@ public function testHandleKernelRequestSelectsFr(): void $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $this->siteSelector + $this->siteManager ->expects(static::once()) - ->method('getSites') - ->with($request) + ->method('findBy') ->willReturn($this->getSites()); $this->siteSelector->handleKernelRequest($event); @@ -94,7 +101,7 @@ public function testHandleKernelRequestSelectsFr(): void // Ensure request locale is fr static::assertSame('fr', $request->attributes->get('_locale')); - $site = $this->getSite(); + $site = $this->siteSelector->retrieve(); // Ensure we retrieved the site "/fr" static::assertSame('/fr', $site->getRelativePath()); diff --git a/tests/Site/HostPathByLocaleSiteSelectorTest.php b/tests/Site/HostPathByLocaleSiteSelectorTest.php index 9d569bd1c..351ae9404 100644 --- a/tests/Site/HostPathByLocaleSiteSelectorTest.php +++ b/tests/Site/HostPathByLocaleSiteSelectorTest.php @@ -13,6 +13,7 @@ namespace Sonata\PageBundle\Tests\Site; +use PHPUnit\Framework\MockObject\MockObject; use Sonata\PageBundle\CmsManager\DecoratorStrategyInterface; use Sonata\PageBundle\Model\SiteManagerInterface; use Sonata\PageBundle\Request\SiteRequest; @@ -27,16 +28,24 @@ */ final class HostPathByLocaleSiteSelectorTest extends BaseLocaleSiteSelectorTest { + /** + * @var MockObject&SiteManagerInterface + */ + private $siteManager; + + private HostPathByLocaleSiteSelector $siteSelector; + protected function setUp(): void { - $siteManager = $this->createMock(SiteManagerInterface::class); + $this->siteManager = $this->createMock(SiteManagerInterface::class); $decoratorStrategy = $this->createMock(DecoratorStrategyInterface::class); $seoPage = $this->createMock(SeoPageInterface::class); - $this->siteSelector = $this->getMockBuilder(HostPathByLocaleSiteSelector::class) - ->setConstructorArgs([$siteManager, $decoratorStrategy, $seoPage]) - ->setMethods(['getSites']) - ->getMock(); + $this->siteSelector = new HostPathByLocaleSiteSelector( + $this->siteManager, + $decoratorStrategy, + $seoPage + ); } /** @@ -52,10 +61,9 @@ public function testHandleKernelRequestRedirectsToEn(): void $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $this->siteSelector + $this->siteManager ->expects(static::once()) - ->method('getSites') - ->with($request) + ->method('findBy') ->willReturn($this->getSites()); $this->siteSelector->handleKernelRequest($event); @@ -63,7 +71,7 @@ public function testHandleKernelRequestRedirectsToEn(): void // Ensure request locale is still null static::assertNull($request->attributes->get('_locale')); - $site = $this->getSite(); + $site = $this->siteSelector->retrieve(); // Ensure no site was retrieved static::assertNull($site); @@ -93,10 +101,9 @@ public function testHandleKernelRequestRedirectsToFr(): void $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $this->siteSelector + $this->siteManager ->expects(static::once()) - ->method('getSites') - ->with($request) + ->method('findBy') ->willReturn($this->getSites()); $this->siteSelector->handleKernelRequest($event); @@ -104,7 +111,7 @@ public function testHandleKernelRequestRedirectsToFr(): void // Ensure request locale is still null static::assertNull($request->attributes->get('_locale')); - $site = $this->getSite(); + $site = $this->siteSelector->retrieve(); // Ensure no site was retrieved static::assertNull($site); diff --git a/tests/Site/SubRequestsSiteSelectorTest.php b/tests/Site/SubRequestsSiteSelectorTest.php index 070dfab28..927ba11bf 100644 --- a/tests/Site/SubRequestsSiteSelectorTest.php +++ b/tests/Site/SubRequestsSiteSelectorTest.php @@ -13,6 +13,7 @@ namespace Sonata\PageBundle\Tests\Site; +use PHPUnit\Framework\MockObject\MockObject; use Sonata\PageBundle\CmsManager\DecoratorStrategy; use Sonata\PageBundle\Model\SiteManagerInterface; use Sonata\PageBundle\Request\SiteRequest; @@ -26,16 +27,24 @@ */ final class SubRequestsSiteSelectorTest extends BaseLocaleSiteSelectorTest { + /** + * @var MockObject&SiteManagerInterface + */ + private $siteManager; + + private HostPathByLocaleSiteSelector $siteSelector; + protected function setUp(): void { - $siteManager = $this->createMock(SiteManagerInterface::class); + $this->siteManager = $this->createMock(SiteManagerInterface::class); $decoratorStrategy = new DecoratorStrategy([], [], []); $seoPage = $this->createMock(SeoPageInterface::class); - $this->siteSelector = $this->getMockBuilder(HostPathByLocaleSiteSelector::class) - ->setConstructorArgs([$siteManager, $decoratorStrategy, $seoPage]) - ->setMethods(['getSites']) - ->getMock(); + $this->siteSelector = new HostPathByLocaleSiteSelector( + $this->siteManager, + $decoratorStrategy, + $seoPage + ); } /** @@ -51,10 +60,9 @@ public function testOnKernelRequestWithMasterDetectEn(): void $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $this->siteSelector + $this->siteManager ->expects(static::once()) - ->method('getSites') - ->with($request) + ->method('findBy') ->willReturn($this->getSites()); $this->siteSelector->onKernelRequest($event); @@ -62,7 +70,7 @@ public function testOnKernelRequestWithMasterDetectEn(): void // Ensure request locale is still null static::assertNull($request->attributes->get('_locale')); - $site = $this->getSite(); + $site = $this->siteSelector->retrieve(); // Ensure no site was retrieved static::assertNull($site); @@ -81,10 +89,9 @@ public function testOnKernelRequestWithMasterDetectFr(): void $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $this->siteSelector + $this->siteManager ->expects(static::once()) - ->method('getSites') - ->with($request) + ->method('findBy') ->willReturn($this->getSites()); $this->siteSelector->onKernelRequest($event); @@ -92,7 +99,7 @@ public function testOnKernelRequestWithMasterDetectFr(): void // Ensure request locale is now fr static::assertSame('fr', $request->attributes->get('_locale')); - $site = $this->getSite(); + $site = $this->siteSelector->retrieve(); // Ensure /fr site was retrieved static::assertNotEmpty($site); @@ -112,10 +119,9 @@ public function testOnKernelRequestWithSubDetectEn(): void $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST); - $this->siteSelector + $this->siteManager ->expects(static::once()) - ->method('getSites') - ->with($request) + ->method('findBy') ->willReturn($this->getSites()); $this->siteSelector->onKernelRequest($event); @@ -123,7 +129,7 @@ public function testOnKernelRequestWithSubDetectEn(): void // Ensure request locale is still null static::assertNull($request->attributes->get('_locale')); - $site = $this->getSite(); + $site = $this->siteSelector->retrieve(); // Ensure no site was retrieved static::assertNull($site); @@ -142,10 +148,9 @@ public function testOnKernelRequestWithSubDetectFr(): void $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST); - $this->siteSelector + $this->siteManager ->expects(static::once()) - ->method('getSites') - ->with($request) + ->method('findBy') ->willReturn($this->getSites()); $this->siteSelector->onKernelRequest($event); @@ -153,7 +158,7 @@ public function testOnKernelRequestWithSubDetectFr(): void // Ensure request locale is now fr static::assertSame('fr', $request->attributes->get('_locale')); - $site = $this->getSite(); + $site = $this->siteSelector->retrieve(); // Ensure /fr site was retrieved static::assertNotEmpty($site);