Merge branch '4.4' into 5.2

* 4.4:
  Streamline dataproviders
  fix validator when we have a false current element
  [Mime] Fix case-sensitive handling in Headers::isUniqueHeader()
  [yaml] Delelte unused comparison operation
This commit is contained in:
Fabien Potencier 2021-02-03 05:42:09 +01:00
commit dab16d041e
7 changed files with 90 additions and 10 deletions

View File

@ -831,4 +831,85 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
->assertRaised();
}
/**
* @dataProvider resultWithEmptyIterator
*/
public function testValidateUniquenessWithEmptyIterator($entity, $result)
{
$constraint = new UniqueEntity([
'message' => 'myMessage',
'fields' => ['name'],
'em' => self::EM_NAME,
'repositoryMethod' => 'findByCustom',
]);
$repository = $this->createRepositoryMock();
$repository->expects($this->once())
->method('findByCustom')
->willReturn($result)
;
$this->em = $this->createEntityManagerMock($repository);
$this->registry = $this->createRegistryMock($this->em);
$this->validator = $this->createValidator();
$this->validator->initialize($this->context);
$this->validator->validate($entity, $constraint);
$this->assertNoViolation();
}
public function resultWithEmptyIterator(): array
{
$entity = new SingleIntIdEntity(1, 'foo');
return [
[$entity, new class() implements \Iterator {
public function current()
{
return null;
}
public function valid(): bool
{
return false;
}
public function next()
{
}
public function key()
{
}
public function rewind()
{
}
}],
[$entity, new class() implements \Iterator {
public function current()
{
return false;
}
public function valid(): bool
{
return false;
}
public function next()
{
}
public function key()
{
}
public function rewind()
{
}
}],
];
}
}

View File

@ -147,8 +147,7 @@ class UniqueEntityValidator extends ConstraintValidator
if ($result instanceof \Countable && 1 < \count($result)) {
$result = [$result->current(), $result->current()];
} else {
$result = $result->current();
$result = null === $result ? [] : [$result];
$result = $result->valid() && null !== $result->current() ? [$result->current()] : [];
}
} elseif (\is_array($result)) {
reset($result);

View File

@ -21,7 +21,7 @@ use Symfony\Component\Routing\RequestContext;
class HttpFoundationExtensionTest extends TestCase
{
/**
* @dataProvider getGenerateAbsoluteUrlData()
* @dataProvider getGenerateAbsoluteUrlData
*/
public function testGenerateAbsoluteUrl($expected, $path, $pathinfo)
{
@ -114,7 +114,7 @@ class HttpFoundationExtensionTest extends TestCase
}
/**
* @dataProvider getGenerateRelativePathData()
* @dataProvider getGenerateRelativePathData
*/
public function testGenerateRelativePath($expected, $path, $pathinfo)
{

View File

@ -727,7 +727,7 @@ class RequestTest extends TestCase
}
/**
* @dataProvider getRelativeUriForPathData()
* @dataProvider getRelativeUriForPathData
*/
public function testGetRelativeUriForPath($expected, $pathinfo, $path)
{

View File

@ -20,7 +20,7 @@ use Symfony\Component\Routing\RequestContext;
class UrlHelperTest extends TestCase
{
/**
* @dataProvider getGenerateAbsoluteUrlData()
* @dataProvider getGenerateAbsoluteUrlData
*/
public function testGenerateAbsoluteUrl($expected, $path, $pathinfo)
{
@ -113,7 +113,7 @@ class UrlHelperTest extends TestCase
}
/**
* @dataProvider getGenerateRelativePathData()
* @dataProvider getGenerateRelativePathData
*/
public function testGenerateRelativePath($expected, $path, $pathinfo)
{

View File

@ -29,7 +29,7 @@ trait CallbacksTestTrait
}
/**
* @dataProvider provideInvalidCallbacks()
* @dataProvider provideInvalidCallbacks
*/
public function testUncallableCallbacks($callbacks)
{

View File

@ -68,7 +68,7 @@ class Dumper
$output .= "\n";
}
if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value) && false !== strpos($value, "\n") && false === strpos($value, "\r")) {
if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value) && false !== strpos($value, "\n") && false === strpos($value, "\r")) {
// If the first line starts with a space character, the spec requires a blockIndicationIndicator
// http://www.yaml.org/spec/1.2/spec.html#id2793979
$blockIndentationIndicator = (' ' === substr($value, 0, 1)) ? (string) $this->indentation : '';
@ -97,7 +97,7 @@ class Dumper
if ($value instanceof TaggedValue) {
$output .= sprintf('%s%s !%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', $value->getTag());
if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value->getValue()) && false !== strpos($value->getValue(), "\n") && false === strpos($value->getValue(), "\r\n")) {
if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value->getValue()) && false !== strpos($value->getValue(), "\n") && false === strpos($value->getValue(), "\r\n")) {
// If the first line starts with a space character, the spec requires a blockIndicationIndicator
// http://www.yaml.org/spec/1.2/spec.html#id2793979
$blockIndentationIndicator = (' ' === substr($value->getValue(), 0, 1)) ? (string) $this->indentation : '';