Skip to content

Commit be8cb29

Browse files
committed
Merge branch '5.4' into 6.3
* 5.4: [Messenger] Fix using negative delay [Validator] Add missing italian translation [Validator] Fix using known option names as field names
2 parents 34d44eb + 508c256 commit be8cb29

File tree

5 files changed

+71
-6
lines changed

5 files changed

+71
-6
lines changed

src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineIntegrationTest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,29 @@ public function testSendWithDelay()
7272
$stmt = $stmt->execute();
7373
}
7474

75-
$available_at = new \DateTimeImmutable($stmt instanceof Result ? $stmt->fetchOne() : $stmt->fetchColumn());
75+
$availableAt = new \DateTimeImmutable($stmt instanceof Result ? $stmt->fetchOne() : $stmt->fetchColumn());
7676

7777
$now = new \DateTimeImmutable('now + 60 seconds');
78-
$this->assertGreaterThan($now, $available_at);
78+
$this->assertGreaterThan($now, $availableAt);
79+
}
80+
81+
public function testSendWithNegativeDelay()
82+
{
83+
$this->connection->send('{"message": "Hi, I am not actually delayed"}', ['type' => DummyMessage::class], -600000);
84+
85+
$qb = $this->driverConnection->createQueryBuilder()
86+
->select('m.available_at')
87+
->from('messenger_messages', 'm')
88+
->where('m.body = :body')
89+
->setParameter('body', '{"message": "Hi, I am not actually delayed"}');
90+
91+
// DBAL 2 compatibility
92+
$result = method_exists($qb, 'executeQuery') ? $qb->executeQuery() : $qb->execute();
93+
94+
$availableAt = new \DateTimeImmutable($result->fetchOne());
95+
96+
$now = new \DateTimeImmutable('now - 60 seconds');
97+
$this->assertLessThan($now, $availableAt);
7998
}
8099

81100
public function testItRetrieveTheFirstAvailableMessage()

src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static function buildConfiguration(#[\SensitiveParameter] string $dsn, ar
126126
public function send(string $body, array $headers, int $delay = 0): string
127127
{
128128
$now = new \DateTimeImmutable('UTC');
129-
$availableAt = $now->modify(sprintf('+%d seconds', $delay / 1000));
129+
$availableAt = $now->modify(sprintf('%+d seconds', $delay / 1000));
130130

131131
$queryBuilder = $this->driverConnection->createQueryBuilder()
132132
->insert($this->configuration['table_name'])

src/Symfony/Component/Validator/Constraints/Collection.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Symfony\Component\Validator\Constraint;
1415
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
1516

1617
/**
@@ -43,9 +44,10 @@ class Collection extends Composite
4344

4445
public function __construct(mixed $fields = null, array $groups = null, mixed $payload = null, bool $allowExtraFields = null, bool $allowMissingFields = null, string $extraFieldsMessage = null, string $missingFieldsMessage = null)
4546
{
46-
// no known options set? $fields is the fields array
4747
if (\is_array($fields)
48-
&& !array_intersect(array_keys($fields), ['groups', 'fields', 'allowExtraFields', 'allowMissingFields', 'extraFieldsMessage', 'missingFieldsMessage'])) {
48+
&& (($firstField = reset($fields)) instanceof Constraint
49+
|| ($firstField[0] ?? null) instanceof Constraint
50+
)) {
4951
$fields = ['fields' => $fields];
5052
}
5153

src/Symfony/Component/Validator/Resources/translations/validators.it.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@
426426
<source>Using hidden overlay characters is not allowed.</source>
427427
<target>Non è consentito utilizzare caratteri sovrapposti nascosti.</target>
428428
</trans-unit>
429+
<trans-unit id="110">
430+
<source>The extension of the file is invalid ({{ extension }}). Allowed extensions are {{ extensions }}.</source>
431+
<target>L'estensione del file non è valida ({{ extension }}). Le estensioni consentite sono {{ extensions }}.</target>
432+
</trans-unit>
429433
</body>
430434
</file>
431435
</xliff>

src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Validator\Constraints\Required;
1919
use Symfony\Component\Validator\Constraints\Valid;
2020
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
21+
use Symfony\Component\Validator\Exception\InvalidOptionsException;
2122

2223
/**
2324
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -34,7 +35,7 @@ public function testRejectInvalidFieldsOption()
3435

3536
public function testRejectNonConstraints()
3637
{
37-
$this->expectException(ConstraintDefinitionException::class);
38+
$this->expectException(InvalidOptionsException::class);
3839
new Collection([
3940
'foo' => 'bar',
4041
]);
@@ -113,4 +114,43 @@ public function testConstraintHasDefaultGroupWithOptionalValues()
113114
$this->assertEquals(['Default'], $constraint->fields['foo']->groups);
114115
$this->assertEquals(['Default'], $constraint->fields['bar']->groups);
115116
}
117+
118+
public function testOnlySomeKeysAreKnowOptions()
119+
{
120+
$constraint = new Collection([
121+
'fields' => [new Required()],
122+
'properties' => [new Required()],
123+
'catalog' => [new Optional()],
124+
]);
125+
126+
$this->assertArrayHasKey('fields', $constraint->fields);
127+
$this->assertInstanceOf(Required::class, $constraint->fields['fields']);
128+
$this->assertArrayHasKey('properties', $constraint->fields);
129+
$this->assertInstanceOf(Required::class, $constraint->fields['properties']);
130+
$this->assertArrayHasKey('catalog', $constraint->fields);
131+
$this->assertInstanceOf(Optional::class, $constraint->fields['catalog']);
132+
}
133+
134+
public function testAllKeysAreKnowOptions()
135+
{
136+
$constraint = new Collection([
137+
'fields' => [
138+
'fields' => [new Required()],
139+
'properties' => [new Required()],
140+
'catalog' => [new Optional()],
141+
],
142+
'allowExtraFields' => true,
143+
'extraFieldsMessage' => 'foo bar baz',
144+
]);
145+
146+
$this->assertArrayHasKey('fields', $constraint->fields);
147+
$this->assertInstanceOf(Required::class, $constraint->fields['fields']);
148+
$this->assertArrayHasKey('properties', $constraint->fields);
149+
$this->assertInstanceOf(Required::class, $constraint->fields['properties']);
150+
$this->assertArrayHasKey('catalog', $constraint->fields);
151+
$this->assertInstanceOf(Optional::class, $constraint->fields['catalog']);
152+
153+
$this->assertTrue($constraint->allowExtraFields);
154+
$this->assertSame('foo bar baz', $constraint->extraFieldsMessage);
155+
}
116156
}

0 commit comments

Comments
 (0)