Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
thenUnset example
return
$v
;
}
)
->
end
(
)
->
children
(
)
->
scalarNode
(
'child_node'
)
->
end
(
)
->
booleanNode
(
'bool_force_cast'
)
->
end
(
)
->
integerNode
(
'int_unset_at_zero'
)
->
validate
(
)
->
ifTrue
(
fn
(
$value
)
=> 0 ===
$value
)
->
thenUnset
(
)
->
end
(
)
->
end
(
)
->
end
(
)
->
end
(
)
->
arrayNode
(
'simple_array_node'
)
->
end
(
)
->
enumNode
(
'enum_node'
)
->
values
(
[
'a', 'b'
]
)
->
end
(
)
->
variableNode
(
'variable_node'
)
->
end
(
)
->
scalarNode
(
'string_node'
)
->
validate
(
)
->
ifTrue
(
fn
(
$value
)
=> !\
is_string
(
$value
)
|| 'fail' ===
$value
)
->
thenInvalid
(
'%s is not a valid string'
)
$this
->
assertFalse
(
$this
->
getField
(
$node
, 'normalizeKeys'
)
)
;
}
public
function
testUnsetChild
(
)
{
$node
=
new
ArrayNodeDefinition
(
'root'
)
;
$node
->
children
(
)
->
scalarNode
(
'value'
)
->
beforeNormalization
(
)
->
ifTrue
(
fn
(
$value
)
=>
empty
(
$value
)
)
->
thenUnset
(
)
->
end
(
)
->
end
(
)
->
end
(
)
;
$this
->
assertSame
(
[
]
,
$node
->
getNode
(
)
->
normalize
(
[
'value' => null
]
)
)
;
}
public
function
testPrototypeVariable
(
)
{
$node
=
new
ArrayNodeDefinition
(
'root'
)
;
$test
=
$this
->
getTestBuilder
(
)
->
ifString
(
)
->
thenInvalid
(
'Invalid value'
)
->
end
(
)
;
$this
->
finalizeTestBuilder
(
$test
)
;
}
public
function
testThenUnsetExpression
(
)
{
$test
=
$this
->
getTestBuilder
(
)
->
ifString
(
)
->
thenUnset
(
)
->
end
(
)
;
$this
->
assertEquals
(
[
]
,
$this
->
finalizeTestBuilder
(
$test
)
)
;
}
public
function
testEndIfPartNotSpecified
(
)
{
$this
->
expectException
(
\RuntimeException::
class
)
;
$this
->
expectExceptionMessage
(
'You must specify an if part.'
)
;
$this
->
getTestBuilder
(
)
->
end
(
)
;
}