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
Feb 28, 2024
1 parent
0bd7ada
commit 98dac69
Showing
20 changed files
with
2,383 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,35 @@ | ||
<?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\RequestStack; | ||
use Symfony\Component\HttpFoundation\Session\SessionFactoryInterface; | ||
|
||
trait WithSessionTrait | ||
{ | ||
private function withSession(Client $client, RequestStack $requestStack, SessionFactoryInterface $sessionFactory, callable $callback): mixed | ||
{ | ||
$cookies = $client->getBrowser()->getCookieJar(); | ||
|
||
try { | ||
$session = $requestStack->getSession(); | ||
} catch (SessionNotFoundException $e) { | ||
$session = $sessionFactory->createSession(); | ||
} | ||
|
||
$cookie = $cookies->get($session->getName()); | ||
if ($cookie !== null) { | ||
$session->setId($cookie->getValue()); | ||
} | ||
|
||
$result = $callback($session); | ||
|
||
$cookie = new Cookie($session->getName(), $session->getId()); | ||
$cookies->set($cookie); | ||
|
||
return $result; | ||
} | ||
} |
Oops, something went wrong.