Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
addNormalizer example
$this
->resolver->
setNormalizer
(
'norm',
function
D
)
{
Assert::
fail
(
'Should not be called.'
)
;
}
)
;
$this
->
assertEmpty
(
$this
->resolver->
resolve
(
)
)
;
}
public
function
testAddNormalizerReturnsThis
(
)
{
$this
->resolver->
setDefault
(
'foo', 'bar'
)
;
$this
->
assertSame
(
$this
->resolver,
$this
->resolver->
addNormalizer
(
'foo',
function
D
)
{
}
)
)
;
}
public
function
testAddNormalizerClosure
(
)
{
// defined by superclass
$this
->resolver->
setDefault
(
'foo', 'bar'
)
;
$this
->resolver->
setNormalizer
(
'foo',
fn
(
Options
$options
,
$value
)
=> '1st-normalized-'.
$value
)
;
// defined by subclass
$this
->resolver->
addNormalizer
(
'foo',
fn
(
Options
$options
,
$value
)
=> '2nd-normalized-'.
$value
)
;
$this
->
assertEquals
(
[
'foo' => '2nd-normalized-1st-normalized-bar'
]
,
$this
->resolver->
resolve
(
)
)
;
}
$this
->
expectExceptionMessage
(
'The option "foo" does not exist.'
)
;
$resolver
=
new
OptionsResolver
(
)
;
$debug
=
new
OptionsResolverIntrospector
(
$resolver
)
;
$this
->
assertSame
(
'bar',
$debug
->
getNormalizer
(
'foo'
)
)
;
}
public
function
testGetNormalizers
(
)
{
$resolver
=
new
OptionsResolver
(
)
;
$resolver
->
setDefined
(
'foo'
)
;
$resolver
->
addNormalizer
(
'foo',
$normalizer1
=
function
D
)
{
}
)
;
$resolver
->
addNormalizer
(
'foo',
$normalizer2
=
function
D
)
{
}
)
;
$debug
=
new
OptionsResolverIntrospector
(
$resolver
)
;
$this
->
assertSame
(
[
$normalizer1
,
$normalizer2
]
,
$debug
->
getNormalizers
(
'foo'
)
)
;
}
public
function
testGetNormalizersThrowsOnNoConfiguredValue
(
)
{
$this
->
expectException
(
NoConfigurationException::
class
)
;
$this
->
expectExceptionMessage
(
'No normalizer was set for the "foo" option.'
)
;
$resolver
=
new
OptionsResolver
(
)
;