Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
IndexerOffset example
public
function
testIterateOffsetWithoutLanguageGetSkipped
(
)
: void
{
$indexer
=
$this
->
getIndexer
(
)
;
$this
->indexCreator
->
expects
(
static
::
never
(
)
)
->
method
(
'createIndex'
)
;
$offset
=
new
IndexerOffset
(
[
]
,
[
]
, null
)
;
static
::
assertNull
(
$indexer
->
iterate
(
$offset
)
)
;
}
public
function
testIterateOffsetWithInvalidLanguage
(
)
: void
{
$indexer
=
$this
->
getIndexer
(
)
;
$this
->indexCreator
->
expects
(
static
::
never
(
)
)
private
function
init
(
)
: IndexerOffset
{
$this
->connection->
executeStatement
(
'DELETE FROM elasticsearch_index_task'
)
;
$this
->
createScripts
(
)
;
$timestamp
=
new
\
DateTime
(
)
;
$this
->
createIndex
(
$timestamp
)
;
return
new
IndexerOffset
(
[
]
,
$this
->registry->
getDefinitionNames
(
)
,
$timestamp
->
getTimestamp
(
)
)
;
}
/** * @param array<mixed> $result * * @return array{index: string, id: string, type: string, reason: string}[] */
/** * @internal * * @covers \Shopware\Elasticsearch\Framework\Indexing\IndexerOffset */
class
IndexerOffsetTest
extends
TestCase
{
public
function
testItConvertsDefinitionsToSerializableNamesAndCanDoAnDefinitionRoundTrip
(
)
: void
{
$timestamp
=
(
new
\
DateTime
(
)
)
->
getTimestamp
(
)
;
$offset
=
new
IndexerOffset
(
[
'foo', 'bar'
]
,
[
'product', 'product_manufacturer'
]
,
$timestamp
)
;
static
::
assertEquals
(
ProductDefinition::ENTITY_NAME,
$offset
->
getDefinition
(
)
)
;
static
::
assertTrue
(
$offset
->
hasNextDefinition
(
)
)
;
static
::
assertSame
(
$timestamp
,
$offset
->
getTimestamp
(
)
)
;
static
::
assertNull
(
$offset
->
getLastId
(
)
)
;
$offset
->
selectNextDefinition
(
)
;
$this
->
createScripts
(
)
;
$languages
=
$this
->languageProvider->
getLanguages
(
Context::
createDefaultContext
(
)
)
;
$timestamp
=
new
\
DateTime
(
)
;
foreach
(
$languages
as
$language
)
{
$this
->
createLanguageIndex
(
$language
,
$timestamp
)
;
}
return
new
IndexerOffset
(
array_values
(
$languages
->
getIds
(
)
)
,
$this
->registry->
getDefinitionNames
(
)
,
$timestamp
->
getTimestamp
(
)
)
;
}
/** * @param array<mixed> $result * * @return array{index: string, id: string, type: string, reason: string}[] */
public
function
testIterateWithMessage
(
)
: void
{
$indexer
=
$this
->
getIndexer
(
)
;
$query
=
$this
->
createMock
(
IterableQuery::
class
)
;
$query
->
method
(
'fetch'
)
->
willReturn
(
[
'1', '2'
]
)
;
$this
->iteratorFactory
->
method
(
'createIterator'
)
->
willReturn
(
$query
)
;
$offset
=
new
IndexerOffset
(
[
]
,
[
'product'
]
, null
)
;
$msg
=
$indexer
->
iterate
(
$offset
)
;
static
::
assertInstanceOf
(
ElasticsearchIndexingMessage::
class
,
$msg
)
;
static
::
assertSame
(
Defaults::LANGUAGE_SYSTEM,
$msg
->
getContext
(
)
->
getLanguageId
(
)
)
;
static
::
assertSame
(
[
'1', '2'
]
,
$msg
->
getData
(
)
->
getIds
(
)
)
;
}
public
function
testIterateWithUnknownDefinition
(
)
: void
{
$indexer
=
$this
->
getIndexer
(
)
;