Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/LiveComponent/src/Test/InteractsWithLiveComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorageFactory;
use Symfony\UX\TwigComponent\ComponentFactory;

/**
Expand All @@ -34,6 +38,19 @@ protected function createLiveComponent(string $name, array $data = [], ?KernelBr
throw new \LogicException(\sprintf('The "%s" component is not a live component.', $name));
}

/** @var RequestStack $requestStack */
$requestStack = self::getContainer()->get(RequestStack::class);
if (null === $requestStack->getMainRequest() && null === $requestStack->getCurrentRequest()) {
$request = new Request();

/** @var MockFileSessionStorageFactory $sessionFactory */
$sessionFactory = self::getContainer()->get('session.storage.factory.mock_file');
$session = new Session($sessionFactory->createStorage($request));

$request->setSession($session);
$requestStack->push($request);
}

return new TestLiveComponent(
$metadata,
$data,
Expand Down