Skip to content

Commit f9d27c6

Browse files
committed
fix security test config on lower sf version
1 parent ce84462 commit f9d27c6

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/LiveComponent/tests/Fixtures/Kernel.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Psr\Log\NullLogger;
1717
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
1818
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
19+
use Symfony\Bundle\SecurityBundle\Security;
1920
use Symfony\Bundle\SecurityBundle\SecurityBundle;
2021
use Symfony\Bundle\TwigBundle\TwigBundle;
2122
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
@@ -118,13 +119,19 @@ protected function configureContainer(ContainerConfigurator $c): void
118119
'default_path' => '%kernel.project_dir%/tests/Fixtures/templates',
119120
]);
120121

121-
$c->extension('security', [
122+
$security = [
122123
'password_hashers' => [InMemoryUser::class => 'plaintext'],
123124
'providers' => ['users' => ['memory' => ['users' => ['kevin' => ['password' => 'pass', 'roles' => ['ROLE_USER']]]]]],
124125
'firewalls' => ['main' => [
125126
'lazy' => true,
126127
]],
127-
]);
128+
];
129+
130+
if (!class_exists(Security::class)) {
131+
$security['enable_authenticator_manager'] = true;
132+
}
133+
134+
$c->extension('security', $security);
128135

129136
$c->extension('twig_component', [
130137
'defaults' => [

src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\DomCrawler\Crawler;
1616
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1717
use Symfony\Component\Security\Core\User\InMemoryUser;
18+
use Symfony\Component\Security\Http\Attribute\IsGranted;
1819
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\Entity1;
1920
use Symfony\UX\LiveComponent\Tests\LiveComponentTestHelper;
2021
use Zenstruck\Browser\Test\HasBrowser;
@@ -504,6 +505,10 @@ public function testWithNullableEntity(): void
504505

505506
public function testCanHaveControllerAttributes(): void
506507
{
508+
if (!class_exists(IsGranted::class)) {
509+
$this->markTestSkipped('The security attributes are not available.');
510+
}
511+
507512
$dehydrated = $this->dehydrateComponent($this->mountComponent('with_security'));
508513

509514
$this->browser()

src/LiveComponent/tests/Functional/Test/InteractsWithLiveComponentsTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
1515
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
1616
use Symfony\Component\Security\Core\User\InMemoryUser;
17+
use Symfony\Component\Security\Http\Attribute\IsGranted;
1718
use Symfony\UX\LiveComponent\Test\InteractsWithLiveComponents;
1819
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\Component2;
1920

@@ -145,6 +146,10 @@ public function testCannotUpdateComponentIfNoLongerInContext(): void
145146

146147
public function testRenderingIsLazy(): void
147148
{
149+
if (!class_exists(IsGranted::class)) {
150+
$this->markTestSkipped('The security attributes are not available.');
151+
}
152+
148153
$testComponent = $this->createLiveComponent('with_security');
149154

150155
$this->expectException(AccessDeniedException::class);

0 commit comments

Comments
 (0)