Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
Blank example
'activated' => true,
'compared_value' => 'bar',
]
,
]
)
)
;
$this
->
assertNoViolation
(
)
;
}
public
function
testConstraintViolations
(
)
{
$constraints
=
[
new
Blank
(
[
'message' => 'my_message',
]
)
,
]
;
$this
->
expectFailingValueValidation
(
0,
'foo',
$constraints
,
null,
new
ConstraintViolation
(
'my_message',
'my_message',
[
use
Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
class
BlankValidatorTest
extends
ConstraintValidatorTestCase
{
protected
function
createValidator
(
)
: BlankValidator
{
return
new
BlankValidator
(
)
;
}
public
function
testNullIsValid
(
)
{
$this
->validator->
validate
(
null,
new
Blank
(
)
)
;
$this
->
assertNoViolation
(
)
;
}
public
function
testBlankIsValid
(
)
{
$this
->validator->
validate
(
'',
new
Blank
(
)
)
;
$this
->
assertNoViolation
(
)
;
}
class
ValidationTest
extends
TestCase
{
public
function
testCreateCallableValid
(
)
{
$validator
= Validation::
createCallable
(
new
NotBlank
(
)
)
;
$this
->
assertEquals
(
'
[email protected]
',
$validator
(
'
[email protected]
'
)
)
;
}
public
function
testCreateCallableInvalid
(
)
{
$validator
= Validation::
createCallable
(
new
Blank
(
)
)
;
try
{
$validator
(
'test'
)
;
$this
->
fail
(
'No ValidationFailedException thrown'
)
;
}
catch
(
ValidationFailedException
$e
)
{
$this
->
assertEquals
(
'test',
$e
->
getValue
(
)
)
;
$violations
=
$e
->
getViolations
(
)
;
$this
->
assertCount
(
1,
$violations
)
;
$this
->
assertEquals
(
'This value should be blank.',
$violations
->
get
(
0
)
->
getMessage
(
)
)
;
}
}