From b71e83bce55abc64ced4bc4f566bc6d04666f80a Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 19 Feb 2024 02:20:27 +0100 Subject: [PATCH] adjust to sf6 --- .github/workflows/test-application.yaml | 2 +- composer.json | 7 ++- .../PublishWorkflowChecker.php | 3 -- src/Resources/config/publish-workflow.xml | 3 +- .../App/DataFixture/LoadRouteData.php | 2 +- tests/Fixtures/App/Document/Content.php | 20 ++++----- tests/Fixtures/App/Document/RouteAware.php | 14 +++--- tests/Fixtures/App/Kernel.php | 4 +- tests/Fixtures/App/config/config.php | 1 + tests/Fixtures/App/config/config.yml | 13 +++++- tests/Fixtures/App/config/services.yaml | 4 ++ .../Form/CheckboxUrlLabelFormTypeTest.php | 2 +- .../PublishWorkflow/PublishWorkflowTest.php | 44 +++++++++---------- .../Form/CheckboxUrlLabelFormTypeTest.php | 2 +- 14 files changed, 64 insertions(+), 57 deletions(-) create mode 100644 tests/Fixtures/App/config/services.yaml diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index ff97e8a..2bffe7f 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -14,7 +14,7 @@ jobs: name: 'PHP ${{ matrix.php-version }}, Symfony ${{ matrix.symfony-version }} ${{ matrix.dependencies}}' runs-on: ubuntu-20.04 env: - SYMFONY_PHPUNIT_VERSION: 8 + SYMFONY_PHPUNIT_VERSION: 9 SYMFONY_DEPRECATIONS_HELPER: "/.*each.*/" SYMFONY_REQUIRE: ${{ matrix.symfony-version }} diff --git a/composer.json b/composer.json index 207e37e..24ac336 100644 --- a/composer.json +++ b/composer.json @@ -22,8 +22,8 @@ "ext-dom": "*", "jackalope/jackalope-doctrine-dbal": "^1.3 || ^2.0", "mockery/mockery": "^1.4.1", - "symfony-cmf/routing-bundle": "dev-sf7 as 3.1.0", - "symfony-cmf/testing": "^4.0.0", + "symfony-cmf/routing-bundle": "3.1.0", + "symfony-cmf/testing": "5.0.2", "doctrine/dbal": "^3.8.1 || ^4.0", "doctrine/doctrine-bundle": "^2.0", "doctrine/phpcr-bundle": "^3.0", @@ -44,8 +44,7 @@ "suggest": { "symfony/twig-bundle": "To get access to the CMF twig extension", "symfony/security-bundle": "To be able to use the publish workflow system", - "symfony-cmf/routing": "To be able to use the CMF twig extension functions cmf_prev_linkable/cmf_next_linkable", - "symfony-cmf/routing-bundle": "To be able to enable the publish_workflow_listener", + "symfony-cmf/routing-bundle": "For the wtig extension functions cmf_prev_linkable/cmf_next_linkable and the publish_workflow_listener", "symfony-cmf/sonata-admin-integration-bundle": "To provide an admin interface for the PHPCR ODM documents." }, "autoload": { diff --git a/src/PublishWorkflow/PublishWorkflowChecker.php b/src/PublishWorkflow/PublishWorkflowChecker.php index b588c3f..f3b0b14 100644 --- a/src/PublishWorkflow/PublishWorkflowChecker.php +++ b/src/PublishWorkflow/PublishWorkflowChecker.php @@ -62,9 +62,6 @@ public function __construct( { } - /** - * {@inheritdoc} - */ public function isGranted(mixed $attribute, mixed $subject = null): bool { if (self::VIEW_ATTRIBUTE === $attribute diff --git a/src/Resources/config/publish-workflow.xml b/src/Resources/config/publish-workflow.xml index bd947ba..5eac110 100644 --- a/src/Resources/config/publish-workflow.xml +++ b/src/Resources/config/publish-workflow.xml @@ -6,9 +6,10 @@ + - unanimous + true diff --git a/tests/Fixtures/App/DataFixture/LoadRouteData.php b/tests/Fixtures/App/DataFixture/LoadRouteData.php index 832ba33..c3abebc 100644 --- a/tests/Fixtures/App/DataFixture/LoadRouteData.php +++ b/tests/Fixtures/App/DataFixture/LoadRouteData.php @@ -22,7 +22,7 @@ */ class LoadRouteData implements FixtureInterface { - public function load(ObjectManager $manager) + public function load(ObjectManager $manager): void { $root = $manager->find(null, '/'); diff --git a/tests/Fixtures/App/Document/Content.php b/tests/Fixtures/App/Document/Content.php index efb1cc2..6eab201 100644 --- a/tests/Fixtures/App/Document/Content.php +++ b/tests/Fixtures/App/Document/Content.php @@ -11,26 +11,26 @@ namespace Symfony\Cmf\Bundle\CoreBundle\Tests\Fixtures\App\Document; -use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\Common\Collections\Collection; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCRODM; +use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route; use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface; -/** - * @PHPCRODM\Document(referenceable=true) - */ +#[PHPCRODM\Document(referenceable: true)] class Content implements RouteReferrersReadInterface { - /** @PHPCRODM\Id */ - public $id; + #[PHPCRODM\Id] + public string $id; - /** @PHPCRODM\Referrers(referringDocument="Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route", referencedBy="content") */ - public $routes; + #[PHPCRODM\Referrers(referencedBy: 'content', referringDocument: Route::class)] + public array|Collection $routes; - public function getId() + public function getId(): string { return $this->id; } - public function getRoutes() + public function getRoutes(): iterable { return $this->routes; } diff --git a/tests/Fixtures/App/Document/RouteAware.php b/tests/Fixtures/App/Document/RouteAware.php index 1114497..98f3b4e 100644 --- a/tests/Fixtures/App/Document/RouteAware.php +++ b/tests/Fixtures/App/Document/RouteAware.php @@ -11,23 +11,21 @@ namespace Symfony\Cmf\Bundle\CoreBundle\Tests\Fixtures\App\Document; -use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCRODM; use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface; -/** - * @PHPCRODM\Document() - */ +#[PHPCRODM\Document] class RouteAware implements RouteReferrersReadInterface { - /** @PHPCRODM\Id */ - public $id; + #[PHPCRODM\Id] + public string $id; - public function getId() + public function getId(): string { return $this->id; } - public function getRoutes() + public function getRoutes(): iterable { return [1, 2]; } diff --git a/tests/Fixtures/App/Kernel.php b/tests/Fixtures/App/Kernel.php index c0d23ee..2e613b6 100644 --- a/tests/Fixtures/App/Kernel.php +++ b/tests/Fixtures/App/Kernel.php @@ -16,14 +16,14 @@ class Kernel extends TestKernel { - public function configure() + public function configure(): void { $this->requireBundleSets(['default', 'phpcr_odm']); $this->registerConfiguredBundles(); } - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load(__DIR__.'/config/config.php'); } diff --git a/tests/Fixtures/App/config/config.php b/tests/Fixtures/App/config/config.php index 5a1de8d..8111a05 100644 --- a/tests/Fixtures/App/config/config.php +++ b/tests/Fixtures/App/config/config.php @@ -15,6 +15,7 @@ $loader->import(__DIR__.'/cmf_core.yml'); $loader->import(__DIR__.'/cmf_routing.yml'); $loader->import(__DIR__.'/config.yml'); +$loader->import(__DIR__.'/services.yaml'); $container->loadFromExtension('framework', [ 'csrf_protection' => false, diff --git a/tests/Fixtures/App/config/config.yml b/tests/Fixtures/App/config/config.yml index f822f71..83deac7 100644 --- a/tests/Fixtures/App/config/config.yml +++ b/tests/Fixtures/App/config/config.yml @@ -1,4 +1,13 @@ # for cmf routing bundle framework: - property_access: ~ - annotations: ~ + property_access: ~ + http_method_override: false + handle_all_throwables: true + php_errors: + log: true + session: + handler_id: null + cookie_secure: auto + cookie_samesite: lax + validation: + email_validation_mode: html5 diff --git a/tests/Fixtures/App/config/services.yaml b/tests/Fixtures/App/config/services.yaml new file mode 100644 index 0000000..68ce253 --- /dev/null +++ b/tests/Fixtures/App/config/services.yaml @@ -0,0 +1,4 @@ +services: + form_factory_public: + public: true + alias: form.factory diff --git a/tests/Functional/Form/CheckboxUrlLabelFormTypeTest.php b/tests/Functional/Form/CheckboxUrlLabelFormTypeTest.php index 5b94097..f82f84a 100644 --- a/tests/Functional/Form/CheckboxUrlLabelFormTypeTest.php +++ b/tests/Functional/Form/CheckboxUrlLabelFormTypeTest.php @@ -26,7 +26,7 @@ public function setUp(): void public function testFormTwigTemplate(): void { - $view = self::getContainer()->get('test.service_container')->get('form.factory')->createNamedBuilder('name') + $view = self::getContainer()->get('form_factory_public')->createNamedBuilder('name') ->add('terms', CheckboxUrlLabelFormType::class, [ 'label' => '%a% and %b% and %c%', 'routes' => [ diff --git a/tests/Functional/PublishWorkflow/PublishWorkflowTest.php b/tests/Functional/PublishWorkflow/PublishWorkflowTest.php index 351a0ec..8c67aef 100644 --- a/tests/Functional/PublishWorkflow/PublishWorkflowTest.php +++ b/tests/Functional/PublishWorkflow/PublishWorkflowTest.php @@ -16,83 +16,81 @@ use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker; use Symfony\Cmf\Component\Testing\Functional\BaseTestCase; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; -use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Symfony\Component\Security\Core\User\UserInterface; class PublishWorkflowTest extends BaseTestCase { - /** - * @var AuthorizationCheckerInterface - */ - private $publishWorkflowChecker; - - /** - * @var TokenStorageInterface - */ - private $tokenStorage; + private AuthorizationCheckerInterface $publishWorkflowChecker; + private TokenStorageInterface $tokenStorage; public function setUp(): void { - $this->publishWorkflowChecker = $this->getContainer()->get('cmf_core.publish_workflow.checker'); - $this->tokenStorage = $this->getContainer()->get('test.service_container')->get('security.token_storage'); + $this->publishWorkflowChecker = self::getContainer()->get('cmf_core.publish_workflow.checker'); + $this->tokenStorage = self::getContainer()->get('test.service_container')->get('security.token_storage'); } - public function testPublishable() + public function testPublishable(): void { $doc = $this->createMock(PublishableReadInterface::class); $doc ->method('isPublishable') - ->will($this->returnValue(true)) + ->willReturn(true) ; $this->assertTrue($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $doc)); $this->assertTrue($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE, $doc)); } - public function testPublishPeriod() + public function testPublishPeriod(): void { $doc = $this->createMock(PublishModel::class); $doc ->method('isPublishable') - ->will($this->returnValue(true)) + ->willReturn(true) ; $doc ->method('getPublishEndDate') - ->will($this->returnValue(new \DateTime('01/01/1980'))) + ->willReturn(new \DateTime('01/01/1980')) ; $this->assertFalse($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $doc)); $this->assertFalse($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE, $doc)); } - public function testIgnoreRoleHas() + public function testIgnoreRoleHas(): void { $doc = $this->createMock(PublishModel::class); $doc ->method('isPublishable') - ->will($this->returnValue(false)) + ->willReturn(false) ; $roles = [ 'ROLE_CAN_VIEW_NON_PUBLISHED', ]; - $token = new UsernamePasswordToken('test', 'pass', 'testprovider', $roles); + $token = $this->createMock(TokenInterface::class); + $token->method('getUser')->willReturn($this->createMock(UserInterface::class)); // authorization checker will ignore roles if user is null + $token->method('getRoleNames')->willReturn($roles); $this->tokenStorage->setToken($token); $this->assertTrue($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $doc)); $this->assertFalse($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE, $doc)); } - public function testIgnoreRoleNotHas() + public function testIgnoreRoleNotHas(): void { $doc = $this->createMock(PublishModel::class); $doc ->method('isPublishable') - ->will($this->returnValue(false)) + ->willReturn(false) ; $roles = [ 'OTHER_ROLE', ]; - $token = new UsernamePasswordToken('test', 'pass', 'testprovider', $roles); + $token = $this->createMock(TokenInterface::class); + $token->method('getUser')->willReturn($this->createMock(UserInterface::class)); + $token->method('getRoleNames')->willReturn($roles); $this->tokenStorage->setToken($token); $this->assertFalse($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $doc)); diff --git a/tests/Unit/Form/CheckboxUrlLabelFormTypeTest.php b/tests/Unit/Form/CheckboxUrlLabelFormTypeTest.php index b9df4b2..d270683 100644 --- a/tests/Unit/Form/CheckboxUrlLabelFormTypeTest.php +++ b/tests/Unit/Form/CheckboxUrlLabelFormTypeTest.php @@ -20,7 +20,7 @@ class Router implements RouterInterface { - public function setContext(RequestContext $context) + public function setContext(RequestContext $context): void { }