- Issue created by @Grevil
- Merge request !8Issue #3492545: Create tests for the basic functionality of the module → (Closed) created by Grevil
- 🇩🇪Germany Grevil
For some reason the cookie is empty inside the tests. This doesn't make sense and I tried to find a reason why, but couldn't.
Not even @anybody could help us here, so we will end it here. The module functionality works great on actual sites, but for some reason not inside tests. Setting this to "Needs work". If anybody wants to finish this, go for it!
- First commit to issue fork.
- 🇩🇪Germany Anybody Porta Westfalica
@Grevil: This is what ChatGPT says:
The issue you're encountering is likely due to the way functional tests handle requests compared to regular requests in Symfony. In functional tests, the request stack might not be fully initialized or populated when you try to access it, which can result in `NULL` values.
To work around this, you can manually set up the request stack in your functional tests. Here's an example of how you can do this:
1. **Create a Test Client**: Use Symfony's test client to simulate requests.
2. **Set Up the Request Stack**: Manually set up the request stack before making the request.Here's a sample code snippet:
```php
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;class YourFunctionalTest extends WebTestCase
{
public function testYourFunction()
{
// Create a client to make requests
$client = static::createClient();// Create a request object
$request = Request::createFromGlobals();// Create a request stack and set the current request
$requestStack = new RequestStack();
$requestStack->setCurrentRequest($request);// Now you can use $this->requestStack->getCurrentRequest()->query->all()
$this->requestStack = $requestStack;// Make your request
$crawler = $client->request('GET', '/your-route');// Perform your assertions
$this->assertNotNull($this->requestStack->getCurrentRequest()->query->all());
}
}
```By manually setting up the request stack, you ensure that it is properly initialized and populated with the query parameters, allowing you to access them as expected.
Source: https://github.com/symfony/symfony/issues/24492
Looks valid?
- 🇩🇪Germany Anybody Porta Westfalica
Fixed in ✨ Add option to use other storage methods Active