Skip to content

Commit 04f7111

Browse files
Merge branch '7.4' into 8.0
* 7.4: [HttpFoundation] Fix session cookie_lifetime not applied in mock session storage [Validator] Fix test [Serializer] Fix denormalization of magic `__set` properties [Config] Fix NodeDefinition template to be covariant Add 'sms' to hostless schemes [Validator] Fix required options check when extending a constraint with a simplified constructor [Validator] Skip ExpressionLanguage requirement in When constraint for closure expressions [Cache] Add timeout and slot eviction to LockRegistry stampede prevention [Console] Fix OUTPUT_RAW corrupting binary content on Windows [Form] Fix session data contamination by non-serializable objects in form flow [Mime] Use shell_exec() instead of passthru() in FileBinaryMimeTypeGuesser [HttpClient] Fix streaming from CachingHttpClient [DoctrineBridge] Rename `_schema_subscriber_check` table to `schema_subscriber_check_` for Oracle compatibility [HttpClient] Fix CachingHttpClient compatibility with decorator clients on 304 responses [FrameworkBundle] Fix stale container after reboot in KernelTestCase [Form] Fix duplicate validation errors when ValidatorExtension is instantiated multiple times
2 parents 28251d6 + 3a1a460 commit 04f7111

File tree

4 files changed

+89
-1
lines changed

4 files changed

+89
-1
lines changed

Constraints/When.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class When extends Composite
4040
*/
4141
public function __construct(string|Expression|\Closure $expression, array|Constraint|null $constraints = null, ?array $values = null, ?array $groups = null, $payload = null, ?array $options = null, array|Constraint $otherwise = [])
4242
{
43-
if (!class_exists(ExpressionLanguage::class)) {
43+
if (!$expression instanceof \Closure && !class_exists(ExpressionLanguage::class)) {
4444
throw new LogicException(\sprintf('The "symfony/expression-language" component is required to use the "%s" constraint. Try running "composer require symfony/expression-language".', __CLASS__));
4545
}
4646

Tests/ConstraintTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Validator\Exception\InvalidArgumentException;
1717
use Symfony\Component\Validator\Tests\Fixtures\ClassConstraint;
1818
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
19+
use Symfony\Component\Validator\Tests\Fixtures\CustomRegex;
1920

2021
class ConstraintTest extends TestCase
2122
{
@@ -74,4 +75,11 @@ public function testGetErrorNameForUnknownCode()
7475
$this->expectException(InvalidArgumentException::class);
7576
Constraint::getErrorName(1);
7677
}
78+
79+
public function testChildConstraintCanSatisfyRequiredOptionsOfParent()
80+
{
81+
$constraint = new CustomRegex();
82+
83+
$this->assertSame('/^xxxxx$/', $constraint->pattern);
84+
}
7785
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Tests\Constraints;
13+
14+
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
15+
use PHPUnit\Framework\TestCase;
16+
use Symfony\Bridge\PhpUnit\ClassExistsMock;
17+
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
18+
use Symfony\Component\Validator\Constraints\NotNull;
19+
use Symfony\Component\Validator\Constraints\When;
20+
use Symfony\Component\Validator\Exception\LogicException;
21+
22+
#[RunTestsInSeparateProcesses]
23+
final class WhenWithoutExpressionLanguageTest extends TestCase
24+
{
25+
public static function setUpBeforeClass(): void
26+
{
27+
ClassExistsMock::register(When::class);
28+
ClassExistsMock::withMockedClasses([
29+
ExpressionLanguage::class => false,
30+
]);
31+
}
32+
33+
public static function tearDownAfterClass(): void
34+
{
35+
ClassExistsMock::withMockedClasses([]);
36+
}
37+
38+
public function testClosureDoesNotRequireExpressionLanguage()
39+
{
40+
$when = new When(
41+
expression: static fn () => true,
42+
constraints: [new NotNull()],
43+
);
44+
45+
self::assertInstanceOf(\Closure::class, $when->expression);
46+
}
47+
48+
public function testStringExpressionRequiresExpressionLanguage()
49+
{
50+
$this->expectException(LogicException::class);
51+
$this->expectExceptionMessage('The "symfony/expression-language" component is required');
52+
53+
new When(
54+
expression: 'true',
55+
constraints: [new NotNull()],
56+
);
57+
}
58+
}

Tests/Fixtures/CustomRegex.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Tests\Fixtures;
13+
14+
use Symfony\Component\Validator\Constraints\Regex;
15+
16+
class CustomRegex extends Regex
17+
{
18+
public function __construct()
19+
{
20+
parent::__construct(pattern: '/^xxxxx$/');
21+
}
22+
}

0 commit comments

Comments
 (0)