Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Rename AtLeastOneOf new Constraint to OneOf #36722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*
* @author Przemysław Bogusz <[email protected]>
*/
class AtLeastOneOf extends Composite
class OneOf extends Composite
{
public const AT_LEAST_ONE_OF_ERROR = 'f27e6d6c-261a-4056-b391-6673a623531c';
public const ONE_OF_ERROR = 'f27e6d6c-261a-4056-b391-6673a623531c';

protected static $errorNames = [
self::AT_LEAST_ONE_OF_ERROR => 'AT_LEAST_ONE_OF_ERROR',
self::ONE_OF_ERROR => 'ONE_OF_ERROR',
];

public $constraints = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
/**
* @author Przemysław Bogusz <[email protected]>
*/
class AtLeastOneOfValidator extends ConstraintValidator
class OneOfValidator extends ConstraintValidator
{
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof AtLeastOneOf) {
throw new UnexpectedTypeException($constraint, AtLeastOneOf::class);
if (!$constraint instanceof OneOf) {
throw new UnexpectedTypeException($constraint, OneOf::class);
}

$validator = $this->context->getValidator();
Expand Down Expand Up @@ -54,7 +54,7 @@ public function validate($value, Constraint $constraint)
}

$this->context->buildViolation(implode('', $messages))
->setCode(AtLeastOneOf::AT_LEAST_ONE_OF_ERROR)
->setCode(OneOf::ONE_OF_ERROR)
->addViolation()
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
namespace Symfony\Component\Validator\Tests\Constraints;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Constraints\AtLeastOneOf;
use Symfony\Component\Validator\Constraints\OneOf;
use Symfony\Component\Validator\Constraints\Valid;

/**
* @author Przemysław Bogusz <[email protected]>
*/
class AtLeastOneOfTest extends TestCase
class OneOfTest extends TestCase
{
public function testRejectNonConstraints()
{
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
new AtLeastOneOf([
new OneOf([
'foo',
]);
}

public function testRejectValidConstraint()
{
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
new AtLeastOneOf([
new OneOf([
new Valid(),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace Symfony\Component\Validator\Tests\Constraints;

use Symfony\Component\Validator\Constraints\AtLeastOneOf;
use Symfony\Component\Validator\Constraints\AtLeastOneOfValidator;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\Count;
use Symfony\Component\Validator\Constraints\Country;
Expand All @@ -24,6 +22,8 @@
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\LessThan;
use Symfony\Component\Validator\Constraints\Negative;
use Symfony\Component\Validator\Constraints\OneOf;
use Symfony\Component\Validator\Constraints\OneOfValidator;
use Symfony\Component\Validator\Constraints\Range;
use Symfony\Component\Validator\Constraints\Regex;
use Symfony\Component\Validator\Constraints\Unique;
Expand All @@ -32,11 +32,11 @@
/**
* @author Przemysław Bogusz <[email protected]>
*/
class AtLeastOneOfValidatorTest extends ConstraintValidatorTestCase
class OneOfValidatorTest extends ConstraintValidatorTestCase
{
protected function createValidator()
{
return new AtLeastOneOfValidator();
return new OneOfValidator();
}

/**
Expand All @@ -50,7 +50,7 @@ public function testValidCombinations($value, $constraints)
$this->expectViolationsAt($i++, $value, $constraint);
}

$this->validator->validate($value, new AtLeastOneOf($constraints));
$this->validator->validate($value, new OneOf($constraints));

$this->assertNoViolation();
}
Expand Down Expand Up @@ -94,7 +94,7 @@ public function getValidCombinations()
*/
public function testInvalidCombinationsWithDefaultMessage($value, $constraints)
{
$atLeastOneOf = new AtLeastOneOf(['constraints' => $constraints]);
$atLeastOneOf = new OneOf(['constraints' => $constraints]);

$message = [$atLeastOneOf->message];

Expand All @@ -106,15 +106,15 @@ public function testInvalidCombinationsWithDefaultMessage($value, $constraints)

$this->validator->validate($value, $atLeastOneOf);

$this->buildViolation(implode('', $message))->setCode(AtLeastOneOf::AT_LEAST_ONE_OF_ERROR)->assertRaised();
$this->buildViolation(implode('', $message))->setCode(OneOf::ONE_OF_ERROR)->assertRaised();
}

/**
* @dataProvider getInvalidCombinations
*/
public function testInvalidCombinationsWithCustomMessage($value, $constraints)
{
$atLeastOneOf = new AtLeastOneOf(['constraints' => $constraints, 'message' => 'foo', 'includeInternalMessages' => false]);
$atLeastOneOf = new OneOf(['constraints' => $constraints, 'message' => 'foo', 'includeInternalMessages' => false]);

$i = 0;

Expand All @@ -124,7 +124,7 @@ public function testInvalidCombinationsWithCustomMessage($value, $constraints)

$this->validator->validate($value, $atLeastOneOf);

$this->buildViolation('foo')->setCode(AtLeastOneOf::AT_LEAST_ONE_OF_ERROR)->assertRaised();
$this->buildViolation('foo')->setCode(OneOf::ONE_OF_ERROR)->assertRaised();
}

public function getInvalidCombinations()
Expand Down