From bfe764b8b8156c047b5978820bfb75311e2f5fdd Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Wed, 27 Aug 2025 19:00:58 +0200 Subject: [PATCH 01/11] Wip on 5.x --- Controller/AbstractCmsController.php | 2 +- Controller/PageController.php | 2 +- Controller/PostsController.php | 2 +- DependencyInjection/Configuration.php | 2 +- DependencyInjection/OrbitaleCmsExtension.php | 2 +- Entity/Category.php | 35 ++++------- Entity/Page.php | 60 +++++++------------ EventListener/DoctrineMappingListener.php | 2 +- EventListener/LayoutsListener.php | 2 +- Resources/config/doctrine/Category.orm.xml | 26 ++++++++ Resources/config/doctrine/Page.orm.xml | 42 +++++++++++++ Tests/AbstractTestCase.php | 5 +- Tests/Fixtures/App/AppKernel.php | 16 ++++- Tests/Fixtures/App/config/config_test.yaml | 17 ++---- Tests/Fixtures/TestBundle/Entity/Category.php | 8 +-- Tests/Fixtures/TestBundle/Entity/Page.php | 8 +-- .../config/doctrine/Category.orm.xml | 11 ++++ .../Resources/config/doctrine/Page.orm.xml | 12 ++++ Tests/bootstrap.php | 17 ++++-- Tests/phpunit.php | 19 ------ composer.json | 30 +++++----- rector.php | 21 +++++++ 22 files changed, 200 insertions(+), 141 deletions(-) create mode 100644 Resources/config/doctrine/Category.orm.xml create mode 100644 Resources/config/doctrine/Page.orm.xml create mode 100644 Tests/Fixtures/TestBundle/Resources/config/doctrine/Category.orm.xml create mode 100644 Tests/Fixtures/TestBundle/Resources/config/doctrine/Page.orm.xml delete mode 100644 Tests/phpunit.php create mode 100644 rector.php diff --git a/Controller/AbstractCmsController.php b/Controller/AbstractCmsController.php index 91ee3d0..3bfad06 100644 --- a/Controller/AbstractCmsController.php +++ b/Controller/AbstractCmsController.php @@ -52,7 +52,7 @@ protected function getFinalTreeElement(array $slugs, array $elements) if ($element) { // Only for the first iteration $match = $previousElement - ? $element->getParent() && $previousElement->getSlug() === $element->getParent()->getSlug() + ? ($element->getParent() && $previousElement->getSlug() === $element->getParent()->getSlug()) : true; $previousElement = $element; diff --git a/Controller/PageController.php b/Controller/PageController.php index 525e9ba..938dc6a 100644 --- a/Controller/PageController.php +++ b/Controller/PageController.php @@ -30,7 +30,7 @@ public function __construct(PageRepository $pageRepository) $this->pageRepository = $pageRepository; } - public function indexAction(Request $request, string $slugs = '', string $_locale = null): Response + public function indexAction(Request $request, string $slugs = '', ?string $_locale = null): Response { if (preg_match('~/$~', $slugs)) { return $this->redirect($this->generateUrl('orbitale_cms_page', ['slugs' => rtrim($slugs, '/')])); diff --git a/Controller/PostsController.php b/Controller/PostsController.php index 107c2a4..29e0a31 100644 --- a/Controller/PostsController.php +++ b/Controller/PostsController.php @@ -32,7 +32,7 @@ public function __construct(PageRepository $pageRepository) $this->pageRepository = $pageRepository; } - public function indexAction(Request $request, string $slugs = '', string $date = '', string $_date_format = null, string $_locale = null): Response + public function indexAction(Request $request, string $slugs = '', string $date = '', ?string $_date_format = null, ?string $_locale = null): Response { if (!$this->isValidDate($date, $_date_format)) { throw $this->createNotFoundException("Invalid date format provided"); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index d9d94c0..6187263 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -27,7 +27,7 @@ class Configuration implements ConfigurationInterface /** * {@inheritdoc} */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('orbitale_cms'); $rootNode = $treeBuilder->getRootNode(); diff --git a/DependencyInjection/OrbitaleCmsExtension.php b/DependencyInjection/OrbitaleCmsExtension.php index ed6d71d..69814b1 100644 --- a/DependencyInjection/OrbitaleCmsExtension.php +++ b/DependencyInjection/OrbitaleCmsExtension.php @@ -27,7 +27,7 @@ class OrbitaleCmsExtension extends Extension /** * {@inheritdoc} */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); diff --git a/Entity/Category.php b/Entity/Category.php index 4d2a4d3..7aeca49 100644 --- a/Entity/Category.php +++ b/Entity/Category.php @@ -12,17 +12,15 @@ namespace Orbitale\Bundle\CmsBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\ORM\Event\LifecycleEventArgs; -use Doctrine\ORM\Mapping as ORM; +use Doctrine\ORM\Event\PreRemoveEventArgs; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\String\Slugger\AsciiSlugger; use Symfony\Component\Validator\Constraints as Assert; /** * @UniqueEntity("slug") - * @ORM\HasLifecycleCallbacks() - * @ORM\MappedSuperclass(repositoryClass="Orbitale\Bundle\CmsBundle\Repository\CategoryRepository") */ +#[UniqueEntity("slug")] abstract class Category { /** @@ -33,46 +31,44 @@ abstract public function getId(); /** * @var string * - * @ORM\Column(name="name", type="string", length=255) - * * @Assert\Type("string") * @Assert\NotBlank() */ + #[Assert\Type("string")] + #[Assert\NotBlank] protected $name; /** * @var string * - * @ORM\Column(name="slug", type="string", length=255, unique=true) - * * @Assert\Type("string") * @Assert\NotBlank() */ + #[Assert\Type("string")] + #[Assert\NotBlank] protected $slug; /** * @var string * - * @ORM\Column(name="description", type="text", nullable=true) - * * @Assert\Type("string") */ + #[Assert\Type("string")] protected $description; /** * @var bool * - * @ORM\Column(name="enabled", type="boolean") - * * @Assert\Type("bool") */ + #[Assert\Type("bool")] protected $enabled = false; /** * @var Category - * * @Assert\Type(Category::class) */ + #[Assert\Type(Category::class)] protected $parent; /** @@ -217,10 +213,6 @@ public function getTree(string $separator = '/'): string return trim($tree, $separator); } - /** - * @ORM\PrePersist() - * @ORM\PreUpdate() - */ public function updateSlug(): void { if (!$this->slug) { @@ -228,14 +220,9 @@ public function updateSlug(): void } } - /** - * @ORM\PreRemove() - * - * @param LifecycleEventArgs $event - */ - public function onRemove(LifecycleEventArgs $event): void + public function onRemove(PreRemoveEventArgs $event): void { - $em = $event->getEntityManager(); + $em = $event->getObjectManager(); if (count($this->children)) { foreach ($this->children as $child) { $child->setParent(null); diff --git a/Entity/Page.php b/Entity/Page.php index dcb1377..7220281 100644 --- a/Entity/Page.php +++ b/Entity/Page.php @@ -12,17 +12,15 @@ namespace Orbitale\Bundle\CmsBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\ORM\Event\LifecycleEventArgs; -use Doctrine\ORM\Mapping as ORM; +use Doctrine\ORM\Event\PreRemoveEventArgs; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\String\Slugger\AsciiSlugger; use Symfony\Component\Validator\Constraints as Assert; /** * @UniqueEntity("slug") - * @ORM\HasLifecycleCallbacks() - * @ORM\MappedSuperclass(repositoryClass="Orbitale\Bundle\CmsBundle\Repository\PageRepository") */ +#[UniqueEntity("slug")] abstract class Page { /** @@ -33,57 +31,53 @@ abstract public function getId(); /** * @var string * - * @ORM\Column(name="title", type="string", length=255) - * * @Assert\Type("string") * @Assert\NotBlank() */ + #[Assert\Type("string")] + #[Assert\NotBlank] protected $title; /** * @var string * - * @ORM\Column(name="slug", type="string", length=255, unique=true) - * * @Assert\Type("string") * @Assert\NotBlank() */ + #[Assert\Type("string")] + #[Assert\NotBlank] protected $slug; /** * @var string * - * @ORM\Column(name="page_content", type="text", nullable=true) - * * @Assert\Type("string") */ + #[Assert\Type("string")] protected $content; /** * @var string * - * @ORM\Column(name="meta_description", type="string", length=255, nullable=true) - * * @Assert\Type("string") */ + #[Assert\Type("string")] protected $metaDescription; /** * @var string * - * @ORM\Column(name="meta_title", type="string", length=255, nullable=true) - * * @Assert\Type("string") */ + #[Assert\Type("string")] protected $metaTitle; /** * @var string * - * @ORM\Column(name="meta_keywords", type="string", length=255, nullable=true) - * * @Assert\Type("string") */ + #[Assert\Type("string")] protected $metaKeywords; /** @@ -91,69 +85,63 @@ abstract public function getId(); * * @Assert\Type(Category::class) */ + #[Assert\Type(Category::class)] protected $category; /** * @var string * - * @ORM\Column(name="css", type="text", nullable=true) - * * @Assert\Type("string") */ + #[Assert\Type("string")] protected $css; /** * @var string * - * @ORM\Column(name="js", type="text", nullable=true) - * * @Assert\Type("string") */ + #[Assert\Type("string")] protected $js; /** * @var \DateTimeImmutable * - * @ORM\Column(name="created_at", type="datetime_immutable") - * * @Assert\Type(\DateTimeImmutable::class) */ + #[Assert\Type(\DateTimeImmutable::class)] protected $createdAt; /** * @var bool * - * @ORM\Column(name="enabled", type="boolean") - * * @Assert\Type("bool") */ + #[Assert\Type("bool")] protected $enabled = false; /** * @var bool * - * @ORM\Column(name="homepage", type="boolean") - * * @Assert\Type("bool") */ + #[Assert\Type("bool")] protected $homepage = false; /** * @var string * - * @ORM\Column(name="host", type="string", length=255, nullable=true) - * * @Assert\Type("string") */ + #[Assert\Type("string")] protected $host; /** * @var string * - * @ORM\Column(name="locale", type="string", length=6, nullable=true) - * * @Assert\Type("string") */ + #[Assert\Type("string")] protected $locale; /** @@ -161,6 +149,7 @@ abstract public function getId(); * * @Assert\Type(Page::class) */ + #[Assert\Type(Page::class)] protected $parent; /** @@ -380,10 +369,6 @@ public function getTree(string $separator = '/'): string return trim($tree, $separator); } - /** - * @ORM\PrePersist() - * @ORM\PreUpdate() - */ public function updateSlug(): void { if (!$this->slug) { @@ -391,12 +376,9 @@ public function updateSlug(): void } } - /** - * @ORM\PreRemove() - */ - public function onRemove(LifecycleEventArgs $event): void + public function onRemove(PreRemoveEventArgs $event): void { - $em = $event->getEntityManager(); + $em = $event->getObjectManager(); if (count($this->children)) { foreach ($this->children as $child) { $child->setParent(null); diff --git a/EventListener/DoctrineMappingListener.php b/EventListener/DoctrineMappingListener.php index 1ed6ec1..ec0940d 100644 --- a/EventListener/DoctrineMappingListener.php +++ b/EventListener/DoctrineMappingListener.php @@ -38,7 +38,7 @@ public function __construct(string $pageClass, string $categoryClass) $this->categoryClass = $categoryClass; } - public function getSubscribedEvents() + public function getSubscribedEvents(): array { return [Events::loadClassMetadata]; } diff --git a/EventListener/LayoutsListener.php b/EventListener/LayoutsListener.php index 6a8d591..eb36d03 100644 --- a/EventListener/LayoutsListener.php +++ b/EventListener/LayoutsListener.php @@ -39,7 +39,7 @@ public function __construct(array $layouts, Environment $twig) /** * {@inheritdoc} */ - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ KernelEvents::REQUEST => ['setRequestLayout', 1], diff --git a/Resources/config/doctrine/Category.orm.xml b/Resources/config/doctrine/Category.orm.xml new file mode 100644 index 0000000..64630f6 --- /dev/null +++ b/Resources/config/doctrine/Category.orm.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Resources/config/doctrine/Page.orm.xml b/Resources/config/doctrine/Page.orm.xml new file mode 100644 index 0000000..acb212b --- /dev/null +++ b/Resources/config/doctrine/Page.orm.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/AbstractTestCase.php b/Tests/AbstractTestCase.php index 02629cf..705aeb5 100644 --- a/Tests/AbstractTestCase.php +++ b/Tests/AbstractTestCase.php @@ -23,8 +23,9 @@ public function setUp(): void /** @var Connection $c */ $c = self::getContainer()->get(Connection::class); - $c->query('delete from orbitale_cms_pages where 1'); - $c->query('delete from orbitale_cms_categories where 1'); + $method = method_exists($c, 'executeQuery') ? 'executeQuery' : 'query'; + $c->$method('delete from orbitale_cms_pages where 1'); + $c->$method('delete from orbitale_cms_categories where 1'); static::ensureKernelShutdown(); } diff --git a/Tests/Fixtures/App/AppKernel.php b/Tests/Fixtures/App/AppKernel.php index fadcc2c..87c9da7 100644 --- a/Tests/Fixtures/App/AppKernel.php +++ b/Tests/Fixtures/App/AppKernel.php @@ -30,6 +30,11 @@ public function registerBundles(): iterable ]; } + protected function prepareContainer(ContainerBuilder $container): void + { + parent::prepareContainer($container); + } + public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yaml'); @@ -41,16 +46,21 @@ public function registerContainerConfiguration(LoaderInterface $loader): void public function getProjectDir(): string { - return __DIR__; + return \dirname(__DIR__); } public function getCacheDir(): string { - return __DIR__.'/../../../build/cache/'.$this->getEnvironment(); + return $this->getBuildDir().'/cache/'; } public function getLogDir(): string { - return __DIR__.'/../../../build/kernel_logs/'.$this->getEnvironment(); + return $this->getBuildDir().'/kernel_logs/'; + } + + public function getBuildDir(): string + { + return \dirname(__DIR__, 3).'/build/'.$this->getEnvironment(); } } diff --git a/Tests/Fixtures/App/config/config_test.yaml b/Tests/Fixtures/App/config/config_test.yaml index 7abf038..2010124 100644 --- a/Tests/Fixtures/App/config/config_test.yaml +++ b/Tests/Fixtures/App/config/config_test.yaml @@ -1,5 +1,5 @@ parameters: - database_path: '%kernel.project_dir%/../../../build/test.db' + database_path: '%kernel.build_dir%/test.db' framework: test: ~ @@ -7,7 +7,7 @@ framework: secret: secret translator: { fallbacks:['fr'] } router: - resource: "%kernel.project_dir%/config/routing.yaml" + resource: "%kernel.project_dir%/App/config/routing.yaml" utf8: true session: storage_factory_id: session.storage.factory.mock_file @@ -15,7 +15,7 @@ framework: twig: strict_variables: false paths: - - '%kernel.project_dir%/templates/' + - '%kernel.project_dir%/App/templates/' doctrine: dbal: @@ -26,16 +26,7 @@ doctrine: path: '%database_path%' orm: auto_generate_proxy_classes: true - auto_mapping: false - mappings: - TestBundle: - type: annotation - dir: '%kernel.project_dir%/../TestBundle/Entity' - prefix: Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity - OrbitaleCmsBundle: - type: annotation - dir: '%kernel.project_dir%/../../../Entity' - prefix: Orbitale\Bundle\CmsBundle\Entity + auto_mapping: true orbitale_cms: page_class: Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Page diff --git a/Tests/Fixtures/TestBundle/Entity/Category.php b/Tests/Fixtures/TestBundle/Entity/Category.php index 0b47018..06c0138 100644 --- a/Tests/Fixtures/TestBundle/Entity/Category.php +++ b/Tests/Fixtures/TestBundle/Entity/Category.php @@ -13,18 +13,12 @@ use Orbitale\Bundle\CmsBundle\Entity\Category as BaseCategory; use Doctrine\ORM\Mapping as ORM; +use Orbitale\Bundle\CmsBundle\Repository\CategoryRepository; -/** - * @ORM\Entity(repositoryClass="Orbitale\Bundle\CmsBundle\Repository\CategoryRepository") - * @ORM\Table(name="orbitale_cms_categories") - */ class Category extends BaseCategory { /** * @var int - * @ORM\Column(name="id", type="integer") - * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; diff --git a/Tests/Fixtures/TestBundle/Entity/Page.php b/Tests/Fixtures/TestBundle/Entity/Page.php index a3962d5..9fc8a03 100644 --- a/Tests/Fixtures/TestBundle/Entity/Page.php +++ b/Tests/Fixtures/TestBundle/Entity/Page.php @@ -13,18 +13,12 @@ use Orbitale\Bundle\CmsBundle\Entity\Page as BasePage; use Doctrine\ORM\Mapping as ORM; +use Orbitale\Bundle\CmsBundle\Repository\PageRepository; -/** - * @ORM\Entity(repositoryClass="Orbitale\Bundle\CmsBundle\Repository\PageRepository") - * @ORM\Table(name="orbitale_cms_pages") - */ class Page extends BasePage { /** * @var int - * @ORM\Column(name="id", type="integer") - * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; diff --git a/Tests/Fixtures/TestBundle/Resources/config/doctrine/Category.orm.xml b/Tests/Fixtures/TestBundle/Resources/config/doctrine/Category.orm.xml new file mode 100644 index 0000000..50d30a3 --- /dev/null +++ b/Tests/Fixtures/TestBundle/Resources/config/doctrine/Category.orm.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/Tests/Fixtures/TestBundle/Resources/config/doctrine/Page.orm.xml b/Tests/Fixtures/TestBundle/Resources/config/doctrine/Page.orm.xml new file mode 100644 index 0000000..86ecf99 --- /dev/null +++ b/Tests/Fixtures/TestBundle/Resources/config/doctrine/Page.orm.xml @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index ae1ac37..b829291 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -14,6 +14,7 @@ use Orbitale\Bundle\CmsBundle\Tests\Fixtures\App\AppKernel; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Filesystem\Filesystem; @@ -28,17 +29,22 @@ (static function(){ $fs = new Filesystem(); + putenv('DATABASE_MAPPING_TYPE=attribute'); + $_SERVER['DATABASE_MAPPING_TYPE'] = 'attribute'; + $_ENV['DATABASE_MAPPING_TYPE'] = 'attribute'; + + $kernel = new AppKernel('test', true); + // Remove build dir files - if (is_dir(__DIR__.'/../build')) { + if (is_dir($kernel->getBuildDir())) { echo "Removing files in the build directory.\n".__DIR__."\n"; try { - $fs->remove(__DIR__.'/../build'); + $fs->remove($kernel->getBuildDir()); } catch (Exception $e) { fwrite(STDERR, $e->getMessage()); } } - $kernel = new AppKernel('test', true); $kernel->boot(); $databaseFile = $kernel->getContainer()->getParameter('database_path'); @@ -49,8 +55,9 @@ $application = new Application($kernel); $application->setAutoExit(false); - $application->run(new ArrayInput(['command' => 'doctrine:database:create'])); - $application->run(new ArrayInput(['command' => 'doctrine:schema:create'])); + $out = new ConsoleOutput(); + $application->run(new ArrayInput(['command' => 'doctrine:database:create']), $out); + $application->run(new ArrayInput(['command' => 'doctrine:schema:update', '--dump-sql' => true, '--force' => true, '--complete' => true]), $out); $kernel->shutdown(); })(); diff --git a/Tests/phpunit.php b/Tests/phpunit.php deleted file mode 100644 index 572ca7d..0000000 --- a/Tests/phpunit.php +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env php -paths([ + __DIR__ . '/Entity', + ]); + + $rectorConfig->sets([ + \Rector\Doctrine\Set\DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES, + \Rector\Symfony\Set\SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES, + \Rector\Symfony\Set\SensiolabsSetList::ANNOTATIONS_TO_ATTRIBUTES, + ]); + $rectorConfig->ruleWithConfiguration(AnnotationToAttributeRector::class, [ + new AnnotationToAttribute(\Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity::class), + new AnnotationToAttribute(\Ibericode\Vat\Bundle\Validator\Constraints\VatNumber::class), + ]); +}; From 1bc793c968eb2cf9818a727a8e97077798fd1eaa Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Thu, 28 Aug 2025 10:00:24 +0200 Subject: [PATCH 02/11] Finish fixing tests --- .github/workflows/php.yml | 18 +++++++---- Resources/config/doctrine/Category.orm.xml | 1 - Resources/config/doctrine/Page.orm.xml | 11 ++++--- Resources/config/services.yaml | 4 ++- Tests/AbstractTestCase.php | 32 +++++++++++++++---- Tests/Fixtures/App/AppKernel.php | 2 +- .../config/doctrine/Category.orm.xml | 4 +-- .../Resources/config/doctrine/Page.orm.xml | 4 +-- Tests/bootstrap.php | 26 +-------------- 9 files changed, 52 insertions(+), 50 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 4059f65..eb6cdaa 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -11,19 +11,23 @@ jobs: php-version: - '7.3' - '7.4' - - '8.0' - '8.1' + - '8.2' + - '8.3' + - '8.4' symfony-version: - - '5.3' - '5.4' - - '6.0' + - '6.4' + - '7.3' exclude: - - php-version: 7.3 - symfony-version: 6.0 - - php-version: 7.4 - symfony-version: 6.0 + - { php-version: 7.3, symfony-version: 6.0 } + - { php-version: 7.4, symfony-version: 6.0 } + + - { php-version: 7.3, symfony-version: 7.3 } + - { php-version: 7.4, symfony-version: 7.3 } + - { php-version: 8.1, symfony-version: 7.3 } name: PHP ${{ matrix.php-version }} and Symfony ${{ matrix.symfony-version }} steps: diff --git a/Resources/config/doctrine/Category.orm.xml b/Resources/config/doctrine/Category.orm.xml index 64630f6..bd29078 100644 --- a/Resources/config/doctrine/Category.orm.xml +++ b/Resources/config/doctrine/Category.orm.xml @@ -6,7 +6,6 @@ diff --git a/Resources/config/doctrine/Page.orm.xml b/Resources/config/doctrine/Page.orm.xml index acb212b..8b16016 100644 --- a/Resources/config/doctrine/Page.orm.xml +++ b/Resources/config/doctrine/Page.orm.xml @@ -6,7 +6,6 @@ @@ -18,13 +17,15 @@ + + - - - + + + - + diff --git a/Resources/config/services.yaml b/Resources/config/services.yaml index 7a2ce17..cb65321 100644 --- a/Resources/config/services.yaml +++ b/Resources/config/services.yaml @@ -45,7 +45,9 @@ services: - '%orbitale_cms.page_class%' - '%orbitale_cms.category_class%' tags: - - doctrine.event_subscriber + - name: doctrine.event_listener + event: loadClassMetadata + priority: 100 Orbitale\Bundle\CmsBundle\Repository\PageRepository: factory: ['@doctrine.orm.entity_manager', 'getRepository'] diff --git a/Tests/AbstractTestCase.php b/Tests/AbstractTestCase.php index 705aeb5..35526d8 100644 --- a/Tests/AbstractTestCase.php +++ b/Tests/AbstractTestCase.php @@ -11,9 +11,14 @@ namespace Orbitale\Bundle\CmsBundle\Tests; -use Doctrine\DBAL\Connection; use Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Page; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\Console\Output\BufferedOutput; +use Symfony\Component\Console\Output\ConsoleOutput; +use Symfony\Component\Console\Output\NullOutput; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Bundle\FrameworkBundle\Console\Application; +use Symfony\Component\Console\Input\ArrayInput; class AbstractTestCase extends WebTestCase { @@ -21,11 +26,26 @@ public function setUp(): void { static::bootKernel(); - /** @var Connection $c */ - $c = self::getContainer()->get(Connection::class); - $method = method_exists($c, 'executeQuery') ? 'executeQuery' : 'query'; - $c->$method('delete from orbitale_cms_pages where 1'); - $c->$method('delete from orbitale_cms_categories where 1'); + $databaseFile = self::$kernel->getContainer()->getParameter('database_path'); + + $fs = new Filesystem(); + + if ($fs->exists($databaseFile)) { + $fs->remove($databaseFile); + } + + $application = new Application(self::$kernel); + $application->setAutoExit(false); + $out = new BufferedOutput(); + $returns = []; + $returns[] = $application->run(new ArrayInput(['command' => 'doctrine:database:create']), $out); + $returns[] = $application->run(new ArrayInput(['command' => 'doctrine:schema:update', '--dump-sql' => true, '--complete' => true]), $out); + $returns[] = $application->run(new ArrayInput(['command' => 'doctrine:schema:create']), $out); + + if (\in_array(1, $returns, true)) { + self::fail(\sprintf("A database setup command has failed:\n%s", $out->fetch())); + } + static::ensureKernelShutdown(); } diff --git a/Tests/Fixtures/App/AppKernel.php b/Tests/Fixtures/App/AppKernel.php index 87c9da7..a04b5e3 100644 --- a/Tests/Fixtures/App/AppKernel.php +++ b/Tests/Fixtures/App/AppKernel.php @@ -61,6 +61,6 @@ public function getLogDir(): string public function getBuildDir(): string { - return \dirname(__DIR__, 3).'/build/'.$this->getEnvironment(); + return \dirname(__DIR__, 3).'/build/'; } } diff --git a/Tests/Fixtures/TestBundle/Resources/config/doctrine/Category.orm.xml b/Tests/Fixtures/TestBundle/Resources/config/doctrine/Category.orm.xml index 50d30a3..56940e2 100644 --- a/Tests/Fixtures/TestBundle/Resources/config/doctrine/Category.orm.xml +++ b/Tests/Fixtures/TestBundle/Resources/config/doctrine/Category.orm.xml @@ -3,8 +3,8 @@ xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> - - + + diff --git a/Tests/Fixtures/TestBundle/Resources/config/doctrine/Page.orm.xml b/Tests/Fixtures/TestBundle/Resources/config/doctrine/Page.orm.xml index 86ecf99..6d8070d 100644 --- a/Tests/Fixtures/TestBundle/Resources/config/doctrine/Page.orm.xml +++ b/Tests/Fixtures/TestBundle/Resources/config/doctrine/Page.orm.xml @@ -3,8 +3,8 @@ xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> - - + + diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index b829291..f4a8193 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -9,13 +9,7 @@ * file that was distributed with this source code. */ -use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; -use Doctrine\Bundle\DoctrineBundle\Command\Proxy\CreateSchemaDoctrineCommand; use Orbitale\Bundle\CmsBundle\Tests\Fixtures\App\AppKernel; -use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Component\Console\Input\ArrayInput; -use Symfony\Component\Console\Output\ConsoleOutput; -use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Filesystem\Filesystem; $file = __DIR__.'/../vendor/autoload.php'; @@ -29,10 +23,6 @@ (static function(){ $fs = new Filesystem(); - putenv('DATABASE_MAPPING_TYPE=attribute'); - $_SERVER['DATABASE_MAPPING_TYPE'] = 'attribute'; - $_ENV['DATABASE_MAPPING_TYPE'] = 'attribute'; - $kernel = new AppKernel('test', true); // Remove build dir files @@ -44,20 +34,6 @@ fwrite(STDERR, $e->getMessage()); } } - - $kernel->boot(); - - $databaseFile = $kernel->getContainer()->getParameter('database_path'); - - if ($fs->exists($databaseFile)) { - $fs->remove($databaseFile); - } - - $application = new Application($kernel); - $application->setAutoExit(false); - $out = new ConsoleOutput(); - $application->run(new ArrayInput(['command' => 'doctrine:database:create']), $out); - $application->run(new ArrayInput(['command' => 'doctrine:schema:update', '--dump-sql' => true, '--force' => true, '--complete' => true]), $out); - $kernel->shutdown(); + unset($kernel); })(); From 8a086687c5aa4f5b684d441838d3dc665ac71b3d Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Thu, 28 Aug 2025 10:03:20 +0200 Subject: [PATCH 03/11] Attempt at fixing CI --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index eb6cdaa..6b2b4f2 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -43,7 +43,7 @@ jobs: - id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - uses: actions/cache@v1 + - uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} From ef4dd605dba418697e35215706b1818b5e450475 Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Thu, 28 Aug 2025 10:09:05 +0200 Subject: [PATCH 04/11] Update symfony version check in CI --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 6b2b4f2..cdf9749 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -51,7 +51,7 @@ jobs: - name: Update Symfony version run: | - sed -i composer.json -e 's/\^5\.0\(.[0-9]\+\)\?[|]\^6\.0/${{ matrix.symfony-version }}.*/g' + sed -i composer.json -e 's/\^5.3[|]\^6.0[|]\^7.0/${{ matrix.symfony-version }}.*/g' - run: composer install From f443b9ca926fa3ea157f0b21af45781b61dd9604 Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Thu, 28 Aug 2025 10:44:56 +0200 Subject: [PATCH 05/11] disable session in tests --- .gitignore | 1 + Tests/AbstractTestCase.php | 7 +++++-- Tests/Fixtures/App/config/config_test.yaml | 1 + Tests/bootstrap.php | 1 - composer.json | 4 ++-- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 45aba60..a86b5db 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ vendor/ build/ .phpunit phpunit.xml + diff --git a/Tests/AbstractTestCase.php b/Tests/AbstractTestCase.php index 35526d8..4c0095b 100644 --- a/Tests/AbstractTestCase.php +++ b/Tests/AbstractTestCase.php @@ -14,8 +14,6 @@ use Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Page; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\Console\Output\BufferedOutput; -use Symfony\Component\Console\Output\ConsoleOutput; -use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Filesystem\Filesystem; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArrayInput; @@ -23,6 +21,11 @@ class AbstractTestCase extends WebTestCase { public function setUp(): void + { + self::installDatabase(); + } + + public static function installDatabase(): void { static::bootKernel(); diff --git a/Tests/Fixtures/App/config/config_test.yaml b/Tests/Fixtures/App/config/config_test.yaml index 2010124..a3e7cb1 100644 --- a/Tests/Fixtures/App/config/config_test.yaml +++ b/Tests/Fixtures/App/config/config_test.yaml @@ -10,6 +10,7 @@ framework: resource: "%kernel.project_dir%/App/config/routing.yaml" utf8: true session: + handler_id: null storage_factory_id: session.storage.factory.mock_file twig: diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index f4a8193..b4abea8 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -34,6 +34,5 @@ fwrite(STDERR, $e->getMessage()); } } - $kernel->shutdown(); unset($kernel); })(); diff --git a/composer.json b/composer.json index 5529310..21b006b 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "license": "MIT", "require": { "php": ">=7.3", - "doctrine/annotations": "^1.8", + "doctrine/annotations": "^1.8|^2.0", "doctrine/doctrine-bundle": "^2.0", "doctrine/orm": "^2.5.1", "symfony/asset": "^5.3|^6.0|^7.0", @@ -51,7 +51,7 @@ ], "extra": { "branch-alias": { - "dev-master": "4.x-dev" + "dev-master": "5.x-dev" } } } From ab70c52ffc1fe836037a9b43ce239e3b83581c33 Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Thu, 28 Aug 2025 10:56:19 +0200 Subject: [PATCH 06/11] Fix symfony version in ci --- .github/workflows/php.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index cdf9749..d746174 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -22,8 +22,8 @@ jobs: - '7.3' exclude: - - { php-version: 7.3, symfony-version: 6.0 } - - { php-version: 7.4, symfony-version: 6.0 } + - { php-version: 7.3, symfony-version: 6.4 } + - { php-version: 7.4, symfony-version: 6.4 } - { php-version: 7.3, symfony-version: 7.3 } - { php-version: 7.4, symfony-version: 7.3 } From aa0e5e6b336d5cc2e6b786f1d5fce0a1934484cb Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Thu, 28 Aug 2025 11:11:50 +0200 Subject: [PATCH 07/11] Remove php7 compatibility --- .github/workflows/php.yml | 7 ------- composer.json | 3 ++- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index d746174..f3fd132 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -9,8 +9,6 @@ jobs: strategy: matrix: php-version: - - '7.3' - - '7.4' - '8.1' - '8.2' - '8.3' @@ -22,11 +20,6 @@ jobs: - '7.3' exclude: - - { php-version: 7.3, symfony-version: 6.4 } - - { php-version: 7.4, symfony-version: 6.4 } - - - { php-version: 7.3, symfony-version: 7.3 } - - { php-version: 7.4, symfony-version: 7.3 } - { php-version: 8.1, symfony-version: 7.3 } name: PHP ${{ matrix.php-version }} and Symfony ${{ matrix.symfony-version }} diff --git a/composer.json b/composer.json index 21b006b..f4fa621 100644 --- a/composer.json +++ b/composer.json @@ -6,10 +6,11 @@ "homepage": "https://github.com/Orbitale/CmsBundle", "license": "MIT", "require": { - "php": ">=7.3", + "php": ">=8.1", "doctrine/annotations": "^1.8|^2.0", "doctrine/doctrine-bundle": "^2.0", "doctrine/orm": "^2.5.1", + "doctrine/dbal": "^3.0|^4.0", "symfony/asset": "^5.3|^6.0|^7.0", "symfony/config": "^5.3|^6.0|^7.0", "symfony/dependency-injection": "^5.3|^6.0|^7.0", From 14a52d563ca4c5c6cac1cb7e5c8a8d7f27ee70f0 Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Thu, 28 Aug 2025 11:22:34 +0200 Subject: [PATCH 08/11] Drop support for sf 5 --- .github/workflows/php.yml | 1 - composer.json | 30 +++++++++++++++--------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index f3fd132..8c4eda2 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -15,7 +15,6 @@ jobs: - '8.4' symfony-version: - - '5.4' - '6.4' - '7.3' diff --git a/composer.json b/composer.json index f4fa621..c3422d5 100644 --- a/composer.json +++ b/composer.json @@ -11,24 +11,24 @@ "doctrine/doctrine-bundle": "^2.0", "doctrine/orm": "^2.5.1", "doctrine/dbal": "^3.0|^4.0", - "symfony/asset": "^5.3|^6.0|^7.0", - "symfony/config": "^5.3|^6.0|^7.0", - "symfony/dependency-injection": "^5.3|^6.0|^7.0", - "symfony/framework-bundle": "^5.3|^6.0|^7.0", - "symfony/http-foundation": "^5.3|^6.0|^7.0", - "symfony/http-kernel": "^5.3|^6.0|^7.0", - "symfony/translation": "^5.3|^6.0|^7.0", - "symfony/twig-bundle": "^5.3|^6.0|^7.0", - "symfony/validator": "^5.3|^6.0|^7.0", + "symfony/asset": "^6.4|^7.0", + "symfony/config": "^6.4|^7.0", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/framework-bundle": "^6.4|^7.0", + "symfony/http-foundation": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0", + "symfony/translation": "^6.4|^7.0", + "symfony/twig-bundle": "^6.4|^7.0", + "symfony/validator": "^6.4|^7.0", "twig/twig": "^2.7|^3.0", - "symfony/string": "^5.3|^6.0|^7.0" + "symfony/string": "^6.4|^7.0" }, "require-dev": { - "symfony/browser-kit": "^5.3|^6.0|^7.0", - "symfony/css-selector": "^5.3|^6.0|^7.0", - "symfony/dom-crawler": "^5.3|^6.0|^7.0", - "symfony/phpunit-bridge": "^5.3|^6.0|^7.0", - "symfony/yaml": "^5.3|^6.0|^7.0" + "symfony/browser-kit": "^6.4|^7.0", + "symfony/css-selector": "^6.4|^7.0", + "symfony/dom-crawler": "^6.4|^7.0", + "symfony/phpunit-bridge": "^6.4|^7.0", + "symfony/yaml": "^6.4|^7.0" }, "suggest": { "javiereguiluz/easyadmin-bundle": "To manage your pages directly inside your CMS (view documentation)." From e5d1756e55bdf39d73ed5f252ffc6d8f6d7143de Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Thu, 28 Aug 2025 11:34:58 +0200 Subject: [PATCH 09/11] CS fix --- .gitignore | 1 - .php-cs-fixer.php | 105 ++++++++++ Controller/AbstractCmsController.php | 36 ++-- Controller/CategoryController.php | 54 +++-- Controller/PageController.php | 41 ++-- Controller/PostsController.php | 30 +-- DependencyInjection/Configuration.php | 161 +++++++-------- DependencyInjection/OrbitaleCmsExtension.php | 31 +-- Entity/Category.php | 77 ++++---- Entity/Page.php | 88 +++++---- EventListener/DoctrineMappingListener.php | 23 +-- EventListener/LayoutsListener.php | 30 +-- Repository/AbstractCmsRepository.php | 23 ++- Repository/CategoryRepository.php | 18 +- Repository/PageRepository.php | 50 +++-- Resources/config/doctrine/Category.orm.xml | 2 +- Resources/config/doctrine/Page.orm.xml | 2 +- Tests/AbstractTestCase.php | 30 +-- Tests/Controller/CategoryControllerTest.php | 45 +++-- Tests/Controller/PageControllerTest.php | 187 +++++++++--------- Tests/Controller/PostsControllerTest.php | 15 +- .../OrbitaleCmsExtensionTest.php | 45 +++-- Tests/Entity/CategoryTest.php | 55 +++--- Tests/Entity/PageTest.php | 47 ++--- Tests/EventListener/LayoutsListenerTest.php | 16 +- Tests/Fixtures/App/AppKernel.php | 28 +-- Tests/Fixtures/TestBundle/Entity/Category.php | 18 +- Tests/Fixtures/TestBundle/Entity/Page.php | 18 +- .../config/doctrine/Category.orm.xml | 3 +- .../Resources/config/doctrine/Page.orm.xml | 2 +- Tests/Fixtures/TestBundle/TestBundle.php | 21 +- Tests/bootstrap.php | 25 +-- Twig/CmsExtension.php | 16 +- rector.php | 21 -- 34 files changed, 747 insertions(+), 617 deletions(-) create mode 100644 .php-cs-fixer.php delete mode 100644 rector.php diff --git a/.gitignore b/.gitignore index a86b5db..45aba60 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ vendor/ build/ .phpunit phpunit.xml - diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..f6ebd33 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,105 @@ + and Studio Agate. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +$header = <<<'HEADER' +This file is part of the OrbitaleCmsBundle package. + +(c) Alexandre Rock Ancelet + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. +HEADER; + +$finder = PhpCsFixer\Finder::create() + ->exclude([ + '.idea/', + 'build/', + 'vendor', + ]) + ->in([ + __DIR__.'/Controller/', + __DIR__.'/DependencyInjection/', + __DIR__.'/Entity/', + __DIR__.'/EventListener/', + __DIR__.'/Repository/', + __DIR__.'/Resources/', + __DIR__.'/templates/', + __DIR__.'/Tests/', + __DIR__.'/Twig/', + ]) + ->files([ + __DIR__.'/OrbitaleCmsBundle.php', + ]) +; + +return (new PhpCsFixer\Config()) + ->setRules([ + 'header_comment' => [ + 'header' => $header, + ], + // Enabled rules + '@DoctrineAnnotation' => true, + '@Symfony' => true, + '@Symfony:risky' => true, + '@PhpCsFixer' => true, + '@PHP70Migration' => true, + '@PHP70Migration:risky' => true, + '@PHP71Migration' => true, + '@PHP71Migration:risky' => true, + '@PHP73Migration' => true, + 'compact_nullable_typehint' => true, + 'fully_qualified_strict_types' => true, + 'heredoc_to_nowdoc' => true, + 'linebreak_after_opening_tag' => true, + 'logical_operators' => true, + 'native_function_invocation' => [ + 'include' => ['@all'], + 'exclude' => ['uuid_create'], + ], + 'no_null_property_initialization' => true, + 'no_php4_constructor' => true, + 'echo_tag_syntax' => ['format' => 'long'], + 'no_superfluous_phpdoc_tags' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'ordered_imports' => true, + 'simplified_null_return' => true, + 'strict_param' => true, + 'php_unit_test_case_static_method_calls' => [ + 'call_type' => 'static', + ], + 'array_syntax' => [ + 'syntax' => 'short', + ], + // Overrides default doctrine rule using ":" as character + 'doctrine_annotation_array_assignment' => [ + 'operator' => '=', + ], + 'multiline_whitespace_before_semicolons' => [ + 'strategy' => 'new_line_for_chained_calls', + ], + + // Disabled rules + 'mb_str_functions' => false, // When we know the input, it's okay to not use mb_, because it's less performant + 'increment_style' => false, // Because "++$i" is not always necessary… + 'non_printable_character' => false, // Because I love using non breakable spaces in test methods ♥ + 'php_unit_test_class_requires_covers' => false, // Because we don't use @covers + 'php_unit_internal_class' => false, // Why would this be necessary? + 'heredoc_indentation' => false, // Well, it breaks the "visual" aspects of some strings... + ]) + ->setRiskyAllowed(true) + ->setIndent(' ') + ->setLineEnding("\n") + ->setUsingCache(true) + ->setFinder($finder) +; diff --git a/Controller/AbstractCmsController.php b/Controller/AbstractCmsController.php index 3bfad06..6571585 100644 --- a/Controller/AbstractCmsController.php +++ b/Controller/AbstractCmsController.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Controller; @@ -24,31 +26,31 @@ abstract class AbstractCmsController extends AbstractController * This also prevents things like /children/parent to work, * as it should be /parent/children. * - * @param array $slugs - * @param Page[]|Category[] $elements + * @param Category[]|Page[] $elements * * @return Category|Page */ protected function getFinalTreeElement(array $slugs, array $elements) { // Will check that slugs and elements match - $slugsElements = array_keys($elements); - $sortedSlugs = $slugs; - sort($sortedSlugs); - sort($slugsElements); + $slugsElements = \array_keys($elements); + $sortedSlugs = $slugs; + \sort($sortedSlugs); + \sort($slugsElements); - if ($sortedSlugs !== $slugsElements || !count($slugs) || count($slugs) !== count($elements)) { + if ($sortedSlugs !== $slugsElements || !\count($slugs) || \count($slugs) !== \count($elements)) { throw $this->createNotFoundException(); } - /** @var Page|Category $element */ + /** @var Category|Page $element */ $element = null; - /** @var Page|Category $previousElement */ + + /** @var Category|Page $previousElement */ $previousElement = null; foreach ($slugs as $slug) { $element = $elements[$slug] ?? null; - $match = false; + $match = false; if ($element) { // Only for the first iteration $match = $previousElement diff --git a/Controller/CategoryController.php b/Controller/CategoryController.php index 9f35077..6330e21 100644 --- a/Controller/CategoryController.php +++ b/Controller/CategoryController.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Controller; @@ -27,19 +29,13 @@ public function __construct(CategoryRepository $categoryRepository, PageReposito $this->pageRepository = $pageRepository; } - /** - * @param string $slugs - * @param Request $request - * - * @return Response - */ public function indexAction(Request $request, string $slugs = ''): Response { - if (preg_match('#/$#', $slugs)) { - return $this->redirect($this->generateUrl('orbitale_cms_category', ['slugs' => rtrim($slugs, '/')])); + if (\preg_match('#/$#', $slugs)) { + return $this->redirect($this->generateUrl('orbitale_cms_category', ['slugs' => \rtrim($slugs, '/')])); } - $slugsArray = preg_split('~/~', $slugs, -1, PREG_SPLIT_NO_EMPTY); + $slugsArray = \preg_split('~/~', $slugs, -1, \PREG_SPLIT_NO_EMPTY); $categories = $this->categoryRepository->findFrontCategories($slugsArray); @@ -47,12 +43,12 @@ public function indexAction(Request $request, string $slugs = ''): Response $validOrderFields = ['createdAt', 'id', 'title', 'content']; - $limit = $request->query->get('limit', 10); - $page = $request->query->get('page', 1); - $order = $request->query->get('order', 'asc'); - $orderBy = $request->query->get('order_by', current($validOrderFields)); - if (!in_array($orderBy, $validOrderFields, true)) { - $orderBy = current($validOrderFields); + $limit = $request->query->get('limit', 10); + $page = $request->query->get('page', 1); + $order = $request->query->get('order', 'asc'); + $orderBy = $request->query->get('order_by', \current($validOrderFields)); + if (!\in_array($orderBy, $validOrderFields, true)) { + $orderBy = \current($validOrderFields); } $pages = $this->pageRepository->findByCategory( @@ -64,15 +60,15 @@ public function indexAction(Request $request, string $slugs = ''): Response ); return $this->render('@OrbitaleCms/Front/category.html.twig', [ - 'category' => $category, + 'category' => $category, 'categories' => $categories, - 'pages' => $pages, - 'pagesCount' => count($pages), - 'filters' => [ - 'page' => $page, - 'limit' => $limit, + 'pages' => $pages, + 'pagesCount' => \count($pages), + 'filters' => [ + 'page' => $page, + 'limit' => $limit, 'orderBy' => $orderBy, - 'order' => $order, + 'order' => $order, ], ]); } diff --git a/Controller/PageController.php b/Controller/PageController.php index 938dc6a..1f6d71c 100644 --- a/Controller/PageController.php +++ b/Controller/PageController.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Controller; @@ -32,14 +34,14 @@ public function __construct(PageRepository $pageRepository) public function indexAction(Request $request, string $slugs = '', ?string $_locale = null): Response { - if (preg_match('~/$~', $slugs)) { - return $this->redirect($this->generateUrl('orbitale_cms_page', ['slugs' => rtrim($slugs, '/')])); + if (\preg_match('~/$~', $slugs)) { + return $this->redirect($this->generateUrl('orbitale_cms_page', ['slugs' => \rtrim($slugs, '/')])); } $this->request = $request; $this->request->setLocale($_locale ?: $this->request->getLocale()); - $slugsArray = preg_split('~/~', $slugs, -1, PREG_SPLIT_NO_EMPTY); + $slugsArray = \preg_split('~/~', $slugs, -1, \PREG_SPLIT_NO_EMPTY); $pages = $this->getPages($slugsArray); @@ -60,7 +62,7 @@ public function indexAction(Request $request, string $slugs = '', ?string $_loca return $this->render('@OrbitaleCms/Front/index.html.twig', [ 'pages' => $pages, - 'page' => $currentPage, + 'page' => $currentPage, ]); } @@ -76,10 +78,11 @@ protected function getPages(array $slugsArray = []): array { /** @var Page[] $pages */ $pages = $this->pageRepository - ->findFrontPages($slugsArray, $this->request->getHost(), $this->request->getLocale()); + ->findFrontPages($slugsArray, $this->request->getHost(), $this->request->getLocale()) + ; - if (!count($pages) || (count($slugsArray) && count($pages) !== count($slugsArray))) { - throw $this->createNotFoundException(count($slugsArray) + if (!\count($pages) || (\count($slugsArray) && \count($pages) !== \count($slugsArray))) { + throw $this->createNotFoundException(\count($slugsArray) ? 'Page not found' : 'No homepage has been configured. Please check your existing pages or create a homepage in your application.'); } @@ -90,17 +93,15 @@ protected function getPages(array $slugsArray = []): array /** * Retrieves the current page based on page list and entered slugs. * - * @param Page[] $pages - * @param string[] $slugsArray - * - * @return Page + * @param Page[] $pages + * @param string[] $slugsArray */ protected function getCurrentPage(array $pages, array $slugsArray): Page { - if (count($pages) === count($slugsArray)) { + if (\count($pages) === \count($slugsArray)) { $currentPage = $this->getFinalTreeElement($slugsArray, $pages); } else { - $currentPage = current($pages); + $currentPage = \current($pages); } return $currentPage; diff --git a/Controller/PostsController.php b/Controller/PostsController.php index 29e0a31..6a07127 100644 --- a/Controller/PostsController.php +++ b/Controller/PostsController.php @@ -1,18 +1,18 @@ -* (c) Micael Dias (@aimproxy) -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Controller; -use DateTime; use Orbitale\Bundle\CmsBundle\Entity\Page; use Orbitale\Bundle\CmsBundle\Repository\PageRepository; use Symfony\Component\HttpFoundation\Request; @@ -35,11 +35,11 @@ public function __construct(PageRepository $pageRepository) public function indexAction(Request $request, string $slugs = '', string $date = '', ?string $_date_format = null, ?string $_locale = null): Response { if (!$this->isValidDate($date, $_date_format)) { - throw $this->createNotFoundException("Invalid date format provided"); + throw $this->createNotFoundException('Invalid date format provided'); } if (!$slugs || '/' === $slugs) { - throw $this->createNotFoundException("No page identifier provided"); + throw $this->createNotFoundException('No page identifier provided'); } $this->request = $request; @@ -54,7 +54,7 @@ public function indexAction(Request $request, string $slugs = '', string $date = $numberOfSlugs = \count($slugsArray); $numberOfPages = \count($pages); if (!$numberOfPages || ($numberOfSlugs && $numberOfPages !== $numberOfSlugs)) { - throw $this->createNotFoundException("Post not found"); + throw $this->createNotFoundException('Post not found'); } $currentPage = $this->getCurrentPage($pages, $slugsArray); @@ -69,16 +69,16 @@ public function indexAction(Request $request, string $slugs = '', string $date = ]); } - function isValidDate(string $date, string $format): bool + public function isValidDate(string $date, string $format): bool { - $d = DateTime::createFromFormat($format, $date); + $d = \DateTime::createFromFormat($format, $date); return $d && $d->format($format) == $date; } public function getCurrentPage(array $pages, array $slugsArray): Page { - if (count($pages) === count($slugsArray)) { + if (\count($pages) === \count($slugsArray)) { return $this->getFinalTreeElement($slugsArray, $pages); } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 6187263..dad87bc 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -1,21 +1,23 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\DependencyInjection; +use Orbitale\Bundle\CmsBundle\Entity\Category; +use Orbitale\Bundle\CmsBundle\Entity\Page; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; -use Orbitale\Bundle\CmsBundle\Entity\Page; -use Orbitale\Bundle\CmsBundle\Entity\Category; /** * This is the class that validates and merges configuration from your app/config files. @@ -30,81 +32,84 @@ class Configuration implements ConfigurationInterface public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('orbitale_cms'); - $rootNode = $treeBuilder->getRootNode(); + $rootNode = $treeBuilder->getRootNode(); $rootNode ->addDefaultsIfNotSet() ->children() - ->scalarNode('page_class') - ->isRequired() - ->validate() - ->ifString() - ->then(function($value) { - if (!class_exists($value) || !is_a($value, Page::class, true)) { - throw new InvalidConfigurationException(sprintf( - 'Page class must be a valid class extending %s. "%s" given.', - Page::class, $value - )); - } + ->scalarNode('page_class') + ->isRequired() + ->validate() + ->ifString() + ->then(function ($value) { + if (!\class_exists($value) || !\is_a($value, Page::class, true)) { + throw new InvalidConfigurationException(\sprintf( + 'Page class must be a valid class extending %s. "%s" given.', + Page::class, + $value + )); + } - return $value; - }) - ->end() - ->end() - ->scalarNode('category_class') - ->isRequired() - ->validate() - ->ifString() - ->then(function($value) { - if (!class_exists($value) || !is_a($value, Category::class, true)) { - throw new InvalidConfigurationException(sprintf( - 'Category class must be a valid class extending %s. "%s" given.', - Category::class, $value - )); - } + return $value; + }) + ->end() + ->end() + ->scalarNode('category_class') + ->isRequired() + ->validate() + ->ifString() + ->then(function ($value) { + if (!\class_exists($value) || !\is_a($value, Category::class, true)) { + throw new InvalidConfigurationException(\sprintf( + 'Category class must be a valid class extending %s. "%s" given.', + Category::class, + $value + )); + } - return $value; - }) - ->end() - ->end() - ->arrayNode('layouts') - ->defaultValue([ - 'front' => [ - 'resource' => '@OrbitaleCms/default_layout.html.twig', - 'pattern' => '', - ], - ]) - ->useAttributeAsKey('name') - ->prototype('array') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('name')->end() - ->scalarNode('resource')->isRequired()->end() - ->arrayNode('assets_css')->prototype('scalar')->end()->end() - ->arrayNode('assets_js')->prototype('scalar')->end()->end() - ->scalarNode('pattern')->defaultValue('')->end() - ->scalarNode('host')->defaultValue('')->end() - ->end() - ->end() - ->end() - ->arrayNode('design') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('breadcrumbs_class')->defaultValue('breadcrumb')->end() - ->scalarNode('breadcrumbs_link_class')->defaultValue('')->end() - ->scalarNode('breadcrumbs_current_class')->defaultValue('')->end() - ->scalarNode('breadcrumbs_separator')->defaultValue('>')->end() - ->scalarNode('breadcrumbs_separator_class')->defaultValue('breadcrumb-separator')->end() - ->end() - ->end() - ->arrayNode('cache') - ->addDefaultsIfNotSet() - ->children() - ->booleanNode('enabled')->defaultFalse()->end() - ->integerNode('ttl')->defaultValue(300)->end() - ->end() - ->end() - ->end(); + return $value; + }) + ->end() + ->end() + ->arrayNode('layouts') + ->defaultValue([ + 'front' => [ + 'resource' => '@OrbitaleCms/default_layout.html.twig', + 'pattern' => '', + ], + ]) + ->useAttributeAsKey('name') + ->prototype('array') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('name')->end() + ->scalarNode('resource')->isRequired()->end() + ->arrayNode('assets_css')->prototype('scalar')->end()->end() + ->arrayNode('assets_js')->prototype('scalar')->end()->end() + ->scalarNode('pattern')->defaultValue('')->end() + ->scalarNode('host')->defaultValue('')->end() + ->end() + ->end() + ->end() + ->arrayNode('design') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('breadcrumbs_class')->defaultValue('breadcrumb')->end() + ->scalarNode('breadcrumbs_link_class')->defaultValue('')->end() + ->scalarNode('breadcrumbs_current_class')->defaultValue('')->end() + ->scalarNode('breadcrumbs_separator')->defaultValue('>')->end() + ->scalarNode('breadcrumbs_separator_class')->defaultValue('breadcrumb-separator')->end() + ->end() + ->end() + ->arrayNode('cache') + ->addDefaultsIfNotSet() + ->children() + ->booleanNode('enabled')->defaultFalse()->end() + ->integerNode('ttl')->defaultValue(300)->end() + ->end() + ->end() + ->end() + ; return $treeBuilder; } diff --git a/DependencyInjection/OrbitaleCmsExtension.php b/DependencyInjection/OrbitaleCmsExtension.php index 69814b1..e1d9c37 100644 --- a/DependencyInjection/OrbitaleCmsExtension.php +++ b/DependencyInjection/OrbitaleCmsExtension.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\DependencyInjection; @@ -15,7 +17,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\HttpKernel\DependencyInjection\Extension; -use Symfony\Component\HttpKernel\Kernel; /** * This is the class that loads and manages your bundle configuration. @@ -30,17 +31,17 @@ class OrbitaleCmsExtension extends Extension public function load(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); - $config = $this->processConfiguration($configuration, $configs); + $config = $this->processConfiguration($configuration, $configs); foreach ($config['layouts'] as $name => $layout) { - $config['layouts'][$name] = array_merge([ - 'name' => $name, + $config['layouts'][$name] = \array_merge([ + 'name' => $name, 'assets_css' => [], - 'assets_js' => [], - 'host' => '', - 'pattern' => '', + 'assets_js' => [], + 'host' => '', + 'pattern' => '', ], $layout); - ksort($config['layouts'][$name]); + \ksort($config['layouts'][$name]); } foreach ($config as $key => $value) { diff --git a/Entity/Category.php b/Entity/Category.php index 7aeca49..cf91be6 100644 --- a/Entity/Category.php +++ b/Entity/Category.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Entity; @@ -20,21 +22,17 @@ /** * @UniqueEntity("slug") */ -#[UniqueEntity("slug")] +#[UniqueEntity('slug')] abstract class Category { - /** - * @return int|string - */ - abstract public function getId(); - /** * @var string * * @Assert\Type("string") + * * @Assert\NotBlank() */ - #[Assert\Type("string")] + #[Assert\Type('string')] #[Assert\NotBlank] protected $name; @@ -42,9 +40,10 @@ abstract public function getId(); * @var string * * @Assert\Type("string") + * * @Assert\NotBlank() */ - #[Assert\Type("string")] + #[Assert\Type('string')] #[Assert\NotBlank] protected $slug; @@ -53,7 +52,7 @@ abstract public function getId(); * * @Assert\Type("string") */ - #[Assert\Type("string")] + #[Assert\Type('string')] protected $description; /** @@ -61,37 +60,43 @@ abstract public function getId(); * * @Assert\Type("bool") */ - #[Assert\Type("bool")] + #[Assert\Type('bool')] protected $enabled = false; /** * @var Category + * * @Assert\Type(Category::class) */ - #[Assert\Type(Category::class)] + #[Assert\Type(self::class)] protected $parent; /** - * @var Category[]|ArrayCollection + * @var ArrayCollection|Category[] */ protected $children; /** - * @var Page[]|ArrayCollection + * @var ArrayCollection|Page[] */ protected $pages; - public function __toString() + public function __construct() { - return $this->name; + $this->children = new ArrayCollection(); + $this->pages = new ArrayCollection(); } - public function __construct() + public function __toString() { - $this->children = new ArrayCollection(); - $this->pages = new ArrayCollection(); + return $this->name; } + /** + * @return int|string + */ + abstract public function getId(); + public function getName(): string { return (string) $this->name; @@ -132,12 +137,12 @@ public function setEnabled(?bool $enabled = false): void $this->enabled = (bool) $enabled; } - public function getParent(): ?Category + public function getParent(): ?self { return $this->parent; } - public function setParent(?Category $parent): void + public function setParent(?self $parent): void { if ($parent === $this) { // Refuse the category to have itself as parent. @@ -155,14 +160,14 @@ public function setParent(?Category $parent): void } /** - * @return Category[]|ArrayCollection + * @return ArrayCollection|Category[] */ public function getChildren() { return $this->children; } - public function addChild(Category $category): void + public function addChild(self $category): void { $this->children->add($category); @@ -171,13 +176,13 @@ public function addChild(Category $category): void } } - public function removeChild(Category $child): void + public function removeChild(self $child): void { $this->children->removeElement($child); } /** - * @return Category[]|ArrayCollection + * @return ArrayCollection|Category[] */ public function getPages() { @@ -206,31 +211,31 @@ public function getTree(string $separator = '/'): string $current = $this; do { - $tree = $current->getSlug().$separator.$tree; + $tree = $current->getSlug().$separator.$tree; $current = $current->getParent(); } while ($current); - return trim($tree, $separator); + return \trim($tree, $separator); } public function updateSlug(): void { if (!$this->slug) { - $this->slug = mb_strtolower((new AsciiSlugger())->slug($this->name)->toString()); + $this->slug = \mb_strtolower((new AsciiSlugger())->slug($this->name)->toString()); } } public function onRemove(PreRemoveEventArgs $event): void { $em = $event->getObjectManager(); - if (count($this->children)) { + if (\count($this->children)) { foreach ($this->children as $child) { $child->setParent(null); $em->persist($child); } } $this->enabled = false; - $this->parent = null; + $this->parent = null; $this->name .= '-'.$this->getId().'-deleted'; $this->slug .= '-'.$this->getId().'-deleted'; } diff --git a/Entity/Page.php b/Entity/Page.php index 7220281..bc3cb61 100644 --- a/Entity/Page.php +++ b/Entity/Page.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Entity; @@ -20,21 +22,17 @@ /** * @UniqueEntity("slug") */ -#[UniqueEntity("slug")] +#[UniqueEntity('slug')] abstract class Page { - /** - * @return int|string - */ - abstract public function getId(); - /** * @var string * * @Assert\Type("string") + * * @Assert\NotBlank() */ - #[Assert\Type("string")] + #[Assert\Type('string')] #[Assert\NotBlank] protected $title; @@ -42,9 +40,10 @@ abstract public function getId(); * @var string * * @Assert\Type("string") + * * @Assert\NotBlank() */ - #[Assert\Type("string")] + #[Assert\Type('string')] #[Assert\NotBlank] protected $slug; @@ -53,7 +52,7 @@ abstract public function getId(); * * @Assert\Type("string") */ - #[Assert\Type("string")] + #[Assert\Type('string')] protected $content; /** @@ -61,7 +60,7 @@ abstract public function getId(); * * @Assert\Type("string") */ - #[Assert\Type("string")] + #[Assert\Type('string')] protected $metaDescription; /** @@ -69,7 +68,7 @@ abstract public function getId(); * * @Assert\Type("string") */ - #[Assert\Type("string")] + #[Assert\Type('string')] protected $metaTitle; /** @@ -77,7 +76,7 @@ abstract public function getId(); * * @Assert\Type("string") */ - #[Assert\Type("string")] + #[Assert\Type('string')] protected $metaKeywords; /** @@ -93,7 +92,7 @@ abstract public function getId(); * * @Assert\Type("string") */ - #[Assert\Type("string")] + #[Assert\Type('string')] protected $css; /** @@ -101,7 +100,7 @@ abstract public function getId(); * * @Assert\Type("string") */ - #[Assert\Type("string")] + #[Assert\Type('string')] protected $js; /** @@ -117,7 +116,7 @@ abstract public function getId(); * * @Assert\Type("bool") */ - #[Assert\Type("bool")] + #[Assert\Type('bool')] protected $enabled = false; /** @@ -125,7 +124,7 @@ abstract public function getId(); * * @Assert\Type("bool") */ - #[Assert\Type("bool")] + #[Assert\Type('bool')] protected $homepage = false; /** @@ -133,7 +132,7 @@ abstract public function getId(); * * @Assert\Type("string") */ - #[Assert\Type("string")] + #[Assert\Type('string')] protected $host; /** @@ -141,7 +140,7 @@ abstract public function getId(); * * @Assert\Type("string") */ - #[Assert\Type("string")] + #[Assert\Type('string')] protected $locale; /** @@ -149,25 +148,30 @@ abstract public function getId(); * * @Assert\Type(Page::class) */ - #[Assert\Type(Page::class)] + #[Assert\Type(self::class)] protected $parent; /** - * @var Page[]|ArrayCollection + * @var ArrayCollection|Page[] */ protected $children; - public function __toString() + public function __construct() { - return $this->title; + $this->createdAt = new \DateTimeImmutable(); + $this->children = new ArrayCollection(); } - public function __construct() + public function __toString() { - $this->createdAt = new \DateTimeImmutable(); - $this->children = new ArrayCollection(); + return $this->title; } + /** + * @return int|string + */ + abstract public function getId(); + public function getTitle(): string { return (string) $this->title; @@ -282,12 +286,12 @@ public function setEnabled(?bool $enabled = false): void $this->enabled = (bool) $enabled; } - public function getParent(): ?Page + public function getParent(): ?self { return $this->parent; } - public function setParent(?Page $parent): void + public function setParent(?self $parent): void { if ($parent === $this) { // Refuse the category to have itself as parent. @@ -305,14 +309,14 @@ public function setParent(?Page $parent): void } /** - * @return Page[]|ArrayCollection + * @return ArrayCollection|Page[] */ public function getChildren() { return $this->children; } - public function addChild(Page $page): void + public function addChild(self $page): void { $this->children->add($page); @@ -321,7 +325,7 @@ public function addChild(Page $page): void } } - public function removeChild(Page $page): void + public function removeChild(self $page): void { $this->children->removeElement($page); } @@ -362,31 +366,31 @@ public function getTree(string $separator = '/'): string $current = $this; do { - $tree = $current->getSlug().$separator.$tree; + $tree = $current->getSlug().$separator.$tree; $current = $current->getParent(); } while ($current); - return trim($tree, $separator); + return \trim($tree, $separator); } public function updateSlug(): void { if (!$this->slug) { - $this->slug = mb_strtolower((new AsciiSlugger())->slug($this->title)->toString()); + $this->slug = \mb_strtolower((new AsciiSlugger())->slug($this->title)->toString()); } } public function onRemove(PreRemoveEventArgs $event): void { $em = $event->getObjectManager(); - if (count($this->children)) { + if (\count($this->children)) { foreach ($this->children as $child) { $child->setParent(null); $em->persist($child); } } $this->enabled = false; - $this->parent = null; + $this->parent = null; $this->title .= '-'.$this->getId().'-deleted'; $this->slug .= '-'.$this->getId().'-deleted'; } diff --git a/EventListener/DoctrineMappingListener.php b/EventListener/DoctrineMappingListener.php index ec0940d..33725ad 100644 --- a/EventListener/DoctrineMappingListener.php +++ b/EventListener/DoctrineMappingListener.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\EventListener; @@ -48,8 +50,8 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void /** @var ClassMetadata $classMetadata */ $classMetadata = $eventArgs->getClassMetadata(); - $isPage = is_a($classMetadata->getName(), $this->pageClass, true); - $isCategory = is_a($classMetadata->getName(), $this->categoryClass, true); + $isPage = \is_a($classMetadata->getName(), $this->pageClass, true); + $isCategory = \is_a($classMetadata->getName(), $this->categoryClass, true); if ($isPage) { $this->processPageMetadata($classMetadata); @@ -84,7 +86,6 @@ private function processCategoryMetadata(ClassMetadata $classMetadata): void 'mappedBy' => 'category', ]); } - } /** @@ -102,7 +103,7 @@ private function processParent(ClassMetadata $classMetadata, string $class): voi } /** - * Declare self-bidirectionnal mapping for children + * Declare self-bidirectionnal mapping for children. */ private function processChildren(ClassMetadata $classMetadata, string $class): void { diff --git a/EventListener/LayoutsListener.php b/EventListener/LayoutsListener.php index eb36d03..2ca2bc0 100644 --- a/EventListener/LayoutsListener.php +++ b/EventListener/LayoutsListener.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\EventListener; @@ -33,7 +35,7 @@ class LayoutsListener implements EventSubscriberInterface public function __construct(array $layouts, Environment $twig) { $this->layouts = $layouts; - $this->twig = $twig; + $this->twig = $twig; } /** @@ -67,12 +69,13 @@ public function setRequestLayout(RequestEvent $event): void } // Check pattern - if ($layoutConfig['pattern'] && preg_match('~'.$layoutConfig['pattern'].'~', $path)) { + if ($layoutConfig['pattern'] && \preg_match('~'.$layoutConfig['pattern'].'~', $path)) { $match = true; } if ($match) { $finalLayout = $layoutConfig; + break; } } @@ -81,19 +84,20 @@ public function setRequestLayout(RequestEvent $event): void if (null === $finalLayout) { $layouts = $this->layouts; do { - $finalLayout = array_shift($layouts); + $finalLayout = \array_shift($layouts); if ($finalLayout['host'] || $finalLayout['pattern']) { $finalLayout = null; } - } while (null === $finalLayout && count($layouts)); + } while (null === $finalLayout && \count($layouts)); } if (null === $finalLayout || !$this->twig->getLoader()->exists($finalLayout['resource'])) { $source = new Source('', $finalLayout['resource']); - throw new LoaderError(sprintf( + throw new LoaderError(\sprintf( 'Unable to find template %s for layout %s. The "layout" parameter must be a valid twig view to be used as a layout.', - $finalLayout['resource'], $finalLayout['name'] + $finalLayout['resource'], + $finalLayout['name'] ), 0, $source); } diff --git a/Repository/AbstractCmsRepository.php b/Repository/AbstractCmsRepository.php index f06285f..0ac95f0 100644 --- a/Repository/AbstractCmsRepository.php +++ b/Repository/AbstractCmsRepository.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Repository; @@ -30,12 +32,9 @@ class AbstractCmsRepository extends EntityRepository */ protected $cacheTtl; - /** - * @param array $cacheConfig - */ - public function setConfig(array $cacheConfig) + public function setConfig(array $cacheConfig): void { $this->cacheEnabled = $cacheConfig['enabled']; - $this->cacheTtl = $cacheConfig['ttl']; + $this->cacheTtl = $cacheConfig['ttl']; } } diff --git a/Repository/CategoryRepository.php b/Repository/CategoryRepository.php index 22875cf..e7ccdea 100644 --- a/Repository/CategoryRepository.php +++ b/Repository/CategoryRepository.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Repository; @@ -16,8 +18,6 @@ class CategoryRepository extends AbstractCmsRepository { /** - * @param array $slugs - * * @return Category[] */ public function findFrontCategories(array $slugs) diff --git a/Repository/PageRepository.php b/Repository/PageRepository.php index 5a424c8..5b9918f 100644 --- a/Repository/PageRepository.php +++ b/Repository/PageRepository.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Repository; @@ -18,13 +20,10 @@ class PageRepository extends AbstractCmsRepository { /** - * @param Category $category - * @param string $order - * @param string $orderBy - * @param int $page - * @param int $limit - * - * @return Paginator + * @param string $order + * @param string $orderBy + * @param int $page + * @param int $limit */ public function findByCategory(Category $category, $order, $orderBy, $page, $limit): Paginator { @@ -33,7 +32,7 @@ public function findByCategory(Category $category, $order, $orderBy, $page, $lim ->andWhere('page.enabled = :enabled') ->orderBy('page.'.$orderBy, $order) ->setMaxResults($limit) - ->setFirstResult($limit * ($page-1)) + ->setFirstResult($limit * ($page - 1)) ->setParameter('category', $category) ->setParameter('enabled', true) ; @@ -46,9 +45,8 @@ public function findByCategory(Category $category, $order, $orderBy, $page, $lim * If slugs are defined, there's no problem in looking for nulled host or locale, * because slugs are unique, so it does not. * - * @param array $slugs - * @param string|null $host - * @param string|null $locale + * @param null|string $host + * @param null|string $locale * * @return Page[] */ @@ -62,7 +60,7 @@ public function findFrontPages(array $slugs = [], $host = null, $locale = null) ; // Will search differently if we're looking for homepage. - $searchForHomepage = 0 === count($slugs); + $searchForHomepage = 0 === \count($slugs); if (true === $searchForHomepage) { // If we are looking for homepage, let's get only the first one. @@ -71,10 +69,10 @@ public function findFrontPages(array $slugs = [], $host = null, $locale = null) ->setParameter('homepage', true) ->setMaxResults(1) ; - } elseif (1 === count($slugs)) { + } elseif (1 === \count($slugs)) { $qb ->andWhere('page.slug = :slug') - ->setParameter('slug', reset($slugs)) + ->setParameter('slug', \reset($slugs)) ->setMaxResults(1) ; } else { @@ -112,13 +110,13 @@ public function findFrontPages(array $slugs = [], $host = null, $locale = null) ->getResult() ; - if (0 === count($results)) { + if (0 === \count($results)) { return $results; } // If we're looking for a homepage, only get the first result (matching more properties). - if (true === $searchForHomepage && count($results) > 0) { - reset($results); + if (true === $searchForHomepage && \count($results) > 0) { + \reset($results); $results = [$results[0]]; } @@ -129,10 +127,10 @@ public function findFrontPages(array $slugs = [], $host = null, $locale = null) $pages = $resultsSortedBySlug; - if (count($slugs) > 0) { + if (\count($slugs) > 0) { $pages = []; foreach ($slugs as $value) { - if (!array_key_exists($value, $resultsSortedBySlug)) { + if (!\array_key_exists($value, $resultsSortedBySlug)) { // Means at least one page in the tree is not enabled return []; } diff --git a/Resources/config/doctrine/Category.orm.xml b/Resources/config/doctrine/Category.orm.xml index bd29078..94ca8fb 100644 --- a/Resources/config/doctrine/Category.orm.xml +++ b/Resources/config/doctrine/Category.orm.xml @@ -22,4 +22,4 @@ - \ No newline at end of file + diff --git a/Resources/config/doctrine/Page.orm.xml b/Resources/config/doctrine/Page.orm.xml index 8b16016..296ce4e 100644 --- a/Resources/config/doctrine/Page.orm.xml +++ b/Resources/config/doctrine/Page.orm.xml @@ -40,4 +40,4 @@ - \ No newline at end of file + diff --git a/Tests/AbstractTestCase.php b/Tests/AbstractTestCase.php index 4c0095b..c3ee936 100644 --- a/Tests/AbstractTestCase.php +++ b/Tests/AbstractTestCase.php @@ -1,26 +1,28 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Tests; use Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Page; +use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Component\Console\Input\ArrayInput; class AbstractTestCase extends WebTestCase { - public function setUp(): void + protected function setUp(): void { self::installDatabase(); } @@ -46,7 +48,7 @@ public static function installDatabase(): void $returns[] = $application->run(new ArrayInput(['command' => 'doctrine:schema:create']), $out); if (\in_array(1, $returns, true)) { - self::fail(\sprintf("A database setup command has failed:\n%s", $out->fetch())); + static::fail(\sprintf("A database setup command has failed:\n%s", $out->fetch())); } static::ensureKernelShutdown(); @@ -56,9 +58,9 @@ protected function createPage(array $values = []): Page { $page = new Page(); - $set = \Closure::bind(function(string $property, $value) { - if (!property_exists(Page::class, $property)){ - throw new \InvalidArgumentException(sprintf("Property %s does not exist in %s", $property, Page::class)); + $set = \Closure::bind(function (string $property, $value): void { + if (!\property_exists(Page::class, $property)) { + throw new \InvalidArgumentException(\sprintf('Property %s does not exist in %s', $property, Page::class)); } $this->{$property} = $value; }, $page, Page::class); diff --git a/Tests/Controller/CategoryControllerTest.php b/Tests/Controller/CategoryControllerTest.php index 4740e23..2ac7af5 100644 --- a/Tests/Controller/CategoryControllerTest.php +++ b/Tests/Controller/CategoryControllerTest.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Tests\Controller; @@ -18,14 +20,14 @@ class CategoryControllerTest extends AbstractTestCase { - public function testNoCategoryWithSlug() + public function testNoCategoryWithSlug(): void { $client = self::createClient(); $client->request('GET', '/category/inexistent-slug'); static::assertEquals(404, $client->getResponse()->getStatusCode()); } - public function testSingleCategory() + public function testSingleCategory(): void { $client = self::createClient(); @@ -46,14 +48,15 @@ public function testSingleCategory() static::assertTrue($client->getResponse()->isRedirect('/category/default')); $crawler = $client->followRedirect(); - static::assertEquals($category->getName(), trim($crawler->filter('title')->html())); - static::assertEquals($category->getName(), trim($crawler->filter('article > h1')->html())); - static::assertStringContainsString($category->getDescription(), trim($crawler->filter('article')->first()->html())); + static::assertEquals($category->getName(), \trim($crawler->filter('title')->html())); + static::assertEquals($category->getName(), \trim($crawler->filter('article > h1')->html())); + static::assertStringContainsString($category->getDescription(), \trim($crawler->filter('article')->first()->html())); } - public function testTree() + public function testTree(): void { $client = self::createClient(); + /** @var EntityManagerInterface $em */ $em = self::getContainer()->get(EntityManagerInterface::class); @@ -89,16 +92,16 @@ public function testTree() // Repeat with the homepage directly in the url $crawler = $client->request('GET', '/category/'.$childOne->getTree()); - static::assertEquals($childOne->getName(), trim($crawler->filter('title')->html())); - static::assertEquals($childOne->getName(), trim($crawler->filter('article > h1')->html())); - static::assertStringContainsString($childOne->getDescription(), trim($crawler->filter('article')->first()->html())); + static::assertEquals($childOne->getName(), \trim($crawler->filter('title')->html())); + static::assertEquals($childOne->getName(), \trim($crawler->filter('article > h1')->html())); + static::assertStringContainsString($childOne->getDescription(), \trim($crawler->filter('article')->first()->html())); // Repeat with the homepage directly in the url $client->request('GET', '/category/root/second-level'); static::assertEquals(404, $client->getResponse()->getStatusCode()); } - public function testWithPages() + public function testWithPages(): void { $client = self::createClient(); @@ -136,11 +139,11 @@ public function testWithPages() $crawler = $client->request('GET', '/category/'.$category->getTree()); $section1 = $crawler->filter('section')->eq(0); - static::assertEquals($page1->getTitle(), trim($section1->filter('article > h2 > a')->html())); - static::assertStringContainsString($page1->getContent(), trim($section1->filter('article')->html())); + static::assertEquals($page1->getTitle(), \trim($section1->filter('article > h2 > a')->html())); + static::assertStringContainsString($page1->getContent(), \trim($section1->filter('article')->html())); $section2 = $crawler->filter('section')->eq(1); - static::assertEquals($page2->getTitle(), trim($section2->filter('article > h2 > a')->html())); - static::assertStringContainsString($page2->getContent(), trim($section2->filter('article')->html())); + static::assertEquals($page2->getTitle(), \trim($section2->filter('article > h2 > a')->html())); + static::assertStringContainsString($page2->getContent(), \trim($section2->filter('article')->html())); } } diff --git a/Tests/Controller/PageControllerTest.php b/Tests/Controller/PageControllerTest.php index 0108e44..c64bf46 100644 --- a/Tests/Controller/PageControllerTest.php +++ b/Tests/Controller/PageControllerTest.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Tests\Controller; @@ -19,10 +21,10 @@ class PageControllerTest extends AbstractTestCase { public function testNoHomepage(): void { - $error = 'No homepage has been configured. Please check your existing pages or create a homepage in your application. (404 Not Found)'; - $client = self::createClient(); + $error = 'No homepage has been configured. Please check your existing pages or create a homepage in your application. (404 Not Found)'; + $client = self::createClient(); $crawler = $client->request('GET', '/page/'); - static::assertEquals($error, trim($crawler->filter('title')->html())); + static::assertEquals($error, \trim($crawler->filter('title')->html())); static::assertEquals(404, $client->getResponse()->getStatusCode()); } @@ -39,11 +41,11 @@ public function testOneHomepage(): void $homepage = $this->createPage([ 'homepage' => true, - 'enabled' => true, - 'slug' => 'home', - 'title' => 'My homepage', - 'host' => 'localhost', - 'content' => 'Hello world!', + 'enabled' => true, + 'slug' => 'home', + 'title' => 'My homepage', + 'host' => 'localhost', + 'content' => 'Hello world!', ]); /** @var EntityManagerInterface $em */ @@ -52,9 +54,9 @@ public function testOneHomepage(): void $em->flush(); $crawler = $client->request('GET', '/page/'); - static::assertEquals($homepage->getTitle(), trim($crawler->filter('title')->html())); - static::assertEquals($homepage->getTitle(), trim($crawler->filter('article > h1')->html())); - static::assertStringContainsString($homepage->getContent(), trim($crawler->filter('article')->html())); + static::assertEquals($homepage->getTitle(), \trim($crawler->filter('title')->html())); + static::assertEquals($homepage->getTitle(), \trim($crawler->filter('article > h1')->html())); + static::assertStringContainsString($homepage->getContent(), \trim($crawler->filter('article')->html())); // Repeat with the homepage directly in the url @@ -67,9 +69,9 @@ public function testOneHomepage(): void static::assertTrue($client->getResponse()->isRedirect('/page')); $crawler = $client->followRedirect(); - static::assertEquals($homepage->getTitle(), trim($crawler->filter('title')->html())); - static::assertEquals($homepage->getTitle(), trim($crawler->filter('article > h1')->html())); - static::assertStringContainsString($homepage->getContent(), trim($crawler->filter('article')->html())); + static::assertEquals($homepage->getTitle(), \trim($crawler->filter('title')->html())); + static::assertEquals($homepage->getTitle(), \trim($crawler->filter('article > h1')->html())); + static::assertStringContainsString($homepage->getContent(), \trim($crawler->filter('article')->html())); } public function testOneHomepageWithLocale(): void @@ -78,12 +80,12 @@ public function testOneHomepageWithLocale(): void $homepage = $this->createPage([ 'homepage' => true, - 'enabled' => true, - 'locale' => 'en', - 'slug' => 'home', - 'title' => 'My homepage', - 'host' => 'localhost', - 'content' => 'Hello world!', + 'enabled' => true, + 'locale' => 'en', + 'slug' => 'home', + 'title' => 'My homepage', + 'host' => 'localhost', + 'content' => 'Hello world!', ]); /** @var EntityManagerInterface $em */ @@ -92,9 +94,9 @@ public function testOneHomepageWithLocale(): void $em->flush(); $crawler = $client->request('GET', '/page/'); - static::assertEquals($homepage->getTitle(), trim($crawler->filter('title')->html())); - static::assertEquals($homepage->getTitle(), trim($crawler->filter('article > h1')->html())); - static::assertStringContainsString($homepage->getContent(), trim($crawler->filter('article')->html())); + static::assertEquals($homepage->getTitle(), \trim($crawler->filter('title')->html())); + static::assertEquals($homepage->getTitle(), \trim($crawler->filter('article > h1')->html())); + static::assertStringContainsString($homepage->getContent(), \trim($crawler->filter('article')->html())); // Repeat with the homepage directly in the url @@ -107,9 +109,9 @@ public function testOneHomepageWithLocale(): void static::assertTrue($client->getResponse()->isRedirect('/page?_locale=en')); $crawler = $client->followRedirect(); - static::assertEquals($homepage->getTitle(), trim($crawler->filter('title')->html())); - static::assertEquals($homepage->getTitle(), trim($crawler->filter('article > h1')->html())); - static::assertStringContainsString($homepage->getContent(), trim($crawler->filter('article')->html())); + static::assertEquals($homepage->getTitle(), \trim($crawler->filter('title')->html())); + static::assertEquals($homepage->getTitle(), \trim($crawler->filter('article > h1')->html())); + static::assertStringContainsString($homepage->getContent(), \trim($crawler->filter('article')->html())); } public function testTree(): void @@ -122,39 +124,39 @@ public function testTree(): void // Prepare 3 pages : the root, the first level, and the third one that's disabled $root = $this->createPage([ 'homepage' => true, - 'enabled' => true, - 'slug' => 'root', - 'title' => 'Root', - 'content' => 'The root page', + 'enabled' => true, + 'slug' => 'root', + 'title' => 'Root', + 'content' => 'The root page', ]); $em->persist($root); $em->flush(); $childOne = $this->createPage([ 'enabled' => true, - 'slug' => 'first-level', - 'title' => 'First level', + 'slug' => 'first-level', + 'title' => 'First level', 'content' => 'This page is only available in the first level', - 'parent' => $root, + 'parent' => $root, ]); $em->persist($childOne); $em->flush(); $childTwoDisabled = $this->createPage([ 'enabled' => false, - 'slug' => 'second-level', - 'title' => 'Disabled Page', + 'slug' => 'second-level', + 'title' => 'Disabled Page', 'content' => 'This page should render a 404 error', - 'parent' => $root, + 'parent' => $root, ]); $em->persist($childTwoDisabled); $em->flush(); // Repeat with the homepage directly in the url $crawler = $client->request('GET', '/page/root/first-level'); - static::assertEquals($childOne->getTitle(), trim($crawler->filter('title')->html())); - static::assertEquals($childOne->getTitle(), trim($crawler->filter('article > h1')->html())); - static::assertStringContainsString($childOne->getContent(), trim($crawler->filter('article')->html())); + static::assertEquals($childOne->getTitle(), \trim($crawler->filter('title')->html())); + static::assertEquals($childOne->getTitle(), \trim($crawler->filter('article > h1')->html())); + static::assertStringContainsString($childOne->getContent(), \trim($crawler->filter('article')->html())); // Repeat with the homepage directly in the url $client->request('GET', '/page/root/second-level'); @@ -169,55 +171,56 @@ public function testMetas(): void $em = self::getContainer()->get(EntityManagerInterface::class); $page = $this->createPage([ - 'homepage' => true, - 'enabled' => true, - 'title' => 'Root', - 'content' => 'The root page', - 'css' => '#home{color:red;}', - 'js' => 'alert("ok");', + 'homepage' => true, + 'enabled' => true, + 'title' => 'Root', + 'content' => 'The root page', + 'css' => '#home{color:red;}', + 'js' => 'alert("ok");', 'metaDescription' => 'meta description', - 'metaKeywords' => 'this is a meta keyword list', - 'metaTitle' => 'this title is only in the metas', + 'metaKeywords' => 'this is a meta keyword list', + 'metaTitle' => 'this title is only in the metas', ]); $em->persist($page); $em->flush(); $crawler = $client->request('GET', '/page'); - static::assertEquals($page->getTitle(), trim($crawler->filter('title')->html())); - static::assertEquals($page->getTitle(), trim($crawler->filter('article > h1')->html())); - static::assertStringContainsString($page->getContent(), trim($crawler->filter('article')->html())); + static::assertEquals($page->getTitle(), \trim($crawler->filter('title')->html())); + static::assertEquals($page->getTitle(), \trim($crawler->filter('article > h1')->html())); + static::assertStringContainsString($page->getContent(), \trim($crawler->filter('article')->html())); - static::assertEquals($page->getCss(), trim($crawler->filter('#orbitale_cms_css')->html())); - static::assertEquals($page->getJs(), trim($crawler->filter('#orbitale_cms_js')->html())); - static::assertEquals($page->getMetaDescription(), trim($crawler->filter('meta[name="description"]') + static::assertEquals($page->getCss(), \trim($crawler->filter('#orbitale_cms_css')->html())); + static::assertEquals($page->getJs(), \trim($crawler->filter('#orbitale_cms_js')->html())); + static::assertEquals($page->getMetaDescription(), \trim($crawler->filter('meta[name="description"]') ->attr('content'))); - static::assertEquals($page->getMetaKeywords(), trim($crawler->filter('meta[name="keywords"]') + static::assertEquals($page->getMetaKeywords(), \trim($crawler->filter('meta[name="keywords"]') ->attr('content'))); - static::assertEquals($page->getMetaTitle(), trim($crawler->filter('meta[name="title"]')->attr('content'))); + static::assertEquals($page->getMetaTitle(), \trim($crawler->filter('meta[name="title"]')->attr('content'))); } public function testParentAndChildrenDontReverse(): void { $client = self::createClient(); + /** @var EntityManagerInterface $em */ $em = self::getContainer()->get(EntityManagerInterface::class); $parent = $this->createPage([ - 'enabled' => true, + 'enabled' => true, 'homepage' => true, - 'title' => 'Locale+host', - 'host' => 'localhost', - 'locale' => 'en', + 'title' => 'Locale+host', + 'host' => 'localhost', + 'locale' => 'en', ]); $em->persist($parent); $em->flush(); $child = $this->createPage([ - 'enabled' => true, + 'enabled' => true, 'homepage' => true, - 'title' => 'Host only', - 'host' => 'localhost', - 'parent' => $parent, + 'title' => 'Host only', + 'host' => 'localhost', + 'parent' => $parent, ]); $em->persist($child); $em->flush(); @@ -244,29 +247,29 @@ public function testAllTypesOfPagesForHomepage(): void // First, create the pages /** @var Page[] $pages */ $pages = [ - 'both' => $this->createPage([ - 'enabled' => true, + 'both' => $this->createPage([ + 'enabled' => true, 'homepage' => true, - 'title' => 'Locale+host', - 'host' => 'localhost', - 'locale' => 'en', + 'title' => 'Locale+host', + 'host' => 'localhost', + 'locale' => 'en', ]), - 'host' => $this->createPage([ - 'enabled' => true, + 'host' => $this->createPage([ + 'enabled' => true, 'homepage' => true, - 'title' => 'Host only', - 'host' => 'localhost', + 'title' => 'Host only', + 'host' => 'localhost', ]), 'locale' => $this->createPage([ - 'enabled' => true, + 'enabled' => true, 'homepage' => true, - 'title' => 'Locale only', - 'locale' => 'en', + 'title' => 'Locale only', + 'locale' => 'en', ]), - 'none' => $this->createPage([ - 'enabled' => true, + 'none' => $this->createPage([ + 'enabled' => true, 'homepage' => true, - 'title' => 'No match', + 'title' => 'No match', ]), ]; foreach ($pages as $page) { @@ -275,13 +278,13 @@ public function testAllTypesOfPagesForHomepage(): void $em->flush(); // First page considered as homepage is the last one inserted. - $pages = array_reverse($pages); + $pages = \array_reverse($pages); // Loop the pages because the "$pages" array respects precedence, // So disabling the pages on each loop should make all assertions work. foreach ($pages as $key => $page) { $crawler = $client->request('GET', '/page/'); - static::assertEquals($page->getTitle(), trim($crawler->filter('title')->html())); + static::assertEquals($page->getTitle(), \trim($crawler->filter('title')->html())); $page = $em->find(Page::class, $page->getId()); $page->setEnabled(false); $em->flush(); @@ -300,9 +303,9 @@ public function testBreadcrumbsDesign(): void $em->flush(); $pageChild = $this->createPage([ 'enabled' => true, - 'slug' => 'child', - 'title' => 'Child page', - 'parent' => $page, + 'slug' => 'child', + 'title' => 'Child page', + 'parent' => $page, ]); $em->persist($pageChild); $em->flush(); @@ -336,7 +339,7 @@ public function testBreadcrumbsDesign(): void $firstLinkNode = $nodesArray[2]; static::assertEquals('a', $firstLinkNode->tagName); static::assertEquals('breadcrumb-link', $firstLinkNode->getAttribute('class')); - static::assertEquals($page->getTitle(), trim($firstLinkNode->textContent)); + static::assertEquals($page->getTitle(), \trim($firstLinkNode->textContent)); // We sort of skip node 3 because it should be a separator static::assertEquals('breadcrumb-overriden-separator-class', $nodesArray[3]->getAttribute('class')); @@ -344,7 +347,7 @@ public function testBreadcrumbsDesign(): void $currentLinkNode = $nodesArray[4]; static::assertEquals('span', $currentLinkNode->tagName); static::assertEquals('breadcrumb-current', $currentLinkNode->getAttribute('class')); - static::assertEquals($pageChild->getTitle(), trim($currentLinkNode->textContent)); + static::assertEquals($pageChild->getTitle(), \trim($currentLinkNode->textContent)); $crawler->clear(); } diff --git a/Tests/Controller/PostsControllerTest.php b/Tests/Controller/PostsControllerTest.php index 333a6c2..d624a2d 100644 --- a/Tests/Controller/PostsControllerTest.php +++ b/Tests/Controller/PostsControllerTest.php @@ -1,5 +1,16 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Orbitale\Bundle\CmsBundle\Tests\Controller; use Doctrine\ORM\EntityManagerInterface; @@ -47,7 +58,7 @@ public function testDateUrlDoesNotMatchPageDate(): void $em->persist($page); $em->flush(); - $client->request('GET', sprintf("/posts/%s/%s", '2020-01-01', $page->getSlug())); + $client->request('GET', \sprintf('/posts/%s/%s', '2020-01-01', $page->getSlug())); static::assertResponseStatusCodeSame(404); static::assertPageTitleContains('Date in URL does not match post\'s date.'); } @@ -68,7 +79,7 @@ public function testSuccessfulPost(): void $em->persist($page); $em->flush(); - $client->request('GET', sprintf("/posts/%s/%s", $now->format('Y-m-d'), $page->getSlug())); + $client->request('GET', \sprintf('/posts/%s/%s', $now->format('Y-m-d'), $page->getSlug())); static::assertResponseStatusCodeSame(200); static::assertPageTitleContains($page->getTitle()); } diff --git a/Tests/DependencyInjection/OrbitaleCmsExtensionTest.php b/Tests/DependencyInjection/OrbitaleCmsExtensionTest.php index 73dbe91..0debec6 100644 --- a/Tests/DependencyInjection/OrbitaleCmsExtensionTest.php +++ b/Tests/DependencyInjection/OrbitaleCmsExtensionTest.php @@ -1,27 +1,29 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Tests\DependencyInjection; use Orbitale\Bundle\CmsBundle\DependencyInjection\OrbitaleCmsExtension; +use Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Category; +use Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Page; use PHPUnit\Framework\TestCase; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Yaml\Yaml; -use Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Category; -use Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Page; class OrbitaleCmsExtensionTest extends TestCase { - public function testInexistentPageClass() + public function testInexistentPageClass(): void { $builder = new ContainerBuilder(); @@ -30,13 +32,13 @@ public function testInexistentPageClass() (new OrbitaleCmsExtension())->load([ 'orbitale_cms' => [ - 'page_class' => 'inexistent_page_class', + 'page_class' => 'inexistent_page_class', 'category_class' => Category::class, ], ], $builder); } - public function testInexistentCategoryClass() + public function testInexistentCategoryClass(): void { $builder = new ContainerBuilder(); @@ -45,7 +47,7 @@ public function testInexistentCategoryClass() (new OrbitaleCmsExtension())->load([ 'orbitale_cms' => [ - 'page_class' => Page::class, + 'page_class' => Page::class, 'category_class' => 'inexistent_category_class', ], ], $builder); @@ -53,11 +55,8 @@ public function testInexistentCategoryClass() /** * @dataProvider provideYamlConfiguration - * - * @param $config - * @param $expected */ - public function testYamlConfiguration($config, $expected) + public function testYamlConfiguration($config, $expected): void { $builder = new ContainerBuilder(); @@ -76,18 +75,18 @@ public function provideYamlConfiguration(): array { $dir = __DIR__.'/../Fixtures/App/extension_test/'; - $configFiles = glob($dir.'config_*.yaml', GLOB_NOSORT); - $resultFiles = glob($dir.'result_*.yaml', GLOB_NOSORT); + $configFiles = \glob($dir.'config_*.yaml', \GLOB_NOSORT); + $resultFiles = \glob($dir.'result_*.yaml', \GLOB_NOSORT); - sort($configFiles); - sort($resultFiles); + \sort($configFiles); + \sort($resultFiles); $tests = []; foreach ($configFiles as $k => $file) { $tests[] = [ - Yaml::parse(file_get_contents($file)), - Yaml::parse(file_get_contents($resultFiles[$k])), + Yaml::parse(\file_get_contents($file)), + Yaml::parse(\file_get_contents($resultFiles[$k])), ]; } diff --git a/Tests/Entity/CategoryTest.php b/Tests/Entity/CategoryTest.php index 5c5d0b6..593bc97 100644 --- a/Tests/Entity/CategoryTest.php +++ b/Tests/Entity/CategoryTest.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Tests\Entity; @@ -19,7 +21,7 @@ class CategoryTest extends AbstractTestCase { - public function testCategory() + public function testCategory(): void { $homepage = new Page(); $homepage->setHomepage(true); @@ -44,14 +46,14 @@ public function testCategory() $em->flush(); /** @var Page $homepage */ - $homepage = $em->getRepository(get_class($homepage))->find($homepage->getId()); + $homepage = $em->getRepository($homepage::class)->find($homepage->getId()); static::assertEquals($homepage->getCategory(), $category); static::assertEquals($category->getName(), (string) $category); static::assertFalse($category->isEnabled()); // Base value } - public function testIdenticalParent() + public function testIdenticalParent(): void { $category = new Category(); $category->setName('Default category'); @@ -61,7 +63,7 @@ public function testIdenticalParent() static::assertNull($category->getParent()); } - public function testLifecycleCallbacks() + public function testLifecycleCallbacks(): void { $category = new Category(); $category->setName('Default category'); @@ -85,7 +87,7 @@ public function testLifecycleCallbacks() static::assertEquals([$child], $category->getChildren()->toArray()); /** @var Category $category */ - $category = $em->getRepository(get_class($category))->findOneBy(['id' => $category->getId()]); + $category = $em->getRepository($category::class)->findOneBy(['id' => $category->getId()]); static::assertNotNull($category); @@ -94,13 +96,13 @@ public function testLifecycleCallbacks() $em->flush(); } - $category = $em->getRepository(get_class($category))->findOneBy(['id' => $category->getId()]); + $category = $em->getRepository($category::class)->findOneBy(['id' => $category->getId()]); static::assertNull($category); static::assertNull($child->getParent()); } - public function testRemoval() + public function testRemoval(): void { $category = new Category(); @@ -126,10 +128,10 @@ public function testRemoval() $em->flush(); /** @var Category $category */ - $category = $em->getRepository(get_class($category))->find($category->getId()); + $category = $em->getRepository($category::class)->find($category->getId()); $children = $category->getChildren(); - $first = $children[0]; + $first = $children[0]; static::assertEquals($child->getId(), $first->getId()); $category->removeChild($child); @@ -138,12 +140,12 @@ public function testRemoval() $em->remove($category); $em->flush(); - $child = $em->getRepository(get_class($child))->find($child->getId()); + $child = $em->getRepository($child::class)->find($child->getId()); static::assertNull($child->getParent()); } - public function testCategorySlugIsTransliterated() + public function testCategorySlugIsTransliterated(): void { $category = new Category(); $category->setName('Default category'); @@ -153,17 +155,17 @@ public function testCategorySlugIsTransliterated() static::assertEquals('default-category', $category->getSlug()); } - public function testCategorySlugIsNotTransliteratedIfEmpty() + public function testCategorySlugIsNotTransliteratedIfEmpty(): void { $category = new Category(); $category->setName(''); $category->updateSlug(); - static::assertEquals(null, $category->getSlug()); + static::assertNull($category->getSlug()); } - public function testSuccessfulValidation() + public function testSuccessfulValidation(): void { self::bootKernel(); $validator = self::getContainer()->get(ValidatorInterface::class); @@ -174,7 +176,7 @@ public function testSuccessfulValidation() $errors = $validator->validate($category); - self::assertCount(0, $errors); + static::assertCount(0, $errors); static::assertSame('Name', $category->getName()); static::assertSame('name', $category->getSlug()); @@ -183,7 +185,7 @@ public function testSuccessfulValidation() static::assertFalse($category->isEnabled()); } - public function testFailingValidationWithEmptyData() + public function testFailingValidationWithEmptyData(): void { self::bootKernel(); $validator = self::getContainer()->get(ValidatorInterface::class); @@ -192,11 +194,10 @@ public function testFailingValidationWithEmptyData() $errors = $validator->validate($category); - self::assertCount(2, $errors); - - self::assertSame('name', $errors[0]->getPropertyPath()); - self::assertSame('slug', $errors[1]->getPropertyPath()); + static::assertCount(2, $errors); + static::assertSame('name', $errors[0]->getPropertyPath()); + static::assertSame('slug', $errors[1]->getPropertyPath()); static::assertSame('', $category->getName()); static::assertSame('', $category->getSlug()); diff --git a/Tests/Entity/PageTest.php b/Tests/Entity/PageTest.php index ddd1cd3..22c42d8 100644 --- a/Tests/Entity/PageTest.php +++ b/Tests/Entity/PageTest.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Tests\Entity; @@ -33,7 +35,7 @@ public function getDummyPage(): Page return $page; } - public function testOneHomepage() + public function testOneHomepage(): void { $homepage = $this->getDummyPage(); @@ -45,7 +47,7 @@ public function testOneHomepage() $em->flush(); /** @var Page $homepage */ - $homepage = $em->getRepository(get_class($homepage))->find($homepage->getId()); + $homepage = $em->getRepository($homepage::class)->find($homepage->getId()); static::assertEquals($homepage->getTitle(), (string) $homepage); @@ -58,7 +60,7 @@ public function testOneHomepage() static::assertNull($homepage->getParent()); } - public function testLifecycleCallbacks() + public function testLifecycleCallbacks(): void { $homepage = $this->getDummyPage(); @@ -79,7 +81,7 @@ public function testLifecycleCallbacks() static::assertEquals([$child], $homepage->getChildren()->toArray()); /** @var Page $homepage */ - $homepage = $em->getRepository(get_class($homepage))->findOneBy(['id' => $homepage->getId()]); + $homepage = $em->getRepository($homepage::class)->findOneBy(['id' => $homepage->getId()]); static::assertNotNull($homepage); @@ -88,13 +90,13 @@ public function testLifecycleCallbacks() $em->flush(); } - $homepage = $em->getRepository(get_class($homepage))->findOneBy(['id' => $homepage->getId()]); + $homepage = $em->getRepository($homepage::class)->findOneBy(['id' => $homepage->getId()]); static::assertNull($homepage); static::assertNull($child->getParent()); } - public function testRemoval() + public function testRemoval(): void { $page = new Page(); $page->setTitle('Default page'); @@ -117,9 +119,10 @@ public function testRemoval() $em->persist($child); $em->flush(); - $page = $em->getRepository(get_class($page))->find($page->getId()); + $page = $em->getRepository($page::class)->find($page->getId()); $children = $page->getChildren(); + /** @var Page $first */ $first = $children[0]; static::assertEquals($child->getId(), $first->getId()); @@ -130,12 +133,12 @@ public function testRemoval() $em->remove($page); $em->flush(); - $child = $em->getRepository(get_class($child))->find($child->getId()); + $child = $em->getRepository($child::class)->find($child->getId()); static::assertNull($child->getParent()); } - public function testPageSlugIsTransliterated() + public function testPageSlugIsTransliterated(): void { $page = new Page(); $page->setTitle('Default page'); @@ -145,7 +148,7 @@ public function testPageSlugIsTransliterated() static::assertEquals('default-page', $page->getSlug()); } - public function testSuccessfulValidation() + public function testSuccessfulValidation(): void { self::bootKernel(); $validator = self::getContainer()->get(ValidatorInterface::class); @@ -156,7 +159,7 @@ public function testSuccessfulValidation() $errors = $validator->validate($page); - self::assertCount(0, $errors); + static::assertCount(0, $errors); static::assertSame('Title', $page->getTitle()); static::assertSame('title', $page->getSlug()); @@ -173,7 +176,7 @@ public function testSuccessfulValidation() static::assertFalse($page->isEnabled()); } - public function testFailingfulValidationWithEmptyData() + public function testFailingfulValidationWithEmptyData(): void { self::bootKernel(); $validator = self::getContainer()->get(ValidatorInterface::class); @@ -183,10 +186,10 @@ public function testFailingfulValidationWithEmptyData() /** @var ConstraintViolationInterface[]&ConstraintViolationListInterface $errors */ $errors = $validator->validate($page); - self::assertCount(2, $errors); + static::assertCount(2, $errors); - self::assertSame('title', $errors[0]->getPropertyPath()); - self::assertSame('slug', $errors[1]->getPropertyPath()); + static::assertSame('title', $errors[0]->getPropertyPath()); + static::assertSame('slug', $errors[1]->getPropertyPath()); static::assertSame('', $page->getTitle()); static::assertSame('', $page->getSlug()); diff --git a/Tests/EventListener/LayoutsListenerTest.php b/Tests/EventListener/LayoutsListenerTest.php index 330f22c..94e1941 100644 --- a/Tests/EventListener/LayoutsListenerTest.php +++ b/Tests/EventListener/LayoutsListenerTest.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Tests\EventListener; diff --git a/Tests/Fixtures/App/AppKernel.php b/Tests/Fixtures/App/AppKernel.php index a04b5e3..83200fc 100644 --- a/Tests/Fixtures/App/AppKernel.php +++ b/Tests/Fixtures/App/AppKernel.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Tests\Fixtures\App; @@ -30,16 +32,11 @@ public function registerBundles(): iterable ]; } - protected function prepareContainer(ContainerBuilder $container): void - { - parent::prepareContainer($container); - } - public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yaml'); - $loader->load(static function (ContainerBuilder $container) { + $loader->load(static function (ContainerBuilder $container): void { $container->register('logger', NullLogger::class); }); } @@ -63,4 +60,9 @@ public function getBuildDir(): string { return \dirname(__DIR__, 3).'/build/'; } + + protected function prepareContainer(ContainerBuilder $container): void + { + parent::prepareContainer($container); + } } diff --git a/Tests/Fixtures/TestBundle/Entity/Category.php b/Tests/Fixtures/TestBundle/Entity/Category.php index 06c0138..a7c19a6 100644 --- a/Tests/Fixtures/TestBundle/Entity/Category.php +++ b/Tests/Fixtures/TestBundle/Entity/Category.php @@ -1,19 +1,19 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity; use Orbitale\Bundle\CmsBundle\Entity\Category as BaseCategory; -use Doctrine\ORM\Mapping as ORM; -use Orbitale\Bundle\CmsBundle\Repository\CategoryRepository; class Category extends BaseCategory { diff --git a/Tests/Fixtures/TestBundle/Entity/Page.php b/Tests/Fixtures/TestBundle/Entity/Page.php index 9fc8a03..28e0dbf 100644 --- a/Tests/Fixtures/TestBundle/Entity/Page.php +++ b/Tests/Fixtures/TestBundle/Entity/Page.php @@ -1,19 +1,19 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity; use Orbitale\Bundle\CmsBundle\Entity\Page as BasePage; -use Doctrine\ORM\Mapping as ORM; -use Orbitale\Bundle\CmsBundle\Repository\PageRepository; class Page extends BasePage { diff --git a/Tests/Fixtures/TestBundle/Resources/config/doctrine/Category.orm.xml b/Tests/Fixtures/TestBundle/Resources/config/doctrine/Category.orm.xml index 56940e2..a21bcb7 100644 --- a/Tests/Fixtures/TestBundle/Resources/config/doctrine/Category.orm.xml +++ b/Tests/Fixtures/TestBundle/Resources/config/doctrine/Category.orm.xml @@ -8,4 +8,5 @@ - \ No newline at end of file + + diff --git a/Tests/Fixtures/TestBundle/Resources/config/doctrine/Page.orm.xml b/Tests/Fixtures/TestBundle/Resources/config/doctrine/Page.orm.xml index 6d8070d..40f9f54 100644 --- a/Tests/Fixtures/TestBundle/Resources/config/doctrine/Page.orm.xml +++ b/Tests/Fixtures/TestBundle/Resources/config/doctrine/Page.orm.xml @@ -9,4 +9,4 @@ - \ No newline at end of file + diff --git a/Tests/Fixtures/TestBundle/TestBundle.php b/Tests/Fixtures/TestBundle/TestBundle.php index 21cb017..ceea90d 100644 --- a/Tests/Fixtures/TestBundle/TestBundle.php +++ b/Tests/Fixtures/TestBundle/TestBundle.php @@ -1,19 +1,18 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; -class TestBundle extends Bundle -{ - -} +class TestBundle extends Bundle {} diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index b4abea8..60962a6 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -1,37 +1,40 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ use Orbitale\Bundle\CmsBundle\Tests\Fixtures\App\AppKernel; use Symfony\Component\Filesystem\Filesystem; $file = __DIR__.'/../vendor/autoload.php'; -if (!file_exists($file)) { +if (!\file_exists($file)) { throw new RuntimeException('Install dependencies to run test suite.'); } $autoload = require $file; require_once __DIR__.'/Fixtures/App/AppKernel.php'; -(static function(){ +(static function (): void { $fs = new Filesystem(); $kernel = new AppKernel('test', true); // Remove build dir files - if (is_dir($kernel->getBuildDir())) { + if (\is_dir($kernel->getBuildDir())) { echo "Removing files in the build directory.\n".__DIR__."\n"; + try { $fs->remove($kernel->getBuildDir()); } catch (Exception $e) { - fwrite(STDERR, $e->getMessage()); + \fwrite(\STDERR, $e->getMessage()); } } unset($kernel); diff --git a/Twig/CmsExtension.php b/Twig/CmsExtension.php index 4d7eba2..4a1bb37 100644 --- a/Twig/CmsExtension.php +++ b/Twig/CmsExtension.php @@ -1,13 +1,15 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the OrbitaleCmsBundle package. + * + * (c) Alexandre Rock Ancelet + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Orbitale\Bundle\CmsBundle\Twig; diff --git a/rector.php b/rector.php deleted file mode 100644 index e604067..0000000 --- a/rector.php +++ /dev/null @@ -1,21 +0,0 @@ -paths([ - __DIR__ . '/Entity', - ]); - - $rectorConfig->sets([ - \Rector\Doctrine\Set\DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES, - \Rector\Symfony\Set\SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES, - \Rector\Symfony\Set\SensiolabsSetList::ANNOTATIONS_TO_ATTRIBUTES, - ]); - $rectorConfig->ruleWithConfiguration(AnnotationToAttributeRector::class, [ - new AnnotationToAttribute(\Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity::class), - new AnnotationToAttribute(\Ibericode\Vat\Bundle\Validator\Constraints\VatNumber::class), - ]); -}; From 321a71292f1857a4122f9a479b2d7d61b4231e62 Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Thu, 28 Aug 2025 11:52:20 +0200 Subject: [PATCH 10/11] Move validation to xml too --- Entity/Category.php | 27 -------- Entity/Page.php | 57 ---------------- Resources/config/validation/validator.xml | 82 +++++++++++++++++++++++ Tests/Entity/CategoryTest.php | 2 +- 4 files changed, 83 insertions(+), 85 deletions(-) create mode 100644 Resources/config/validation/validator.xml diff --git a/Entity/Category.php b/Entity/Category.php index cf91be6..31bd67a 100644 --- a/Entity/Category.php +++ b/Entity/Category.php @@ -15,60 +15,33 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Event\PreRemoveEventArgs; -use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\String\Slugger\AsciiSlugger; -use Symfony\Component\Validator\Constraints as Assert; -/** - * @UniqueEntity("slug") - */ -#[UniqueEntity('slug')] abstract class Category { /** * @var string - * - * @Assert\Type("string") - * - * @Assert\NotBlank() */ - #[Assert\Type('string')] - #[Assert\NotBlank] protected $name; /** * @var string - * - * @Assert\Type("string") - * - * @Assert\NotBlank() */ - #[Assert\Type('string')] - #[Assert\NotBlank] protected $slug; /** * @var string - * - * @Assert\Type("string") */ - #[Assert\Type('string')] protected $description; /** * @var bool - * - * @Assert\Type("bool") */ - #[Assert\Type('bool')] protected $enabled = false; /** * @var Category - * - * @Assert\Type(Category::class) */ - #[Assert\Type(self::class)] protected $parent; /** diff --git a/Entity/Page.php b/Entity/Page.php index bc3cb61..003323f 100644 --- a/Entity/Page.php +++ b/Entity/Page.php @@ -15,140 +15,83 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Event\PreRemoveEventArgs; -use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\String\Slugger\AsciiSlugger; -use Symfony\Component\Validator\Constraints as Assert; -/** - * @UniqueEntity("slug") - */ -#[UniqueEntity('slug')] abstract class Page { /** * @var string - * - * @Assert\Type("string") - * - * @Assert\NotBlank() */ - #[Assert\Type('string')] - #[Assert\NotBlank] protected $title; /** * @var string - * - * @Assert\Type("string") - * - * @Assert\NotBlank() */ - #[Assert\Type('string')] - #[Assert\NotBlank] protected $slug; /** * @var string - * - * @Assert\Type("string") */ - #[Assert\Type('string')] protected $content; /** * @var string - * - * @Assert\Type("string") */ - #[Assert\Type('string')] protected $metaDescription; /** * @var string - * - * @Assert\Type("string") */ - #[Assert\Type('string')] protected $metaTitle; /** * @var string - * - * @Assert\Type("string") */ - #[Assert\Type('string')] protected $metaKeywords; /** * @var null|Category - * - * @Assert\Type(Category::class) */ - #[Assert\Type(Category::class)] protected $category; /** * @var string - * - * @Assert\Type("string") */ - #[Assert\Type('string')] protected $css; /** * @var string - * - * @Assert\Type("string") */ - #[Assert\Type('string')] protected $js; /** * @var \DateTimeImmutable - * - * @Assert\Type(\DateTimeImmutable::class) */ - #[Assert\Type(\DateTimeImmutable::class)] protected $createdAt; /** * @var bool - * - * @Assert\Type("bool") */ - #[Assert\Type('bool')] protected $enabled = false; /** * @var bool - * - * @Assert\Type("bool") */ - #[Assert\Type('bool')] protected $homepage = false; /** * @var string - * - * @Assert\Type("string") */ - #[Assert\Type('string')] protected $host; /** * @var string - * - * @Assert\Type("string") */ - #[Assert\Type('string')] protected $locale; /** * @var null|Page - * - * @Assert\Type(Page::class) */ - #[Assert\Type(self::class)] protected $parent; /** diff --git a/Resources/config/validation/validator.xml b/Resources/config/validation/validator.xml new file mode 100644 index 0000000..e25135c --- /dev/null +++ b/Resources/config/validation/validator.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/Entity/CategoryTest.php b/Tests/Entity/CategoryTest.php index 593bc97..99e35d3 100644 --- a/Tests/Entity/CategoryTest.php +++ b/Tests/Entity/CategoryTest.php @@ -162,7 +162,7 @@ public function testCategorySlugIsNotTransliteratedIfEmpty(): void $category->updateSlug(); - static::assertNull($category->getSlug()); + static::assertSame('', $category->getSlug()); } public function testSuccessfulValidation(): void From 5131338ddc6819ca6ef1b1cceb719aa166a6596a Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Thu, 28 Aug 2025 11:56:03 +0200 Subject: [PATCH 11/11] Prepare 5.0 --- CHANGELOG.md | 13 ++++++++++++- README.md | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab13b06..8deb898 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,15 @@ -#v4.1.0 +# v5.0.0 + +* Add support for Symfony 7. +* Drop support for Symfony 5, support starts at Symfony 6.4 now. +* Drop support for PHP 7 and 8.0, support starts at PHP 8.1 now. +* Base entities mapping is now in XML instead of annotations/attributes. +* Base entities validations rules are now in XML instead of annotations/attributes. +* Fix some PHP deprecations in types. +* Tests: revamp setup a bit, for modernisation. +* Dev: add CS fix setup + +# v4.1.0 * Make the project compatible with Symfony 6.0 * Test multiple versions of PHP and Symfony in CI diff --git a/README.md b/README.md index df70e0b..4cfafca 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ [![Build Status](https://travis-ci.org/Orbitale/CmsBundle.svg?branch=master)](https://travis-ci.org/Orbitale/CmsBundle) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Orbitale/CmsBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Orbitale/CmsBundle/?branch=master) -:warning: You're looking at the 4.x branch documentation.
+:warning: You're looking at the 5.x branch documentation.
+If you need information about 4.x, go [here](https://github.com/Orbitale/CmsBundle/tree/4.x) If you need information about 3.x, go [here](https://github.com/Orbitale/CmsBundle/tree/3.x) If you need information about 2.x, go [here](https://github.com/Orbitale/CmsBundle/tree/2.x) If you need information about 1.x, go [here](https://github.com/Orbitale/CmsBundle/tree/1.x)