generated from rich-id/bundle-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matthias Devlamynck
committed
Mar 1, 2024
1 parent
0bd7ada
commit fde3a9e
Showing
20 changed files
with
2,377 additions
and
2,611 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
namespace RichCongress\WebTestBundle\TestCase; | ||
|
||
use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig; | ||
use RichCongress\TestFramework\TestConfiguration\Attribute\TestConfig; | ||
use RichCongress\WebTestBundle\TestCase\TestTrait\ControllerTestUtilitiesTrait; | ||
use RichCongress\WebTestBundle\TestCase\TestTrait\WebTestAssertionsTrait; | ||
|
||
|
@@ -12,8 +12,8 @@ | |
* @package RichCongress\WebTestBundle\TestCase | ||
* @author Nicolas Guilloux <[email protected]> | ||
* @copyright 2014 - 2020 RichCongress (https://www.richcongress.com) | ||
* @TestConfig("kernel") | ||
*/ | ||
#[TestConfig('kernel')] | ||
abstract class ControllerTestCase extends TestCase | ||
{ | ||
use WebTestAssertionsTrait; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace RichCongress\WebTestBundle\TestCase\TestTrait; | ||
|
||
use RichCongress\WebTestBundle\WebTest\Client; | ||
use Symfony\Component\BrowserKit\Cookie; | ||
use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\HttpFoundation\Session\SessionFactoryInterface; | ||
|
||
trait WithSessionTrait | ||
{ | ||
private function withSession(Client $client, callable $callback): mixed | ||
{ | ||
$container = $client->getBrowser()->getContainer(); | ||
$requestStack = $container->get(RequestStack::class); | ||
$sessionFactory = $container->get('session.factory'); | ||
$cookies = $client->getBrowser()->getCookieJar(); | ||
|
||
$session = $sessionFactory->createSession(); | ||
$cookie = $cookies->get($session->getName()); | ||
|
||
if ($cookie !== null) { | ||
$session->setId($cookie->getValue()); | ||
} | ||
|
||
$session->start(); | ||
|
||
$request = new Request(); | ||
$request->setSession($session); | ||
$requestStack->push($request); | ||
|
||
$result = $callback($session); | ||
|
||
$requestStack->pop(); | ||
$session->save(); | ||
|
||
$cookie = new Cookie($session->getName(), $session->getId()); | ||
$cookies->set($cookie); | ||
|
||
return $result; | ||
} | ||
} |
Oops, something went wrong.