Skip to content

Commit d9c04bf

Browse files
committed
feat(live): add TestLiveComponent::actingAs()
1 parent 50ac534 commit d9c04bf

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/LiveComponent/src/Test/TestLiveComponent.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
1515
use Symfony\Component\HttpFoundation\Response;
1616
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
17+
use Symfony\Component\Security\Core\User\UserInterface;
1718
use Symfony\UX\LiveComponent\LiveComponentHydrator;
1819
use Symfony\UX\LiveComponent\Metadata\LiveComponentMetadataFactory;
1920
use Symfony\UX\TwigComponent\ComponentFactory;
@@ -76,6 +77,16 @@ public function component(): object
7677
return (new MountedComponent($this->metadata->getName(), $component, $componentAttributes))->getComponent();
7778
}
7879

80+
/**
81+
* @param UserInterface $user
82+
*/
83+
public function actingAs(object $user, string $firewallContext = 'main'): self
84+
{
85+
$this->client->loginUser($user, $firewallContext);
86+
87+
return $this;
88+
}
89+
7990
/**
8091
* @param array<string,mixed> $arguments
8192
*/

0 commit comments

Comments
 (0)