Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
CountryCollection example
new
PaymentMethodEntity
(
)
,
new
ShippingMethodEntity
(
)
,
new
ShippingLocation
(
new
CountryEntity
(
)
, null, null
)
,
new
CustomerEntity
(
)
,
new
CashRoundingConfig
(
1, 1.1, true
)
,
new
CashRoundingConfig
(
1, 1.1, true
)
)
;
$this
->response =
new
CountryRouteResponse
(
new
EntitySearchResult
(
'entity',
1,
new
CountryCollection
(
)
,
null,
new
Criteria
(
)
,
Context::
createDefaultContext
(
)
)
)
;
$this
->cachedRoute =
new
CachedCountryRoute
(
$this
->decorated,
$this
->cache,
$this
->
createMock
(
EntityCacheKeyGenerator::
class
)
,
$this
->
createMock
(
AbstractCacheTracer::
class
)
,
return
$this
->
fmap
(
fn
(
OrderAddressEntity
$orderAddress
)
=>
$orderAddress
->
getVatId
(
)
)
;
}
public
function
filterByVatId
(
string
$id
)
: self
{
return
$this
->
filter
(
fn
(
OrderAddressEntity
$orderAddress
)
=>
$orderAddress
->
getVatId
(
)
===
$id
)
;
}
public
function
getCountries
(
)
: CountryCollection
{
return
new
CountryCollection
(
$this
->
fmap
(
fn
(
OrderAddressEntity
$orderAddress
)
=>
$orderAddress
->
getCountry
(
)
)
)
;
}
public
function
getCountryStates
(
)
: CountryStateCollection
{
return
new
CountryStateCollection
(
$this
->
fmap
(
fn
(
OrderAddressEntity
$orderAddress
)
=>
$orderAddress
->
getCountryState
(
)
)
)
;
}
$this
->
getContainer
(
)
->
get
(
'cache.object'
)
->
invalidateTags
(
[
CachedCountryRoute::
buildName
(
TestDefaults::SALES_CHANNEL
)
]
)
;
}
/** * @dataProvider criteriaProvider */
public
function
testCriteria
(
Criteria
$criteria
)
: void
{
$context
=
$this
->
createMock
(
SalesChannelContext::
class
)
;
$response
=
new
CountryRouteResponse
(
new
EntitySearchResult
(
'country', 0,
new
CountryCollection
(
)
, null,
$criteria
,
$context
->
getContext
(
)
)
)
;
$core
=
$this
->
createMock
(
CountryRoute::
class
)
;
$core
->
expects
(
static
::
exactly
(
2
)
)
->
method
(
'load'
)
->
willReturn
(
$response
)
;
$route
=
new
CachedCountryRoute
(
$core
,
new
TagAwareAdapter
(
new
ArrayAdapter
(
100
)
)
,
$this
->
getContainer
(
)
->
get
(
EntityCacheKeyGenerator::
class
)
,
false|array
$fetchDataResult
,
false|string
$fetchParentLanguageResult
,
array
$entitySearchResult
,
?string
$exceptionMessage
= null
)
: void
{
if
(
$exceptionMessage
!== null
)
{
static
::
expectExceptionMessage
(
$exceptionMessage
)
;
}
$currencyRepository
=
new
StaticEntityRepository
(
[
new
CurrencyCollection
(
$entitySearchResult
[
CurrencyDefinition::ENTITY_NAME
]
??
[
]
)
]
)
;
$customerGroupRepository
=
new
StaticEntityRepository
(
[
new
CustomerGroupCollection
(
$entitySearchResult
[
CustomerGroupDefinition::ENTITY_NAME
]
??
[
]
)
]
)
;
$countryRepository
=
new
StaticEntityRepository
(
[
new
CountryCollection
(
$entitySearchResult
[
CountryDefinition::ENTITY_NAME
]
??
[
]
)
]
)
;
$taxRepository
=
new
StaticEntityRepository
(
[
new
TaxCollection
(
$entitySearchResult
[
TaxDefinition::ENTITY_NAME
]
??
[
]
)
]
)
;
$paymentMethodRepository
=
new
StaticEntityRepository
(
[
new
PaymentMethodCollection
(
$entitySearchResult
[
PaymentMethodDefinition::ENTITY_NAME
]
??
[
]
)
]
)
;
$shippingMethodRepository
=
new
StaticEntityRepository
(
[
new
ShippingMethodCollection
(
$entitySearchResult
[
ShippingMethodDefinition::ENTITY_NAME
]
??
[
]
)
]
)
;
$salesChannelRepository
=
new
StaticEntityRepository
(
[
new
SalesChannelCollection
(
$entitySearchResult
[
SalesChannelDefinition::ENTITY_NAME
]
??
[
]
)
]
)
;
$countryStateRepository
=
new
StaticEntityRepository
(
[
new
CountryStateCollection
(
$entitySearchResult
[
CountryStateDefinition::ENTITY_NAME
]
??
[
]
)
]
)
;
$currencyCountryRepository
=
new
StaticEntityRepository
(
[
new
CurrencyCountryRoundingCollection
(
$entitySearchResult
[
CurrencyCountryRoundingDefinition::ENTITY_NAME
]
??
[
]
)
]
)
;
$connection
=
$this
->
createMock
(
Connection::
class
)
;
$connection
->
expects
(
static
::
once
(
)
)
->
method
(
'fetchAssociative'
)
->
willReturn
(
$fetchDataResult
)
;
if
(
$fetchDataResult
=== false
)
{
return
$this
->
fmap
(
fn
(
CustomerAddressEntity
$customerAddress
)
=>
$customerAddress
->
getCountryStateId
(
)
)
;
}
public
function
filterByCountryStateId
(
string
$id
)
: self
{
return
$this
->
filter
(
fn
(
CustomerAddressEntity
$customerAddress
)
=>
$customerAddress
->
getCountryStateId
(
)
===
$id
)
;
}
public
function
getCountries
(
)
: CountryCollection
{
return
new
CountryCollection
(
$this
->
fmap
(
fn
(
CustomerAddressEntity
$customerAddress
)
=>
$customerAddress
->
getCountry
(
)
)
)
;
}
public
function
getCountryStates
(
)
: CountryStateCollection
{
return
new
CountryStateCollection
(
$this
->
fmap
(
fn
(
CustomerAddressEntity
$customerAddress
)
=>
$customerAddress
->
getCountryState
(
)
)
)
;
}