Merge branch '4.4' into 5.1

This commit is contained in:
Alexander M. Turek 2020-11-02 08:55:38 +01:00
commit 8d964bda5b
12 changed files with 2273 additions and 2010 deletions

View File

@ -118,9 +118,9 @@ abstract class AdapterTestCase extends CachePoolTest
$metadata = $item->getMetadata();
$this->assertArrayHasKey(CacheItem::METADATA_CTIME, $metadata);
$this->assertEqualsWithDelta(1000, $metadata[CacheItem::METADATA_CTIME], 6);
$this->assertEqualsWithDelta(999, $metadata[CacheItem::METADATA_CTIME], 10);
$this->assertArrayHasKey(CacheItem::METADATA_EXPIRY, $metadata);
$this->assertEqualsWithDelta(9.5 + time(), $metadata[CacheItem::METADATA_EXPIRY], 0.6);
$this->assertEqualsWithDelta(9 + time(), $metadata[CacheItem::METADATA_EXPIRY], 1);
}
public function testDefaultLifeTime()

View File

@ -35,9 +35,10 @@ class SortableIteratorTest extends RealIteratorTestCase
case SortableIterator::SORT_BY_ACCESSED_TIME:
touch(self::toAbsolute('.git'));
sleep(1);
file_get_contents(self::toAbsolute('.bar'));
touch(self::toAbsolute('.bar'), time());
break;
case SortableIterator::SORT_BY_CHANGED_TIME:
sleep(1);
file_put_contents(self::toAbsolute('test.php'), 'foo');
sleep(1);
file_put_contents(self::toAbsolute('test.py'), 'foo');

View File

