Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
StructEncoder example
)
;
$registry
=
new
StaticDefinitionInstanceRegistry
(
[
SalesChannelProductDefinition::
class
]
,
$this
->
createMock
(
ValidatorInterface::
class
)
,
$this
->
createMock
(
EntityWriteGatewayInterface::
class
)
)
;
$serializer
=
new
Serializer
(
[
new
StructNormalizer
(
)
]
,
[
new
JsonEncoder
(
)
]
)
;
$encoded
=
(
new
StructEncoder
(
$this
->
getChainRegistry
(
$registry
)
,
$serializer
)
)
->
encode
(
$product
,
new
ResponseFields
(
null
)
)
;
static
::
assertArrayNotHasKey
(
'cheapestPrice',
$encoded
)
;
static
::
assertArrayHasKey
(
'name',
$encoded
)
;
static
::
assertEquals
(
'test',
$encoded
[
'name'
]
)
;
}
public
function
testNoneMappedFieldsAreNotExposed
(
)
: void
{
$product
=
new
ExtendedProductEntity
(
)
;
$product
->
internalSetEntityData
(
'product',
new
FieldVisibility
(
[
]
)
)
;
$registry
->
method
(
'has'
)
->
willReturn
(
true
)
;
$definition
=
new
MyEntityDefinition
(
)
;
$definition
->
compile
(
$this
->
getContainer
(
)
->
get
(
DefinitionInstanceRegistry::
class
)
)
;
$registry
->
method
(
'getByEntityName'
)
->
willReturn
(
$definition
)
;
$encoder
=
new
StructEncoder
(
$registry
,
$this
->
getContainer
(
)
->
get
(
'serializer'
)
)
;
$encoded
=
$encoder
->
encode
(
$entity
,
new
ResponseFields
(
null
)
)
;
static
::
assertArrayHasKey
(
'name',
$encoded
)
;
static
::
assertArrayNotHasKey
(
'description',
$encoded
)
;
static
::
assertArrayHasKey
(
'translated',
$encoded
)
;
static
::
assertArrayHasKey
(
'name',
$encoded
[
'translated'
]
)
;