Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
NullOutput example
$connection
=
$this
->
getContainer
(
)
->
get
(
Connection::
class
)
;
$connection
->
executeStatement
(
'DELETE FROM custom_field'
)
;
$command
=
new
ElasticsearchIndexingCommand
(
$this
->
getContainer
(
)
->
get
(
ElasticsearchIndexer::
class
)
,
$this
->
getContainer
(
)
->
get
(
'messenger.bus.shopware'
)
,
$this
->
getContainer
(
)
->
get
(
CreateAliasTaskHandler::
class
)
,
true
)
;
$command
->
run
(
new
ArrayInput
(
[
]
)
,
new
NullOutput
(
)
)
;
static
::
assertNotEmpty
(
$this
->indexDetector->
getAllUsedIndices
(
)
)
;
}
/** * @depends testCreateIndices */
public
function
testCreateCustomFields
(
)
: void
{
$customFieldRepository
=
$this
->
getContainer
(
)
->
get
(
'custom_field_set.repository'
)
;
if
(
Feature::
isActive
(
'ES_MULTILINGUAL_INDEX'
)
)
{
public
function
__construct
(
private
readonly \IteratorAggregate
$generators
,
private
readonly string
$projectDir
,
private
readonly DefinitionInstanceRegistry
$registry
)
{
}
public
function
generate
(
DemodataRequest
$request
, Context
$context
, ?SymfonyStyle
$console
)
: DemodataContext
{
if
(
!
$console
)
{
$console
=
new
ShopwareStyle
(
new
ArgvInput
(
)
,
new
NullOutput
(
)
)
;
}
$faker
=
$this
->
getFaker
(
)
;
$demodataContext
=
new
DemodataContext
(
$context
,
$faker
,
$this
->projectDir,
$console
,
$this
->registry
)
;
foreach
(
$request
->
all
(
)
as
$definitionClass
=>
$numberOfItems
)
{
if
(
$numberOfItems
=== 0
)
{
continue
;
}
$io
->
text
(
sprintf
(
'%s %d plugin(s):',
ucfirst
(
$lifecycleMethod
)
, \
count
(
$plugins
)
)
)
;
$io
->
listing
(
$this
->
formatPluginList
(
$plugins
)
)
;
return
$plugins
;
}
protected
function
refreshPlugins
(
)
: void
{
$input
=
new
StringInput
(
'plugin:refresh -s'
)
;
/** @var Application $application */
$application
=
$this
->
getApplication
(
)
;
$application
->
doRun
(
$input
,
new
NullOutput
(
)
)
;
}
protected
function
handleClearCacheOption
(
InputInterface
$input
, ShopwareStyle
$io
, string
$action
)
: void
{
if
(
$input
->
getOption
(
'clearCache'
)
)
{
$io
->
note
(
'Clearing Cache'
)
;
try
{
$this
->cacheClearer->
clear
(
)
;
}
catch
(
\Exception
)
{
$io
->
error
(
'Error clearing cache'
)
;
$this
->exporter->
expects
(
static
::
once
(
)
)
->
method
(
'generate'
)
->
with
(
static
::
callback
(
function
DSalesChannelContext
$context
)
use
(
$storefrontId
)
{
static
::
assertSame
(
$storefrontId
,
$context
->
getSalesChannelId
(
)
)
;
return
true;
}
)
)
->
willReturn
(
$result
)
;
$input
=
new
ArrayInput
(
[
]
)
;
$this
->command->
run
(
$input
,
new
NullOutput
(
)
)
;
}
}
$cmd
= self::
getContainer
(
)
->
get
(
ChangelogReleaseCommand::
class
)
;
Feature::
registerFeature
(
'CHANGELOG-00001'
)
;
Feature::
registerFeature
(
'CHANGELOG-00002'
)
;
self::
getContainer
(
)
->
get
(
ChangelogReleaseCreator::
class
)
->
setActiveFlags
(
[
'CHANGELOG-00001' =>
[
'default' => true,
]
,
]
)
;
$cmd
->
run
(
new
StringInput
(
'12.13.14.15'
)
,
new
NullOutput
(
)
)
;
static
::
assertFileExists
(
__DIR__ . '/_fixture/stage/command-valid-flag/CHANGELOG.md'
)
;
$content
=
(string)
file_get_contents
(
__DIR__ . '/_fixture/stage/command-valid-flag/CHANGELOG.md'
)
;
static
::
assertStringContainsString
(
'/changelog/release-12-13-14-15/1977-12-10-a-full-change.md',
$content
)
;
static
::
assertStringContainsString
(
'/changelog/release-12-13-14-15/1977-12-11-flag-active',
$content
)
;
static
::
assertStringNotContainsString
(
'/changelog/release-12-13-14-15/1977-12-11-flag-inactive',
$content
)
;
}
}
public
function
disableElasticsearch
(
)
: void
{
$this
->
getDiContainer
(
)
->
get
(
ElasticsearchHelper::
class
)
->
setEnabled
(
false
)
;
}
public
function
indexElasticSearch
(
)
: void
{
$this
->
getDiContainer
(
)
->
get
(
ElasticsearchIndexingCommand::
class
)
->
run
(
new
ArrayInput
(
[
]
)
,
new
NullOutput
(
)
)
;
$this
->
runWorker
(
)
;
$this
->
refreshIndex
(
)
;
}
public
function
refreshIndex
(
)
: void
{
$this
->
getDiContainer
(
)
->
get
(
Client::
class
)
->
indices
(
)
->
refresh
(
[
'index' => '_all'
]
)
;
}
$context
=
$this
->
getSalesChannelContext
(
$redisCart
->
getToken
(
)
)
;
$factory
=
new
RedisConnectionFactory
(
'test-prefix-'
)
;
$redis
=
$factory
->
create
(
(string)
$url
)
;
static
::
assertInstanceOf
(
\Redis::
class
,
$redis
)
;
$redis
->
flushAll
(
)
;
$persister
=
new
RedisCartPersister
(
$redis
,
$this
->
getContainer
(
)
->
get
(
'event_dispatcher'
)
,
$this
->
getContainer
(
)
->
get
(
CartSerializationCleaner::
class
)
, false, 90
)
;
$persister
->
save
(
$redisCart
,
$context
)
;
$command
=
new
CartMigrateCommand
(
$redis
,
$this
->
getContainer
(
)
->
get
(
Connection::
class
)
, false, 90,
$factory
)
;
$command
->
run
(
new
ArrayInput
(
[
'from' => 'redis'
]
)
,
new
NullOutput
(
)
)
;
$persister
=
new
CartPersister
(
$this
->
getContainer
(
)
->
get
(
Connection::
class
)
,
$this
->
getContainer
(
)
->
get
(
'event_dispatcher'
)
,
$this
->
getContainer
(
)
->
get
(
CartSerializationCleaner::
class
)
,
false
)
;
$persister
->
load
(
$redisCart
->
getToken
(
)
,
$context
)
;
}
$generator
=
$this
->
createMock
(
BundleConfigGenerator::
class
)
;
$generator
->
method
(
'getConfig'
)
->
willReturn
(
[
]
)
;
$tempDir
= \
sys_get_temp_dir
(
)
. '/' .
uniqid
(
__FUNCTION__, true
)
;
(
new
Filesystem
(
)
)
->
mkdir
(
[
$tempDir
,
$tempDir
. '/var/'
]
)
;
$dumper
=
new
BundleDumpCommand
(
$generator
,
$tempDir
)
;
static
::
assertSame
(
0,
$dumper
->
run
(
new
StringInput
(
''
)
,
new
NullOutput
(
)
)
)
;
static
::
assertFileExists
(
$tempDir
. '/var/plugins.json'
)
;
(
new
Filesystem
(
)
)
->
remove
(
$tempDir
)
;
}
public
function
testDumperWritesFileToSpecifiedFilePath
(
)
: void
{
$generator
=
$this
->
createMock
(
BundleConfigGenerator::
class
)
;
$generator
->
method
(
'getConfig'
)
->
willReturn
(
[
]
)
;
$tempDir
= \
sys_get_temp_dir
(
)
. '/' .
uniqid
(
__FUNCTION__, true
)
;
(
new
Filesystem
(
)
)
->
mkdir
(
[
$tempDir
,
$tempDir
. '/var/'
]
)
;
->
get
(
AdminElasticsearchHelper::
class
)
->
setEnabled
(
false
)
;
}
/** * @param array<string, mixed> $input */
public
function
indexElasticSearch
(
array
$input
=
[
]
)
: void
{
$this
->
getDiContainer
(
)
->
get
(
ElasticsearchAdminIndexingCommand::
class
)
->
run
(
new
ArrayInput
(
[
...
$input
, '--no-queue' => true
]
)
,
new
NullOutput
(
)
)
;
$this
->
runWorker
(
)
;
$this
->
refreshIndex
(
)
;
}
public
function
refreshIndex
(
)
: void
{
$this
->
getDiContainer
(
)
->
get
(
Client::
class
)
->
indices
(
)
->
refresh
(
[
'index' => '_all'
]
)
;
}