@ -14,6 +14,126 @@
<source>The CSRF token is invalid. Please try to resubmit the form.</source>
<target>CSRF nişanı yanlışdır. Lütfen formanı yenidən göndərin.</target>
</trans-unit>
<trans-unit id="99">
<source>This value is not a valid HTML5 color.</source>
<target>Bu dəyər doğru bir HTML5 rəngi deyil.</target>
</trans-unit>
<trans-unit id="100">
<source>Please enter a valid birthdate.</source>
<target>Zəhmət olmasa doğru bir doğum günü daxil edin.</target>
</trans-unit>
<trans-unit id="101">
<source>The selected choice is invalid.</source>
<target>Seçilmiş seçim doğru deyil.</target>
</trans-unit>
<trans-unit id="102">
<source>The collection is invalid.</source>
<target>Kolleksiya doğru deyil.</target>
</trans-unit>
<trans-unit id="103">
<source>Please select a valid color.</source>
<target>Zəhmət olmasa doğru bir rəng seçin.</target>
</trans-unit>
<trans-unit id="104">
<source>Please select a valid country.</source>
<target>Zəhmət olmasa doğru bir ölkə seçin.</target>
</trans-unit>
<trans-unit id="105">
<source>Please select a valid currency.</source>
<target>Zəhmət olmasa doğru bir valyuta seçin.</target>
</trans-unit>
<trans-unit id="106">
<source>Please choose a valid date interval.</source>
<target>Zəhmət olmasa doğru bir tarix aralığı seçin.</target>
</trans-unit>
<trans-unit id="107">
<source>Please enter a valid date and time.</source>
<target>Zəhmət olmasa doğru bir tarix ve saat daxil edin.</target>
</trans-unit>
<trans-unit id="108">
<source>Please enter a valid date.</source>
<target>Zəhmət olmasa doğru bir tarix daxil edin.</target>
</trans-unit>
<trans-unit id="109">
<source>Please select a valid file.</source>
<target>Zəhmət olmasa doğru bir fayl seçin.</target>
</trans-unit>
<trans-unit id="110">
<source>The hidden field is invalid.</source>
<target>Gizli sahə doğru deyil.</target>
</trans-unit>
<trans-unit id="111">
<source>Please enter an integer.</source>
<target>Zəhmət olmasa bir tam ədəd daxil edin.</target>
</trans-unit>
<trans-unit id="112">
<source>Please select a valid language.</source>
<target>Zəhmət olmasa doğru bir dil seçin.</target>
</trans-unit>
<trans-unit id="113">
<source>Please select a valid locale.</source>
<target>Zəhmət olmasa doğru bir yer seçin.</target>
</trans-unit>
<trans-unit id="114">
<source>Please enter a valid money amount.</source>
<target>Zəhmət olmasa doğru bir pul miqdarı daxil edin.</target>
</trans-unit>
<trans-unit id="115">
<source>Please enter a number.</source>
<target>Zəhmət olmasa doğru bir rəqəm daxil edin.</target>
</trans-unit>
<trans-unit id="116">
<source>The password is invalid.</source>
<target>Parol doğru deyil.</target>
</trans-unit>
<trans-unit id="117">
<source>Please enter a percentage value.</source>
<target>Zəhmət olmasa doğru bir faiz dəyəri daxil edin.</target>
</trans-unit>
<trans-unit id="118">
<source>The values do not match.</source>
<target>Dəyərlər örtüşmür.</target>
</trans-unit>
<trans-unit id="119">
<source>Please enter a valid time.</source>
<target>Zəhmət olmasa doğru bir saat daxil edin.</target>
</trans-unit>
<trans-unit id="120">
<source>Please select a valid timezone.</source>
<target>Zəhmət olmasa doğru bir saat qurşağı seçin.</target>
</trans-unit>
<trans-unit id="121">
<source>Please enter a valid URL.</source>
<target>Zəhmət olmasa doğru bir URL daxil edin.</target>
</trans-unit>
<trans-unit id="122">
<source>Please enter a valid search term.</source>
<target>Zəhmət olmasa doğru bir axtarış termini daxil edin.</target>
</trans-unit>
<trans-unit id="123">
<source>Please provide a valid phone number.</source>
<target>Zəhmət olmasa doğru bir telefon nömrəsi seçin.</target>
</trans-unit>
<trans-unit id="124">
<source>The checkbox has an invalid value.</source>
<target>Seçim qutusunda doğru olmayan dəyər var.</target>
</trans-unit>
<trans-unit id="125">
<source>Please enter a valid email address.</source>
<target>Zəhmət olmasa doğru bir e-poçt seçin.</target>
</trans-unit>
<trans-unit id="126">
<source>Please select a valid option.</source>
<target>Zəhmət olmasa doğru bir variant seçin.</target>
</trans-unit>
<trans-unit id="127">
<source>Please select a valid range.</source>
<target>Zəhmət olmasa doğru bir aralıq seçin.</target>
</trans-unit>
<trans-unit id="128">
<source>Please enter a valid week.</source>
<target>Zəhmət olmasa doğru bir həftə seçin.</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -14,6 +14,126 @@
<source>The CSRF token is invalid. Please try to resubmit the form.</source>
<target>El token CSRF no és vàlid. Per favor, provi d'enviar novament el formulari.</target>
</trans-unit>
<trans-unit id="99">
<source>This value is not a valid HTML5 color.</source>
<target>Aquest valor no és un color HTML5 valid.</target>
</trans-unit>
<trans-unit id="100">
<source>Please enter a valid birthdate.</source>
<target>Per favor introdueix una data d'aniversari valida.</target>
</trans-unit>
<trans-unit id="101">
<source>The selected choice is invalid.</source>
<target>L'opció escollida és invalida.</target>
</trans-unit>
<trans-unit id="102">
<source>The collection is invalid.</source>
<target>La col·lecció és invalida.</target>
</trans-unit>
<trans-unit id="103">
<source>Please select a valid color.</source>
<target>Per favor selecciona un color vàlid.</target>
</trans-unit>
<trans-unit id="104">
<source>Please select a valid country.</source>
<target>Per favor selecciona una ciutat vàlida.</target>
</trans-unit>
<trans-unit id="105">
<source>Please select a valid currency.</source>
<target>Per favor selecciona una moneda vàlida.</target>
</trans-unit>
<trans-unit id="106">
<source>Please choose a valid date interval.</source>
<target>Per favor escull un interval de dates vàlides.</target>
</trans-unit>
<trans-unit id="107">
<source>Please enter a valid date and time.</source>
<target>Per favor introdueix una data i temps vàlid.</target>
</trans-unit>
<trans-unit id="108">
<source>Please enter a valid date.</source>
<target>Per favor introdueix una data vàlida.</target>
</trans-unit>
<trans-unit id="109">
<source>Please select a valid file.</source>
<target>Per favor selecciona un arxiu vàlid.</target>
</trans-unit>
<trans-unit id="110">
<source>The hidden field is invalid.</source>
<target>El camp ocult és invàlid.</target>
</trans-unit>
<trans-unit id="111">
<source>Please enter an integer.</source>
<target>Per favor introdueix un enter.</target>
</trans-unit>
<trans-unit id="112">
<source>Please select a valid language.</source>
<target>Per favor selecciona un idioma vàlid.</target>
</trans-unit>
<trans-unit id="113">
<source>Please select a valid locale.</source>
<target>Per favor seleccioneu una configuració regional vàlida</target>
</trans-unit>
<trans-unit id="114">
<source>Please enter a valid money amount.</source>
<target>Per favor introdueix una quantitat de diners vàlids.</target>
</trans-unit>
<trans-unit id="115">
<source>Please enter a number.</source>
<target>Per favor introdueix un número.</target>
</trans-unit>
<trans-unit id="116">
<source>The password is invalid.</source>
<target>La contrasenya es invàlida.</target>
</trans-unit>
<trans-unit id="117">
<source>Please enter a percentage value.</source>
<target>Per favor introdueix un valor percentual.</target>
</trans-unit>
<trans-unit id="118">
<source>The values do not match.</source>
<target>Els valors no coincideixen.</target>
</trans-unit>
<trans-unit id="119">
<source>Please enter a valid time.</source>
<target>Per favor introdueix un temps vàlid.</target>
</trans-unit>
<trans-unit id="120">
<source>Please select a valid timezone.</source>
<target>Per favor selecciona una zona horària vàlida.</target>
</trans-unit>
<trans-unit id="121">
<source>Please enter a valid URL.</source>
<target>Per favor introdueix una URL vàlida.</target>
</trans-unit>
<trans-unit id="122">
<source>Please enter a valid search term.</source>
<target>Per favor introdueix un concepte de cerca vàlid.</target>
</trans-unit>
<trans-unit id="123">
<source>Please provide a valid phone number.</source>
<target>Per favor introdueix un número de telèfon vàlid.</target>
</trans-unit>
<trans-unit id="124">
<source>The checkbox has an invalid value.</source>
<target>La casella de selecció te un valor invàlid.</target>
</trans-unit>
<trans-unit id="125">
<source>Please enter a valid email address.</source>
<target>Per favor introdueix un correu electrònic vàlid.</target>
</trans-unit>
<trans-unit id="126">
<source>Please select a valid option.</source>
<target>Per favor selecciona una opció vàlida.</target>
</trans-unit>
<trans-unit id="127">
<source>Please select a valid range.</source>
<target>Per favor selecciona un rang vàlid.</target>
</trans-unit>
<trans-unit id="128">
<source>Please enter a valid week.</source>
<target>Per favor introdueix una setmana vàlida.</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -4,15 +4,15 @@
<body>
<trans-unit id="28">
<source>This form should not contain extra fields.</source>
<target>Este formulário não deveria conter campos extra.</target>
<target>Este formulário não deveria possuir mais campos.</target>
</trans-unit>
<trans-unit id="29">
<source>The uploaded file was too large. Please try to upload a smaller file.</source>
<target>O arquivo enviado é muito grande. Por favor, tente enviar um ficheiro mais pequeno.</target>
<target>O arquivo enviado é muito grande. Por favor, tente enviar um arquivo menor.</target>
</trans-unit>
<trans-unit id="30">
<source>The CSRF token is invalid. Please try to resubmit the form.</source>
<target>O token CSRF é inválido. Por favor submeta o formulário novamente.</target>
<target>O token CSRF está inválido. Por favor, tente enviar o formulário novamente.</target>
</trans-unit>
</body>
</file>

