-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Description
Symfony version(s) affected
7.3.4
Description
Trying to upgrade to 7.3.4, one of my WebTestCase failed early.
After some investigation, it seems related to this fix: #61605.
To be more specific issue happens because:
- method parse() in ExpressionLanguage shoud return a ParsedExpression.
- $this->cache->getItem() in this same method return a closure, due to the change in PhpFileAdapter line 120
Previous line was $values[$id] = $value(); now it's $values[$id] = $value; and failed.
I don't understand reason for this change so I can't be more specific. I can reproduce with a simple WebTestCase
How to reproduce
We can build a simple controller with an Expression language, and a simple test to trigger the issue.
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
#[IsGranted(new Expression("'ROLE_OWNER' in user.getRoles() or 'ROLE_ADMIN' in user.getRoles()"))]
class ReproducerController extends AbstractController
{
#[Route('/break', name: 'break')]
public function break(Request $request): JsonResponse
{
return new JsonResponse([
'success' => true,
]);
}
}
<?php
namespace App\Tests\Smoke;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ReproducerTest extends WebTestCase
{
public function testSomething(): void
{
// This calls KernelTestCase::bootKernel(), and creates a
// "client" that is acting as the browser
$client = static::createClient();
// Request a specific page
$crawler = $client->request('GET', '/break');
// Validate a successful response and some content
$this->assertResponseIsSuccessful();
}
}
Result:
ExpressionLanguage\ParsedExpression, Closure returned (500 Internal Server Error)
/var/www/sf/vendor/symfony/framework-bundle/Test/BrowserKitAssertionsTrait.php:148
/var/www/sf/vendor/symfony/framework-bundle/Test/BrowserKitAssertionsTrait.php:33
/var/www/sf/tests/Smoke/ReproducerTest.php:19
Caused by
ErrorException: Symfony\Component\ExpressionLanguage\ExpressionLanguage::parse(): Return value must be of type Symfony\Component\ExpressionLanguage\ParsedExpression, Closure returned
Possible Solution
No response
Additional Context
No response