Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
StaticMethodLoader example
$loaders
=
[
]
;
foreach
(
$this
->xmlMappings
as
$xmlMapping
)
{
$loaders
[
]
=
new
XmlFileLoader
(
$xmlMapping
)
;
}
foreach
(
$this
->yamlMappings
as
$yamlMappings
)
{
$loaders
[
]
=
new
YamlFileLoader
(
$yamlMappings
)
;
}
foreach
(
$this
->methodMappings
as
$methodName
)
{
$loaders
[
]
=
new
StaticMethodLoader
(
$methodName
)
;
}
if
(
$this
->enableAnnotationMapping
)
{
$loaders
[
]
=
new
AnnotationLoader
(
$this
->annotationReader
)
;
}
return
array_merge
(
$loaders
,
$this
->loaders
)
;
}
/** * Builds and returns a new validator object. */
use
Symfony\Component\Validator\Validation;
use
Symfony\Component\Validator\Validator\ValidatorInterface;
class
FormValidatorFunctionalTest
extends
TestCase
{
private
ValidatorInterface
$validator
;
private
FormFactoryInterface
$formFactory
;
protected
function
setUp
(
)
: void
{
$this
->validator = Validation::
createValidatorBuilder
(
)
->
setMetadataFactory
(
new
LazyLoadingMetadataFactory
(
new
StaticMethodLoader
(
)
)
)
->
getValidator
(
)
;
$this
->formFactory =
(
new
FormFactoryBuilder
(
)
)
->
addExtension
(
new
ValidatorExtension
(
$this
->validator
)
)
->
getFormFactory
(
)
;
}
public
function
testDataConstraintsInvalidateFormEvenIfFieldIsNotSubmitted
(
)
{
$form
=
$this
->formFactory->
create
(
FooType::
class
)
;
$form
->
submit
(
[
'baz' => 'foobar'
]
, false
)
;
$loaders
=
[
]
;
foreach
(
$this
->xmlMappings
as
$xmlMapping
)
{
$loaders
[
]
=
new
XmlFileLoader
(
$xmlMapping
)
;
}
foreach
(
$this
->yamlMappings
as
$yamlMappings
)
{
$loaders
[
]
=
new
YamlFileLoader
(
$yamlMappings
)
;
}
foreach
(
$this
->methodMappings
as
$methodName
)
{
$loaders
[
]
=
new
StaticMethodLoader
(
$methodName
)
;
}
if
(
$this
->enableAttributeMapping &&
$this
->annotationReader
)
{
$loaders
[
]
=
new
AnnotationLoader
(
$this
->annotationReader
)
;
}
elseif
(
$this
->enableAttributeMapping
)
{
$loaders
[
]
=
new
AttributeLoader
(
)
;
}
return
array_merge
(
$loaders
,
$this
->loaders
)
;
}
$this
->errorLevel =
error_reporting
(
)
;
}
protected
function
tearDown
(
)
: void
{
error_reporting
(
$this
->errorLevel
)
;
}
public
function
testLoadClassMetadataReturnsTrueIfSuccessful
(
)
{
$loader
=
new
StaticMethodLoader
(
'loadMetadata'
)
;
$metadata
=
new
ClassMetadata
(
StaticLoaderEntity::
class
)
;
$this
->
assertTrue
(
$loader
->
loadClassMetadata
(
$metadata
)
)
;
}
public
function
testLoadClassMetadataReturnsFalseIfNotSuccessful
(
)
{
$loader
=
new
StaticMethodLoader
(
'loadMetadata'
)
;
$metadata
=
new
ClassMetadata
(
'\stdClass'
)
;
$this
->
assertFalse
(
$loader
->
loadClassMetadata
(
$metadata
)
)
;
}
$metadata
->
addConstraint
(
new
Callback
(
function
D
)
{
}
)
)
;
$this
->
assertCount
(
3,
$metadata
->
getConstraints
(
)
)
;
$metadata
=
$factory
->
getMetadataFor
(
self::CLASS_NAME
)
;
$this
->
assertCount
(
6,
$metadata
->
getConstraints
(
)
)
;
}
public
function
testGroupsFromParent
(
)
{
$reader
=
new
\Symfony\Component\Validator\Mapping\Loader\
StaticMethodLoader
(
)
;
$factory
=
new
LazyLoadingMetadataFactory
(
$reader
)
;
$metadata
=
$factory
->
getMetadataFor
(
'Symfony\Component\Validator\Tests\Fixtures\EntityStaticCarTurbo'
)
;
$groups
=
[
]
;
foreach
(
$metadata
->
getPropertyMetadata
(
'wheels'
)
as
$propertyMetadata
)
{
$constraints
=
$propertyMetadata
->
getConstraints
(
)
;
$groups
=
array_replace
(
$groups
,
$constraints
[
0
]
->groups
)
;
}
$this
->
assertCount
(
4,
$groups
)
;
$this
->
assertContains
(
'Default',
$groups
)
;