View File

@ -62,6 +62,14 @@
<source>Account is locked.</source>
<target>Hesab kilitlənib.</target>
</trans-unit>
<trans-unit id="17">
<source>Too many failed login attempts, please try again later.</source>
<target>Çoxlu uğursuz giriş təşəbbüsü, zəhmət olmasa daha sonra yeniden yoxlayın.</target>
</trans-unit>
<trans-unit id="18">
<source>Invalid or expired login link.</source>
<target>Yanlış və ya müddəti keçmiş giriş keçidi.</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -62,6 +62,14 @@
<source>Account is locked.</source>
<target>El compte està bloquejat.</target>
</trans-unit>
<trans-unit id="17">
<source>Too many failed login attempts, please try again later.</source>
<target>Massa intents d'inici de sessió fallits, torneu-ho a provar més tard.</target>
</trans-unit>
<trans-unit id="18">
<source>Invalid or expired login link.</source>
<target>Enllaç d'inici de sessió no vàlid o caducat.</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -366,6 +366,26 @@
<source>This value should be between {{ min }} and {{ max }}.</source>
<target>Bu dəyər {{ min }} və {{ max }} arasında olmaldır.</target>
</trans-unit>
<trans-unit id="95">
<source>This value is not a valid hostname.</source>
<target>Bu dəyər doğru bir host adı deyil.</target>
</trans-unit>
<trans-unit id="96">
<source>The number of elements in this collection should be a multiple of {{ compared_value }}.</source>
<target>Bu kolleksiyadakı elementlerin sayı {{ compared_value }} tam bölünəni olmalıdır.</target>
</trans-unit>
<trans-unit id="97">
<source>This value should satisfy at least one of the following constraints:</source>
<target>Bu dəyər aşağıdakı məcburiyyətlərdən birini qarşılamalıdır:</target>
</trans-unit>
<trans-unit id="98">
<source>Each element of this collection should satisfy its own set of constraints.</source>
<target>Bu kolleksiyadakı hər element öz məcburiyyətlərini qarşılamalıdır.</target>
</trans-unit>
<trans-unit id="99">
<source>This value is not a valid International Securities Identification Number (ISIN).</source>
<target>Bu dəyər doğru bir Qiymətli Kağızın Beynəlxalq İdentifikasiya Kodu (ISIN) deyil.</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -330,6 +330,62 @@
<source>This Business Identifier Code (BIC) is not associated with IBAN {{ iban }}.</source>
<target>Aquest Codi d'identificació bancari (BIC) no està associat amb l'IBAN {{ iban }}.</target>
</trans-unit>
<trans-unit id="86">
<source>This value should be valid JSON.</source>
<target>Aquest valor hauria de ser JSON vàlid.</target>
</trans-unit>
<trans-unit id="87">
<source>This collection should contain only unique elements.</source>
<target>Aquesta col·lecció només hauria de contenir elements únics.</target>
</trans-unit>
<trans-unit id="88">
<source>This value should be positive.</source>
<target>Aquest valor hauria de ser positiu.</target>
</trans-unit>
<trans-unit id="89">
<source>This value should be either positive or zero.</source>
<target>Aquest valor ha de ser positiu o zero.</target>
</trans-unit>
<trans-unit id="90">
<source>This value should be negative.</source>
<target>Aquest valor ha de ser negatiu.</target>
</trans-unit>
<trans-unit id="91">
<source>This value should be either negative or zero.</source>
<target>Aquest valor ha de ser negatiu o zero.</target>
</trans-unit>
<trans-unit id="92">
<source>This value is not a valid timezone.</source>
<target>Aquest valor no és una zona horària vàlida.</target>
</trans-unit>
<trans-unit id="93">
<source>This password has been leaked in a data breach, it must not be used. Please use another password.</source>
<target>Aquesta contrasenya s'ha filtrat en cas de violació de dades, no s'ha d'utilitzar. Utilitzeu una altra contrasenya.</target>
</trans-unit>
<trans-unit id="94">
<source>This value should be between {{ min }} and {{ max }}.</source>
<target>Aquest valor ha d'estar entre {{ min }} i {{ max }}.</target>
</trans-unit>
<trans-unit id="95">
<source>This value is not a valid hostname.</source>
<target>Aquest valor no és un nom d'amfitrió vàlid.</target>
</trans-unit>
<trans-unit id="96">
<source>The number of elements in this collection should be a multiple of {{ compared_value }}.</source>
<target>El nombre d'elements d'aquesta col·lecció ha de ser múltiple de {{compared_value}}.</target>
</trans-unit>
<trans-unit id="97">
<source>This value should satisfy at least one of the following constraints:</source>
<target>Aquest valor ha de satisfer almenys una de les restriccions següents:</target>
</trans-unit>
<trans-unit id="98">
<source>Each element of this collection should satisfy its own set of constraints.</source>
<target>Cada element d'aquesta col·lecció hauria de satisfer el seu propi conjunt de restriccions.</target>
</trans-unit>
<trans-unit id="99">
<source>This value is not a valid International Securities Identification Number (ISIN).</source>
<target>Aquest valor no és un número d'identificació de valors internacionals (ISIN) vàlid.</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -1,722 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Validator\Tests\Validator;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\Expression;
use Symfony\Component\Validator\Constraints\GroupSequence;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\Constraints\Traverse;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
use Symfony\Component\Validator\Tests\Fixtures\Entity;
use Symfony\Component\Validator\Tests\Fixtures\FailingConstraint;
use Symfony\Component\Validator\Tests\Fixtures\Reference;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
abstract class AbstractTest extends AbstractValidatorTest
{
/**
* @var ValidatorInterface
*/
protected $validator;
abstract protected function createValidator(MetadataFactoryInterface $metadataFactory, array $objectInitializers = []): ValidatorInterface;
protected function setUp(): void
{
parent::setUp();
$this->validator = $this->createValidator($this->metadataFactory);
}
protected function validate($value, $constraints = null, $groups = null)
{
return $this->validator->validate($value, $constraints, $groups);
}
protected function validateProperty($object, $propertyName, $groups = null)
{
return $this->validator->validateProperty($object, $propertyName, $groups);
}
protected function validatePropertyValue($object, $propertyName, $value, $groups = null)
{
return $this->validator->validatePropertyValue($object, $propertyName, $value, $groups);
}
public function testValidateConstraintWithoutGroup()
{
$violations = $this->validator->validate(null, new NotNull());
$this->assertCount(1, $violations);
}
public function testValidateWithEmptyArrayAsConstraint()
{
$violations = $this->validator->validate('value', []);
$this->assertCount(0, $violations);
}
public function testGroupSequenceAbortsAfterFailedGroup()
{
$entity = new Entity();
$callback1 = function ($value, ExecutionContextInterface $context) {
$context->addViolation('Message 1');
};
$callback2 = function ($value, ExecutionContextInterface $context) {
$context->addViolation('Message 2');
};
$this->metadata->addConstraint(new Callback([
'callback' => function () {},
'groups' => 'Group 1',
]));
$this->metadata->addConstraint(new Callback([
'callback' => $callback1,
'groups' => 'Group 2',
]));
$this->metadata->addConstraint(new Callback([
'callback' => $callback2,
'groups' => 'Group 3',
]));
$sequence = new GroupSequence(['Group 1', 'Group 2', 'Group 3']);
$violations = $this->validator->validate($entity, new Valid(), $sequence);
/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(1, $violations);
$this->assertSame('Message 1', $violations[0]->getMessage());
}
public function testGroupSequenceIncludesReferences()
{
$entity = new Entity();
$entity->reference = new Reference();
$callback1 = function ($value, ExecutionContextInterface $context) {
$context->addViolation('Reference violation 1');
};
$callback2 = function ($value, ExecutionContextInterface $context) {
$context->addViolation('Reference violation 2');
};
$this->metadata->addPropertyConstraint('reference', new Valid());
$this->referenceMetadata->addConstraint(new Callback([
'callback' => $callback1,
'groups' => 'Group 1',
]));
$this->referenceMetadata->addConstraint(new Callback([
'callback' => $callback2,
'groups' => 'Group 2',
]));
$sequence = new GroupSequence(['Group 1', 'Entity']);
$violations = $this->validator->validate($entity, new Valid(), $sequence);
/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(1, $violations);
$this->assertSame('Reference violation 1', $violations[0]->getMessage());
}
public function testValidateInSeparateContext()
{
$entity = new Entity();
$entity->reference = new Reference();
$callback1 = function ($value, ExecutionContextInterface $context) use ($entity) {
$violations = $context
->getValidator()
// Since the validator is not context aware, the group must
// be passed explicitly
->validate($value->reference, new Valid(), 'Group')
;
/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(1, $violations);
$this->assertSame('Message value', $violations[0]->getMessage());
$this->assertSame('Message %param%', $violations[0]->getMessageTemplate());
$this->assertSame(['%param%' => 'value'], $violations[0]->getParameters());
$this->assertSame('', $violations[0]->getPropertyPath());
// The root is different as we're in a new context
$this->assertSame($entity->reference, $violations[0]->getRoot());
$this->assertSame($entity->reference, $violations[0]->getInvalidValue());
$this->assertNull($violations[0]->getPlural());
$this->assertNull($violations[0]->getCode());
// Verify that this method is called
$context->addViolation('Separate violation');
};
$callback2 = function ($value, ExecutionContextInterface $context) use ($entity) {
$this->assertSame($this::REFERENCE_CLASS, $context->getClassName());
$this->assertNull($context->getPropertyName());
$this->assertSame('', $context->getPropertyPath());
$this->assertSame('Group', $context->getGroup());
$this->assertSame($this->referenceMetadata, $context->getMetadata());
$this->assertSame($entity->reference, $context->getRoot());
$this->assertSame($entity->reference, $context->getValue());
$this->assertSame($entity->reference, $value);
$context->addViolation('Message %param%', ['%param%' => 'value']);
};
$this->metadata->addConstraint(new Callback([
'callback' => $callback1,
'groups' => 'Group',
]));
$this->referenceMetadata->addConstraint(new Callback([
'callback' => $callback2,
'groups' => 'Group',
]));
$violations = $this->validator->validate($entity, new Valid(), 'Group');
/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(1, $violations);
$this->assertSame('Separate violation', $violations[0]->getMessage());
}
public function testValidateInContext()
{
$entity = new Entity();
$entity->reference = new Reference();
$callback1 = function ($value, ExecutionContextInterface $context) {
$previousValue = $context->getValue();
$previousObject = $context->getObject();
$previousMetadata = $context->getMetadata();
$previousPath = $context->getPropertyPath();
$previousGroup = $context->getGroup();
$context
->getValidator()
->inContext($context)
->atPath('subpath')
->validate($value->reference)
;
// context changes shouldn't leak out of the validate() call
$this->assertSame($previousValue, $context->getValue());
$this->assertSame($previousObject, $context->getObject());
$this->assertSame($previousMetadata, $context->getMetadata());
$this->assertSame($previousPath, $context->getPropertyPath());
$this->assertSame($previousGroup, $context->getGroup());
};
$callback2 = function ($value, ExecutionContextInterface $context) use ($entity) {
$this->assertSame($this::REFERENCE_CLASS, $context->getClassName());
$this->assertNull($context->getPropertyName());
$this->assertSame('subpath', $context->getPropertyPath());
$this->assertSame('Group', $context->getGroup());
$this->assertSame($this->referenceMetadata, $context->getMetadata());
$this->assertSame($entity, $context->getRoot());
$this->assertSame($entity->reference, $context->getValue());
$this->assertSame($entity->reference, $value);
$context->addViolation('Message %param%', ['%param%' => 'value']);
};
$this->metadata->addConstraint(new Callback([
'callback' => $callback1,
'groups' => 'Group',
]));
$this->referenceMetadata->addConstraint(new Callback([
'callback' => $callback2,
'groups' => 'Group',
]));
$violations = $this->validator->validate($entity, new Valid(), 'Group');
/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(1, $violations);
$this->assertSame('Message value', $violations[0]->getMessage());
$this->assertSame('Message %param%', $violations[0]->getMessageTemplate());
$this->assertSame(['%param%' => 'value'], $violations[0]->getParameters());
$this->assertSame('subpath', $violations[0]->getPropertyPath());
$this->assertSame($entity, $violations[0]->getRoot());
$this->assertSame($entity->reference, $violations[0]->getInvalidValue());
$this->assertNull($violations[0]->getPlural());
$this->assertNull($violations[0]->getCode());
}
public function testValidateArrayInContext()
{
$entity = new Entity();
$entity->reference = new Reference();
$callback1 = function ($value, ExecutionContextInterface $context) {
$previousValue = $context->getValue();
$previousObject = $context->getObject();
$previousMetadata = $context->getMetadata();
$previousPath = $context->getPropertyPath();
$previousGroup = $context->getGroup();
$context
->getValidator()
->inContext($context)
->atPath('subpath')
->validate(['key' => $value->reference])
;
// context changes shouldn't leak out of the validate() call
$this->assertSame($previousValue, $context->getValue());
$this->assertSame($previousObject, $context->getObject());
$this->assertSame($previousMetadata, $context->getMetadata());
$this->assertSame($previousPath, $context->getPropertyPath());
$this->assertSame($previousGroup, $context->getGroup());
};
$callback2 = function ($value, ExecutionContextInterface $context) use ($entity) {
$this->assertSame($this::REFERENCE_CLASS, $context->getClassName());
$this->assertNull($context->getPropertyName());
$this->assertSame('subpath[key]', $context->getPropertyPath());
$this->assertSame('Group', $context->getGroup());
$this->assertSame($this->referenceMetadata, $context->getMetadata());
$this->assertSame($entity, $context->getRoot());
$this->assertSame($entity->reference, $context->getValue());
$this->assertSame($entity->reference, $value);
$context->addViolation('Message %param%', ['%param%' => 'value']);
};
$this->metadata->addConstraint(new Callback([
'callback' => $callback1,
'groups' => 'Group',
]));
$this->referenceMetadata->addConstraint(new Callback([
'callback' => $callback2,
'groups' => 'Group',
]));
$violations = $this->validator->validate($entity, new Valid(), 'Group');
/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(1, $violations);
$this->assertSame('Message value', $violations[0]->getMessage());
$this->assertSame('Message %param%', $violations[0]->getMessageTemplate());
$this->assertSame(['%param%' => 'value'], $violations[0]->getParameters());
$this->assertSame('subpath[key]', $violations[0]->getPropertyPath());
$this->assertSame($entity, $violations[0]->getRoot());
$this->assertSame($entity->reference, $violations[0]->getInvalidValue());
$this->assertNull($violations[0]->getPlural());
$this->assertNull($violations[0]->getCode());
}
public function testTraverseTraversableByDefault()
{
$entity = new Entity();
$traversable = new \ArrayIterator(['key' => $entity]);
$callback = function ($value, ExecutionContextInterface $context) use ($entity, $traversable) {
$this->assertSame($this::ENTITY_CLASS, $context->getClassName());
$this->assertNull($context->getPropertyName());
$this->assertSame('[key]', $context->getPropertyPath());
$this->assertSame('Group', $context->getGroup());
$this->assertSame($this->metadata, $context->getMetadata());
$this->assertSame($traversable, $context->getRoot());
$this->assertSame($entity, $context->getValue());
$this->assertSame($entity, $value);
$context->addViolation('Message %param%', ['%param%' => 'value']);
};
$this->metadataFactory->addMetadata(new ClassMetadata('ArrayIterator'));
$this->metadata->addConstraint(new Callback([
'callback' => $callback,
'groups' => 'Group',
]));
$violations = $this->validate($traversable, new Valid(), 'Group');
/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(1, $violations);
$this->assertSame('Message value', $violations[0]->getMessage());
$this->assertSame('Message %param%', $violations[0]->getMessageTemplate());
$this->assertSame(['%param%' => 'value'], $violations[0]->getParameters());
$this->assertSame('[key]', $violations[0]->getPropertyPath());
$this->assertSame($traversable, $violations[0]->getRoot());
$this->assertSame($entity, $violations[0]->getInvalidValue());
$this->assertNull($violations[0]->getPlural());
$this->assertNull($violations[0]->getCode());
}
public function testTraversalEnabledOnClass()
{
$entity = new Entity();
$traversable = new \ArrayIterator(['key' => $entity]);
$callback = function ($value, ExecutionContextInterface $context) {
$context->addViolation('Message');
};
$traversableMetadata = new ClassMetadata('ArrayIterator');
$traversableMetadata->addConstraint(new Traverse(true));
$this->metadataFactory->addMetadata($traversableMetadata);
$this->metadata->addConstraint(new Callback([
'callback' => $callback,
'groups' => 'Group',
]));
$violations = $this->validate($traversable, new Valid(), 'Group');
/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(1, $violations);
}
public function testTraversalDisabledOnClass()
{
$entity = new Entity();
$traversable = new \ArrayIterator(['key' => $entity]);
$callback = function ($value, ExecutionContextInterface $context) {
$this->fail('Should not be called');
};
$traversableMetadata = new ClassMetadata('ArrayIterator');
$traversableMetadata->addConstraint(new Traverse(false));
$this->metadataFactory->addMetadata($traversableMetadata);
$this->metadata->addConstraint(new Callback([
'callback' => $callback,
'groups' => 'Group',
]));
$violations = $this->validate($traversable, new Valid(), 'Group');
/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(0, $violations);
}
public function testExpectTraversableIfTraversalEnabledOnClass()
{
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
$entity = new Entity();
$this->metadata->addConstraint(new Traverse(true));
$this->validator->validate($entity);
}
public function testReferenceTraversalDisabledOnClass()
{
$entity = new Entity();
$entity->reference = new \ArrayIterator(['key' => new Reference()]);
$callback = function ($value, ExecutionContextInterface $context) {
$this->fail('Should not be called');
};
$traversableMetadata = new ClassMetadata('ArrayIterator');
$traversableMetadata->addConstraint(new Traverse(false));
$this->metadataFactory->addMetadata($traversableMetadata);
$this->referenceMetadata->addConstraint(new Callback([
'callback' => $callback,
'groups' => 'Group',
]));
$this->metadata->addPropertyConstraint('reference', new Valid());
$violations = $this->validate($entity, new Valid(), 'Group');
/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(0, $violations);
}
public function testReferenceTraversalEnabledOnReferenceDisabledOnClass()
{
$entity = new Entity();
$entity->reference = new \ArrayIterator(['key' => new Reference()]);
$callback = function ($value, ExecutionContextInterface $context) {
$this->fail('Should not be called');
};
$traversableMetadata = new ClassMetadata('ArrayIterator');
$traversableMetadata->addConstraint(new Traverse(false));
$this->metadataFactory->addMetadata($traversableMetadata);
$this->referenceMetadata->addConstraint(new Callback([
'callback' => $callback,
'groups' => 'Group',
]));
$this->metadata->addPropertyConstraint('reference', new Valid([
'traverse' => true,
]));
$violations = $this->validate($entity, new Valid(), 'Group');
/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(0, $violations);
}
public function testReferenceTraversalDisabledOnReferenceEnabledOnClass()
{
$entity = new Entity();
$entity->reference = new \ArrayIterator(['key' => new Reference()]);
$callback = function ($value, ExecutionContextInterface $context) {
$this->fail('Should not be called');
};
$traversableMetadata = new ClassMetadata('ArrayIterator');
$traversableMetadata->addConstraint(new Traverse(true));
$this->metadataFactory->addMetadata($traversableMetadata);
$this->referenceMetadata->addConstraint(new Callback([
'callback' => $callback,
'groups' => 'Group',
]));
$this->metadata->addPropertyConstraint('reference', new Valid([
'traverse' => false,
]));
$violations = $this->validate($entity, new Valid(), 'Group');
/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(0, $violations);
}
public function testAddCustomizedViolation()
{
$entity = new Entity();
$callback = function ($value, ExecutionContextInterface $context) {
$context->buildViolation('Message %param%')
->setParameter('%param%', 'value')
->setInvalidValue('Invalid value')
->setPlural(2)
->setCode('42')
->addViolation();
};
$this->metadata->addConstraint(new Callback($callback));
$violations = $this->validator->validate($entity);
/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(1, $violations);
$this->assertSame('Message value', $violations[0]->getMessage());
$this->assertSame('Message %param%', $violations[0]->getMessageTemplate());
$this->assertSame(['%param%' => 'value'], $violations[0]->getParameters());
$this->assertSame('', $violations[0]->getPropertyPath());
$this->assertSame($entity, $violations[0]->getRoot());
$this->assertSame('Invalid value', $violations[0]->getInvalidValue());
$this->assertSame(2, $violations[0]->getPlural());
$this->assertSame('42', $violations[0]->getCode());
}
public function testNoDuplicateValidationIfClassConstraintInMultipleGroups()
{
$entity = new Entity();
$callback = function ($value, ExecutionContextInterface $context) {
$context->addViolation('Message');
};
$this->metadata->addConstraint(new Callback([
'callback' => $callback,
'groups' => ['Group 1', 'Group 2'],
]));
$violations = $this->validator->validate($entity, new Valid(), ['Group 1', 'Group 2']);
/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(1, $violations);
}
public function testNoDuplicateValidationIfPropertyConstraintInMultipleGroups()
{
$entity = new Entity();
$callback = function ($value, ExecutionContextInterface $context) {
$context->addViolation('Message');
};
$this->metadata->addPropertyConstraint('firstName', new Callback([
'callback' => $callback,
'groups' => ['Group 1', 'Group 2'],
]));
$violations = $this->validator->validate($entity, new Valid(), ['Group 1', 'Group 2']);
/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(1, $violations);
}
public function testValidateFailsIfNoConstraintsAndNoObjectOrArray()
{
$this->expectException('Symfony\Component\Validator\Exception\RuntimeException');
$this->validate('Foobar');
}
public function testAccessCurrentObject()
{
$called = false;
$entity = new Entity();
$entity->firstName = 'Bernhard';
$entity->data = ['firstName' => 'Bernhard'];
$callback = function ($value, ExecutionContextInterface $context) use ($entity, &$called) {
$called = true;
$this->assertSame($entity, $context->getObject());
};
$this->metadata->addConstraint(new Callback($callback));
$this->metadata->addPropertyConstraint('firstName', new Callback($callback));
$this->metadata->addPropertyConstraint('data', new Collection(['firstName' => new Expression('value == this.firstName')]));
$this->validator->validate($entity);
$this->assertTrue($called);
}
public function testInitializeObjectsOnFirstValidation()
{
$entity = new Entity();
$entity->initialized = false;
// prepare initializers that set "initialized" to true
$initializer1 = $this->getMockBuilder('Symfony\\Component\\Validator\\ObjectInitializerInterface')->getMock();
$initializer2 = $this->getMockBuilder('Symfony\\Component\\Validator\\ObjectInitializerInterface')->getMock();
$initializer1->expects($this->once())
->method('initialize')
->with($entity)
->willReturnCallback(function ($object) {
$object->initialized = true;
});
$initializer2->expects($this->once())
->method('initialize')
->with($entity);
$this->validator = $this->createValidator($this->metadataFactory, [
$initializer1,
$initializer2,
]);
// prepare constraint which
// * checks that "initialized" is set to true
// * validates the object again
$callback = function ($object, ExecutionContextInterface $context) {
$this->assertTrue($object->initialized);
// validate again in same group
$validator = $context->getValidator()->inContext($context);
$validator->validate($object);
// validate again in other group
$validator->validate($object, null, 'SomeGroup');
};
$this->metadata->addConstraint(new Callback($callback));
$this->validate($entity);
$this->assertTrue($entity->initialized);
}
public function testPassConstraintToViolation()
{
$constraint = new FailingConstraint();
$violations = $this->validate('Foobar', $constraint);
$this->assertCount(1, $violations);
$this->assertSame($constraint, $violations[0]->getConstraint());
}
public function testCollectionConstraitViolationHasCorrectContext()
{
$data = [
'foo' => 'fooValue',
];
// Missing field must not be the first in the collection validation
$constraint = new Collection([
'foo' => new NotNull(),
'bar' => new NotNull(),
]);
$violations = $this->validate($data, $constraint);
$this->assertCount(1, $violations);
$this->assertSame($constraint, $violations[0]->getConstraint());
}
public function testNestedObjectIsNotValidatedIfGroupInValidConstraintIsNotValidated()
{
$entity = new Entity();
$entity->firstName = '';
$reference = new Reference();
$reference->value = '';
$entity->childA = $reference;
$this->metadata->addPropertyConstraint('firstName', new NotBlank(['groups' => 'group1']));
$this->metadata->addPropertyConstraint('childA', new Valid(['groups' => 'group1']));
$this->referenceMetadata->addPropertyConstraint('value', new NotBlank());
$violations = $this->validator->validate($entity, null, []);
$this->assertCount(0, $violations);
}
public function testNestedObjectIsValidatedIfGroupInValidConstraintIsValidated()
{
$entity = new Entity();
$entity->firstName = '';
$reference = new Reference();
$reference->value = '';
$entity->childA = $reference;
$this->metadata->addPropertyConstraint('firstName', new NotBlank(['groups' => 'group1']));
$this->metadata->addPropertyConstraint('childA', new Valid(['groups' => 'group1']));
$this->referenceMetadata->addPropertyConstraint('value', new NotBlank(['groups' => 'group1']));
$violations = $this->validator->validate($entity, null, ['Default', 'group1']);
$this->assertCount(2, $violations);
}
public function testNestedObjectIsValidatedInMultipleGroupsIfGroupInValidConstraintIsValidated()
{
$entity = new Entity();
$entity->firstName = null;
$reference = new Reference();
$reference->value = null;
$entity->childA = $reference;
$this->metadata->addPropertyConstraint('firstName', new NotBlank());
$this->metadata->addPropertyConstraint('childA', new Valid(['groups' => ['group1', 'group2']]));
$this->referenceMetadata->addPropertyConstraint('value', new NotBlank(['groups' => 'group1']));
$this->referenceMetadata->addPropertyConstraint('value', new NotNull(['groups' => 'group2']));
$violations = $this->validator->validate($entity, null, ['Default', 'group1', 'group2']);
$this->assertCount(3, $violations);
}
}