Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 6.4: (29 commits)
  fix tests
  add missing method
  fix merge
  fix test
  fix merge
  fix test
  change test to use a real ObjectManager
  [Mailer] Document the usage of custom headers in Infobip bridge
  [SecurityBundle] Add `provider` XML attribute to the authenticators it’s missing from
  [DoctrineBridge] Test reset with a true manager
  Sync php-cs-fixer config file with 7.2
  [HttpClient] Fix parsing SSE
  [Notifier] Fix thread key in GoogleChat bridge
  [HttpKernel][Security] Fix accessing session for stateless request
  [Serializer] Fix `ObjectNormalizer` with property path
  test handling of special "value" constraint option
  [PhpUnitBridge] Add missing import
  [FrameworkBundle] Fix setting default context for certain normalizers
  [57251] Missing translations for Romanian (ro)
  [ErrorHandler] Fix rendered exception code highlighting on PHP 8.3
  ...
  • Loading branch information
xabbuh committed Jun 22, 2024
2 parents 23af65d + ee0a4d6 commit 0426605
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Constraints/UniqueValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function validate(mixed $value, Constraint $constraint): void

if (\in_array($element, $collectionElements, true)) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setParameter('{{ value }}', $this->formatValue($element))
->setCode(Unique::IS_NOT_UNIQUE)
->addViolation();

Expand Down
2 changes: 1 addition & 1 deletion Resources/translations/validators.ro.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@
</trans-unit>
<trans-unit id="113">
<source>This URL is missing a top-level domain.</source>
<target state="needs-review-translation">Acest URL îi lipsește un domeniu de nivel superior.</target>
<target>Acestui URL îi lipsește un domeniu de nivel superior.</target>
</trans-unit>
</body>
</file>
Expand Down
2 changes: 1 addition & 1 deletion Tests/Constraints/CssColorValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public static function getInvalidHSL(): array
}

/**
* @dataProvider getInvalidHSL
* @dataProvider getInvalidHSLA
*/
public function testInvalidHSLA($cssColor)
{
Expand Down
34 changes: 18 additions & 16 deletions Tests/Constraints/UniqueValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public static function getValidValues()
/**
* @dataProvider getInvalidValues
*/
public function testInvalidValues($value)
public function testInvalidValues($value, $expectedMessageParam)
{
$constraint = new Unique([
'message' => 'myMessage',
]);
$this->validator->validate($value, $constraint);

$this->buildViolation('myMessage')
->setParameter('{{ value }}', 'array')
->setParameter('{{ value }}', $expectedMessageParam)
->setCode(Unique::IS_NOT_UNIQUE)
->assertRaised();
}
Expand All @@ -79,12 +79,12 @@ public static function getInvalidValues()
$object = new \stdClass();

return [
yield 'not unique booleans' => [[true, true]],
yield 'not unique integers' => [[1, 2, 3, 3]],
yield 'not unique floats' => [[0.1, 0.2, 0.1]],
yield 'not unique string' => [['a', 'b', 'a']],
yield 'not unique arrays' => [[[1, 1], [2, 3], [1, 1]]],
yield 'not unique objects' => [[$object, $object]],
yield 'not unique booleans' => [[true, true], 'true'],
yield 'not unique integers' => [[1, 2, 3, 3], 3],
yield 'not unique floats' => [[0.1, 0.2, 0.1], 0.1],
yield 'not unique string' => [['a', 'b', 'a'], '"a"'],
yield 'not unique arrays' => [[[1, 1], [2, 3], [1, 1]], 'array'],
yield 'not unique objects' => [[$object, $object], 'object'],
];
}

Expand All @@ -94,7 +94,7 @@ public function testInvalidValueNamed()
$this->validator->validate([1, 2, 3, 3], $constraint);

$this->buildViolation('myMessage')
->setParameter('{{ value }}', 'array')
->setParameter('{{ value }}', '3')
->setCode(Unique::IS_NOT_UNIQUE)
->assertRaised();
}
Expand Down Expand Up @@ -174,7 +174,7 @@ public function testExpectsInvalidNonStrictComparison()
]));

$this->buildViolation('myMessage')
->setParameter('{{ value }}', 'array')
->setParameter('{{ value }}', '1')
->setCode(Unique::IS_NOT_UNIQUE)
->assertRaised();
}
Expand All @@ -200,7 +200,7 @@ public function testExpectsInvalidCaseInsensitiveComparison()
]));

$this->buildViolation('myMessage')
->setParameter('{{ value }}', 'array')
->setParameter('{{ value }}', '"hello"')
->setCode(Unique::IS_NOT_UNIQUE)
->assertRaised();
}
Expand Down Expand Up @@ -246,14 +246,14 @@ public static function getInvalidFieldNames(): array
/**
* @dataProvider getInvalidCollectionValues
*/
public function testInvalidCollectionValues(array $value, array $fields)
public function testInvalidCollectionValues(array $value, array $fields, string $expectedMessageParam)
{
$this->validator->validate($value, new Unique([
'message' => 'myMessage',
], fields: $fields));

$this->buildViolation('myMessage')
->setParameter('{{ value }}', 'array')
->setParameter('{{ value }}', $expectedMessageParam)
->setCode(Unique::IS_NOT_UNIQUE)
->assertRaised();
}
Expand All @@ -264,23 +264,25 @@ public static function getInvalidCollectionValues(): array
'unique string' => [[
['lang' => 'eng', 'translation' => 'hi'],
['lang' => 'eng', 'translation' => 'hello'],
], ['lang']],
], ['lang'], 'array'],
'unique floats' => [[
['latitude' => 51.509865, 'longitude' => -0.118092, 'poi' => 'capital'],
['latitude' => 52.520008, 'longitude' => 13.404954],
['latitude' => 51.509865, 'longitude' => -0.118092],
], ['latitude', 'longitude']],
], ['latitude', 'longitude'], 'array'],
'unique int' => [[
['id' => 1, 'email' => '[email protected]'],
['id' => 1, 'email' => '[email protected]'],
], ['id']],
], ['id'], 'array'],
'unique null' => [
[null, null],
[],
'null',
],
'unique field null' => [
[['nullField' => null], ['nullField' => null]],
['nullField'],
'array',
],
];
}
Expand Down

0 comments on commit 0426605

Please sign in to comment.