From 7bf924389d5bd6ce6919f717c089929ed519b691 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 | 2 +- .../PublishWorkflowChecker.php | 3 -- src/Resources/config/publish-workflow.xml | 3 +- tests/Fixtures/App/Document/Content.php | 20 ++++----- tests/Fixtures/App/Document/RouteAware.php | 14 +++--- tests/Fixtures/App/config/config.php | 1 + tests/Fixtures/App/config/config.yml | 1 - tests/Fixtures/App/config/services.yaml | 4 ++ .../Form/CheckboxUrlLabelFormTypeTest.php | 2 +- .../PublishWorkflow/PublishWorkflowTest.php | 44 +++++++++---------- .../Form/CheckboxUrlLabelFormTypeTest.php | 2 +- 12 files changed, 48 insertions(+), 50 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..0ff7636 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "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/testing": "dev-sf7 as 5.0.0", "doctrine/dbal": "^3.8.1 || ^4.0", "doctrine/doctrine-bundle": "^2.0", "doctrine/phpcr-bundle": "^3.0", 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/Document/Content.php b/tests/Fixtures/App/Document/Content.php index efb1cc2..a29da7e 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\Component\Routing\RouteReferrersReadInterface; +use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route; -/** - * @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/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..5107812 100644 --- a/tests/Fixtures/App/config/config.yml +++ b/tests/Fixtures/App/config/config.yml @@ -1,4 +1,3 @@ # for cmf routing bundle framework: property_access: ~ - annotations: ~ 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 { }