Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getEmptyMedia example
protected
function
setUp
(
)
: void
{
$this
->nameProvider =
$this
->
getContainer
(
)
->
get
(
FileNameProvider::
class
)
;
$this
->context = Context::
createDefaultContext
(
)
;
$this
->
setFixtureContext
(
$this
->context
)
;
}
public
function
testItReturnsOriginalName
(
)
: void
{
$media
=
$this
->
getEmptyMedia
(
)
;
$original
= 'test';
$new
=
$this
->nameProvider->
provide
(
$original
, 'png',
$media
->
getId
(
)
,
$this
->context
)
;
static
::
assertEquals
(
$original
,
$new
)
;
}
public
function
testItGeneratesNewName
(
)
: void
{
$existing
=
$this
->
getJpg
(
)
;
$searchCriteria
=
new
Criteria
(
)
;
$mediaResult
=
$this
->mediaRepository->
search
(
$searchCriteria
,
$this
->context
)
;
/** @var MediaEntity $updatedMedia */
foreach
(
$mediaResult
->
getEntities
(
)
as
$updatedMedia
)
{
static
::
assertInstanceOf
(
MediaType::
class
,
$updatedMedia
->
getMediaType
(
)
)
;
}
}
public
function
testExecuteWithMediaWithoutFile
(
)
: void
{
$this
->
setFixtureContext
(
$this
->context
)
;
$this
->
getEmptyMedia
(
)
;
$input
=
new
StringInput
(
''
)
;
$output
=
new
BufferedOutput
(
)
;
$this
->
runCommand
(
$this
->generateMediaTypesCommand,
$input
,
$output
)
;
$mediaResult
=
$this
->
getNewMediaEntities
(
)
;
/** @var MediaEntity $updatedMedia */
foreach
(
$mediaResult
as
$updatedMedia
)
{
static
::
assertNull
(
$updatedMedia
->
getMediaType
(
)
)
;
}
}
private
bool
$mediaDirCreated
= false;
private
?MediaUploadedEvent
$thrownMediaEvent
;
protected
function
setUp
(
)
: void
{
$this
->mediaRepository =
$this
->
getContainer
(
)
->
get
(
'media.repository'
)
;
$this
->urlGenerator =
$this
->
getContainer
(
)
->
get
(
UrlGeneratorInterface::
class
)
;
$this
->context = Context::
createDefaultContext
(
)
;
$this
->mediaId =
$this
->
getEmptyMedia
(
)
->
getId
(
)
;
$this
->thrownMediaEvent = null;
$this
->
addEventListener
(
$this
->
getContainer
(
)
->
get
(
'event_dispatcher'
)
,
MediaUploadedEvent::
class
,
function
DMediaUploadedEvent
$event
)
: void
{
$this
->thrownMediaEvent =
$event
;
}
)
;
$projectDir
=
$this
->
getContainer
(
)
->
getParameter
(
'kernel.project_dir'
)
;
private
Context
$context
;
protected
function
setUp
(
)
: void
{
$this
->repository =
$this
->
getContainer
(
)
->
get
(
'media.repository'
)
;
$this
->context = Context::
createDefaultContext
(
)
;
}
public
function
testWriteReadMinimalFields
(
)
: void
{
$media
=
$this
->
getEmptyMedia
(
)
;
$criteria
=
$this
->
getIdCriteria
(
$media
->
getId
(
)
)
;
$result
=
$this
->repository->
search
(
$criteria
,
$this
->context
)
;
$media
=
$result
->
getEntities
(
)
->
first
(
)
;
static
::
assertInstanceOf
(
MediaEntity::
class
,
$media
)
;
static
::
assertEquals
(
$media
->
getId
(
)
,
$media
->
getId
(
)
)
;
}
public
function
testThumbnailsAreConvertedToStructWhenFetchedFromDb
(
)
: void
{