Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
AdminElasticsearchHelper example
$this
->connection =
$this
->
getContainer
(
)
->
get
(
Connection::
class
)
;
$this
->client =
$this
->
getContainer
(
)
->
get
(
Client::
class
)
;
$indexer
=
new
PromotionAdminSearchIndexer
(
$this
->connection,
$this
->
getContainer
(
)
->
get
(
IteratorFactory::
class
)
,
$this
->
getContainer
(
)
->
get
(
'promotion.repository'
)
,
100
)
;
$searchHelper
=
new
AdminElasticsearchHelper
(
true, true, 'sw-admin'
)
;
$this
->registry =
new
AdminSearchRegistry
(
[
'promotion' =>
$indexer
]
,
$this
->connection,
$this
->
createMock
(
MessageBusInterface::
class
)
,
$this
->
createMock
(
EventDispatcherInterface::
class
)
,
$this
->client,
$searchHelper
,
[
]
,
[
]
)
;
}
class
AdminElasticsearchHelperTest
extends
TestCase
{
/** * @dataProvider searchHelperProvider */
public
function
testSearchHelper
(
bool
$adminEsEnabled
, bool
$refreshIndices
, string
$adminIndexPrefix
)
: void
{
$searchHelper
=
new
AdminElasticsearchHelper
(
$adminEsEnabled
,
$refreshIndices
,
$adminIndexPrefix
)
;
static
::
assertEquals
(
$adminEsEnabled
,
$searchHelper
->
getEnabled
(
)
)
;
static
::
assertEquals
(
$refreshIndices
,
$searchHelper
->
getRefreshIndices
(
)
)
;
static
::
assertEquals
(
$adminIndexPrefix
,
$searchHelper
->
getPrefix
(
)
)
;
static
::
assertEquals
(
$adminIndexPrefix
. '-promotion-listing',
$searchHelper
->
getIndex
(
'promotion-listing'
)
)
;
}
public
function
testSetEnable
(
)
: void
{
$searchHelper
=
new
AdminElasticsearchHelper
(
false, false, 'sw-admin'
)
;
$this
->registry =
$this
->
getMockBuilder
(
AdminSearchRegistry::
class
)
->
disableOriginalConstructor
(
)
->
getMock
(
)
;
$indexer
=
new
ProductAdminSearchIndexer
(
$this
->
createMock
(
Connection::
class
)
,
$this
->
createMock
(
IteratorFactory::
class
)
,
$this
->
createMock
(
EntityRepository::
class
)
,
100,
)
;
$this
->registry->
method
(
'getIndexers'
)
->
willReturn
(
[
'product' =>
$indexer
]
)
;
$this
->registry->
method
(
'getIndexer'
)
->
willReturn
(
$indexer
)
;
$searchHelper
=
new
AdminElasticsearchHelper
(
true, false, 'sw-admin'
)
;
$this
->searcher =
new
AdminSearcher
(
$this
->client,
$this
->registry,
$searchHelper
, '5s', 20
)
;
}
public
function
testElasticSearch
(
)
: void
{
$this
->client
->
expects
(
static
::
once
(
)
)
->
method
(
'msearch'
)
->
with
(
[
'body' =>
[
[
public
function
testGetSubscribedEvents
(
)
: void
{
$events
= AdminSearchRegistry::
getSubscribedEvents
(
)
;
static
::
assertArrayHasKey
(
EntityWrittenContainerEvent::
class
,
$events
)
;
}
public
function
testGetIndexers
(
)
: void
{
$searchHelper
=
new
AdminElasticsearchHelper
(
true, false, 'sw-admin'
)
;
$registry
=
new
AdminSearchRegistry
(
[
'promotion' =>
$this
->indexer
]
,
$this
->
createMock
(
Connection::
class
)
,
$this
->
createMock
(
MessageBusInterface::
class
)
,
$this
->
createMock
(
EventDispatcherInterface::
class
)
,
$this
->
createMock
(
Client::
class
)
,
$searchHelper
,
[
]
,
[
]
)
;
$indexers
=
$registry
->
getIndexers
(
)
;
'index' => 'sw-admin-promotion-listing',
]
,
]
)
;
}
public
function
testElasticSearchWithElasticSearchNotEnable
(
)
: void
{
$controller
=
new
AdminSearchController
(
$this
->
getMockBuilder
(
AdminSearcher::
class
)
->
disableOriginalConstructor
(
)
->
getMock
(
)
,
$this
->
createMock
(
DefinitionInstanceRegistry::
class
)
,
$this
->
createMock
(
JsonEntityEncoder::
class
)
,
new
AdminElasticsearchHelper
(
false, false, 'sw-admin'
)
)
;
$request
=
new
Request
(
)
;
$request
->attributes->
set
(
'term', 'test'
)
;
$this
->
expectException
(
\RuntimeException::
class
)
;
$this
->
expectExceptionMessage
(
'Admin elasticsearch is not enabled'
)
;
$controller
->
elastic
(
$request
, Context::
createDefaultContext
(
)
)
;
}