Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setBackground example
$style
->
setForeground
(
'default'
)
;
$this
->
assertEquals
(
"\033[39mfoo\033[39m",
$style
->
apply
(
'foo'
)
)
;
$this
->
expectException
(
\InvalidArgumentException::
class
)
;
$style
->
setForeground
(
'undefined-color'
)
;
}
public
function
testBackground
(
)
{
$style
=
new
OutputFormatterStyle
(
)
;
$style
->
setBackground
(
'black'
)
;
$this
->
assertEquals
(
"\033[40mfoo\033[49m",
$style
->
apply
(
'foo'
)
)
;
$style
->
setBackground
(
'yellow'
)
;
$this
->
assertEquals
(
"\033[43mfoo\033[49m",
$style
->
apply
(
'foo'
)
)
;
$style
->
setBackground
(
'default'
)
;
$this
->
assertEquals
(
"\033[49mfoo\033[49m",
$style
->
apply
(
'foo'
)
)
;
$this
->
expectException
(
\InvalidArgumentException::
class
)
;
$style
->
setBackground
(
'undefined-color'
)
;
}
return
null;
}
$style
=
new
OutputFormatterStyle
(
)
;
foreach
(
$matches
as
$match
)
{
array_shift
(
$match
)
;
$match
[
0
]
=
strtolower
(
$match
[
0
]
)
;
if
(
'fg' ==
$match
[
0
]
)
{
$style
->
setForeground
(
strtolower
(
$match
[
1
]
)
)
;
}
elseif
(
'bg' ==
$match
[
0
]
)
{
$style
->
setBackground
(
strtolower
(
$match
[
1
]
)
)
;
}
elseif
(
'href' ===
$match
[
0
]
)
{
$url
=
preg_replace
(
'{\\\\([<>])}', '$1',
$match
[
1
]
)
;
$style
->
setHref
(
$url
)
;
}
elseif
(
'options' ===
$match
[
0
]
)
{
preg_match_all
(
'([^,;]+)',
strtolower
(
$match
[
1
]
)
,
$options
)
;
$options
=
array_shift
(
$options
)
;
foreach
(
$options
as
$option
)
{
$style
->
setOption
(
$option
)
;
}
}
else
{
return
null;
}
public
function
testSetForeground
(
)
{
$style
=
new
NullOutputFormatterStyle
(
)
;
$style
->
setForeground
(
'black'
)
;
$this
->
assertSame
(
'foo',
$style
->
apply
(
'foo'
)
)
;
}
public
function
testSetBackground
(
)
{
$style
=
new
NullOutputFormatterStyle
(
)
;
$style
->
setBackground
(
'blue'
)
;
$this
->
assertSame
(
'foo',
$style
->
apply
(
'foo'
)
)
;
}
public
function
testOptions
(
)
{
$style
=
new
NullOutputFormatterStyle
(
)
;
$style
->
setOptions
(
[
'reverse', 'conceal'
]
)
;
$this
->
assertSame
(
'foo',
$style
->
apply
(
'foo'
)
)
;
$style
->
setOption
(
'bold'
)
;
return
null;
}
$style
=
new
OutputFormatterStyle
(
)
;
foreach
(
$matches
as
$match
)
{
array_shift
(
$match
)
;
$match
[
0
]
=
strtolower
(
$match
[
0
]
)
;
if
(
'fg' ==
$match
[
0
]
)
{
$style
->
setForeground
(
strtolower
(
$match
[
1
]
)
)
;
}
elseif
(
'bg' ==
$match
[
0
]
)
{
$style
->
setBackground
(
strtolower
(
$match
[
1
]
)
)
;
}
elseif
(
'href' ===
$match
[
0
]
)
{
$url
=
preg_replace
(
'{\\\\([<>])}', '$1',
$match
[
1
]
)
;
$style
->
setHref
(
$url
)
;
}
elseif
(
'options' ===
$match
[
0
]
)
{
preg_match_all
(
'([^,;]+)',
strtolower
(
$match
[
1
]
)
,
$options
)
;
$options
=
array_shift
(
$options
)
;
foreach
(
$options
as
$option
)
{
$style
->
setOption
(
$option
)
;
}
}
else
{
return
null;
}