Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[FWB][Serializer][Form][Validator] Uid integration #36317

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 33 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
UidValidatorTest
  • Loading branch information
Guillaume Pédelagrabe committed Apr 8, 2020
commit 2d88bd078777adb2c6d24c80753e8805c24325be
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Symfony\Component\Validator\Tests\Constraints;

use Symfony\Component\Validator\Constraints\Uid;
use Symfony\Component\Validator\Constraints\UidValidator;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;

class UidValidatorTest extends ConstraintValidatorTestCase
{
protected function createValidator()
{
return new UidValidator();
}

public function testNullIsValid()
{
$this->validator->validate(null, new Uid());

$this->assertNoViolation();
}

public function testEmptyStringIsValid()
{
$this->validator->validate('', new Uid());

$this->assertNoViolation();
}

public function testValidUids()
{
$this->validator->validate('9b7541de-6f87-11ea-ab3c-9da9a81562fc', new Uid());
$this->validator->validate('e576629b-ff34-3642-9c08-1f5219f0d45b', new Uid());
$this->validator->validate('4126dbc1-488e-4f6e-aadd-775dcbac482e', new Uid());
$this->validator->validate('18cdf3d3-ea1b-5b23-a9c5-40abd0e2df22', new Uid());
$this->validator->validate('1ea6ecef-eb9a-66fe-b62b-957b45f17e43', new Uid());
$this->validator->validate('01E4BYF64YZ97MDV6RH0HAMN6X', new Uid());

$this->assertNoViolation();
}

public function testInvalidUid()
{
$value = 'foo';

$constraint = new Uid([
'message' => 'myMessage',
]);

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

$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"'.$value.'"')
->setCode(Uid::INVALID_UID_ERROR)
->assertRaised();
}

public function testInvalidUidForTypes()
{
$value = '9b7541de-6f87-11ea-ab3c-9da9a81562fc';

$constraint = new Uid([
'message' => 'myMessage',
'types' => [Uid::UUID_V3]
]);

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

$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"'.$value.'"')
->setCode(Uid::INVALID_UID_ERROR)
->assertRaised();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.