Skip to content

Commit 603071a

Browse files
committed
adjust to sf6
1 parent b50b8d0 commit 603071a

File tree

12 files changed

+49
-52
lines changed

12 files changed

+49
-52
lines changed

.github/workflows/test-application.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
name: 'PHP ${{ matrix.php-version }}, Symfony ${{ matrix.symfony-version }} ${{ matrix.dependencies}}'
1515
runs-on: ubuntu-20.04
1616
env:
17-
SYMFONY_PHPUNIT_VERSION: 8
17+
SYMFONY_PHPUNIT_VERSION: 9
1818
SYMFONY_DEPRECATIONS_HELPER: "/.*each.*/"
1919
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}
2020

composer.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"jackalope/jackalope-doctrine-dbal": "^1.3 || ^2.0",
2424
"mockery/mockery": "^1.4.1",
2525
"symfony-cmf/routing-bundle": "dev-sf7 as 3.1.0",
26-
"symfony-cmf/testing": "^4.0.0",
26+
"symfony-cmf/testing": "dev-sf7 as 5.0.0",
2727
"doctrine/dbal": "^3.8.1 || ^4.0",
2828
"doctrine/doctrine-bundle": "^2.0",
2929
"doctrine/phpcr-bundle": "^3.0",
@@ -44,8 +44,7 @@
4444
"suggest": {
4545
"symfony/twig-bundle": "To get access to the CMF twig extension",
4646
"symfony/security-bundle": "To be able to use the publish workflow system",
47-
"symfony-cmf/routing": "To be able to use the CMF twig extension functions cmf_prev_linkable/cmf_next_linkable",
48-
"symfony-cmf/routing-bundle": "To be able to enable the publish_workflow_listener",
47+
"symfony-cmf/routing-bundle": "For the wtig extension functions cmf_prev_linkable/cmf_next_linkable and the publish_workflow_listener",
4948
"symfony-cmf/sonata-admin-integration-bundle": "To provide an admin interface for the PHPCR ODM documents."
5049
},
5150
"autoload": {

src/PublishWorkflow/PublishWorkflowChecker.php

-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ public function __construct(
6262
{
6363
}
6464

65-
/**
66-
* {@inheritdoc}
67-
*/
6865
public function isGranted(mixed $attribute, mixed $subject = null): bool
6966
{
7067
if (self::VIEW_ATTRIBUTE === $attribute

src/Resources/config/publish-workflow.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
<services>
88

9+
<service id="cmf_core.publish_workflow.access_decision_manager.strategy" class="Symfony\Component\Security\Core\Authorization\Strategy\UnanimousStrategy"/>
910
<service id="cmf_core.publish_workflow.access_decision_manager" class="Symfony\Component\Security\Core\Authorization\AccessDecisionManager">
1011
<argument type="collection"/>
11-
<argument>unanimous</argument>
12+
<argument type="service" id="cmf_core.publish_workflow.access_decision_manager.strategy"/>
1213
<argument>true</argument>
1314
</service>
1415

tests/Fixtures/App/Document/Content.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@
1111

1212
namespace Symfony\Cmf\Bundle\CoreBundle\Tests\Fixtures\App\Document;
1313

14-
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
14+
use Doctrine\Common\Collections\Collection;
15+
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCRODM;
16+
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
1517
use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface;
1618

17-
/**
18-
* @PHPCRODM\Document(referenceable=true)
19-
*/
19+
#[PHPCRODM\Document(referenceable: true)]
2020
class Content implements RouteReferrersReadInterface
2121
{
22-
/** @PHPCRODM\Id */
23-
public $id;
22+
#[PHPCRODM\Id]
23+
public string $id;
2424

25-
/** @PHPCRODM\Referrers(referringDocument="Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route", referencedBy="content") */
26-
public $routes;
25+
#[PHPCRODM\Referrers(referencedBy: 'content', referringDocument: Route::class)]
26+
public array|Collection $routes;
2727

28-
public function getId()
28+
public function getId(): string
2929
{
3030
return $this->id;
3131
}
3232

33-
public function getRoutes()
33+
public function getRoutes(): iterable
3434
{
3535
return $this->routes;
3636
}

tests/Fixtures/App/Document/RouteAware.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,21 @@
1111

1212
namespace Symfony\Cmf\Bundle\CoreBundle\Tests\Fixtures\App\Document;
1313

14-
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
14+
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCRODM;
1515
use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface;
1616

17-
/**
18-
* @PHPCRODM\Document()
19-
*/
17+
#[PHPCRODM\Document]
2018
class RouteAware implements RouteReferrersReadInterface
2119
{
22-
/** @PHPCRODM\Id */
23-
public $id;
20+
#[PHPCRODM\Id]
21+
public string $id;
2422

25-
public function getId()
23+
public function getId(): string
2624
{
2725
return $this->id;
2826
}
2927

30-
public function getRoutes()
28+
public function getRoutes(): iterable
3129
{
3230
return [1, 2];
3331
}

tests/Fixtures/App/config/config.php

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
$loader->import(__DIR__.'/cmf_core.yml');
1616
$loader->import(__DIR__.'/cmf_routing.yml');
1717
$loader->import(__DIR__.'/config.yml');
18+
$loader->import(__DIR__.'/services.yaml');
1819

1920
$container->loadFromExtension('framework', [
2021
'csrf_protection' => false,

tests/Fixtures/App/config/config.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# for cmf routing bundle
22
framework:
33
property_access: ~
4-
annotations: ~
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
form_factory_public:
3+
public: true
4+
alias: form.factory

tests/Functional/Form/CheckboxUrlLabelFormTypeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function setUp(): void
2626

2727
public function testFormTwigTemplate(): void
2828
{
29-
$view = self::getContainer()->get('test.service_container')->get('form.factory')->createNamedBuilder('name')
29+
$view = self::getContainer()->get('form_factory_public')->createNamedBuilder('name')
3030
->add('terms', CheckboxUrlLabelFormType::class, [
3131
'label' => '%a% and %b% and %c%',
3232
'routes' => [

tests/Functional/PublishWorkflow/PublishWorkflowTest.php

+21-23
Original file line numberDiff line numberDiff line change
@@ -16,83 +16,81 @@
1616
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker;
1717
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase;
1818
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
19-
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
19+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2020
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
21+
use Symfony\Component\Security\Core\User\UserInterface;
2122

2223
class PublishWorkflowTest extends BaseTestCase
2324
{
24-
/**
25-
* @var AuthorizationCheckerInterface
26-
*/
27-
private $publishWorkflowChecker;
28-
29-
/**
30-
* @var TokenStorageInterface
31-
*/
32-
private $tokenStorage;
25+
private AuthorizationCheckerInterface $publishWorkflowChecker;
26+
private TokenStorageInterface $tokenStorage;
3327

3428
public function setUp(): void
3529
{
36-
$this->publishWorkflowChecker = $this->getContainer()->get('cmf_core.publish_workflow.checker');
37-
$this->tokenStorage = $this->getContainer()->get('test.service_container')->get('security.token_storage');
30+
$this->publishWorkflowChecker = self::getContainer()->get('cmf_core.publish_workflow.checker');
31+
$this->tokenStorage = self::getContainer()->get('test.service_container')->get('security.token_storage');
3832
}
3933

40-
public function testPublishable()
34+
public function testPublishable(): void
4135
{
4236
$doc = $this->createMock(PublishableReadInterface::class);
4337
$doc
4438
->method('isPublishable')
45-
->will($this->returnValue(true))
39+
->willReturn(true)
4640
;
4741

4842
$this->assertTrue($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $doc));
4943
$this->assertTrue($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE, $doc));
5044
}
5145

52-
public function testPublishPeriod()
46+
public function testPublishPeriod(): void
5347
{
5448
$doc = $this->createMock(PublishModel::class);
5549
$doc
5650
->method('isPublishable')
57-
->will($this->returnValue(true))
51+
->willReturn(true)
5852
;
5953
$doc
6054
->method('getPublishEndDate')
61-
->will($this->returnValue(new \DateTime('01/01/1980')))
55+
->willReturn(new \DateTime('01/01/1980'))
6256
;
6357

6458
$this->assertFalse($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $doc));
6559
$this->assertFalse($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE, $doc));
6660
}
6761

68-
public function testIgnoreRoleHas()
62+
public function testIgnoreRoleHas(): void
6963
{
7064
$doc = $this->createMock(PublishModel::class);
7165
$doc
7266
->method('isPublishable')
73-
->will($this->returnValue(false))
67+
->willReturn(false)
7468
;
7569
$roles = [
7670
'ROLE_CAN_VIEW_NON_PUBLISHED',
7771
];
78-
$token = new UsernamePasswordToken('test', 'pass', 'testprovider', $roles);
72+
$token = $this->createMock(TokenInterface::class);
73+
$token->method('getUser')->willReturn($this->createMock(UserInterface::class)); // authorization checker will ignore roles if user is null
74+
$token->method('getRoleNames')->willReturn($roles);
7975
$this->tokenStorage->setToken($token);
8076

8177
$this->assertTrue($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $doc));
8278
$this->assertFalse($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE, $doc));
8379
}
8480

85-
public function testIgnoreRoleNotHas()
81+
public function testIgnoreRoleNotHas(): void
8682
{
8783
$doc = $this->createMock(PublishModel::class);
8884
$doc
8985
->method('isPublishable')
90-
->will($this->returnValue(false))
86+
->willReturn(false)
9187
;
9288
$roles = [
9389
'OTHER_ROLE',
9490
];
95-
$token = new UsernamePasswordToken('test', 'pass', 'testprovider', $roles);
91+
$token = $this->createMock(TokenInterface::class);
92+
$token->method('getUser')->willReturn($this->createMock(UserInterface::class));
93+
$token->method('getRoleNames')->willReturn($roles);
9694
$this->tokenStorage->setToken($token);
9795

9896
$this->assertFalse($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $doc));

tests/Unit/Form/CheckboxUrlLabelFormTypeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class Router implements RouterInterface
2222
{
23-
public function setContext(RequestContext $context)
23+
public function setContext(RequestContext $context): void
2424
{
2525
}
2626

0 commit comments

Comments
 (0)