Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
createEntityManagerMock example
/** * @dataProvider provideConstraintsWithCustomRepositoryMethod */
public
function
testValidateUniquenessUsingCustomRepositoryMethod
(
UniqueEntity
$constraint
)
{
$repository
=
$this
->
createRepositoryMock
(
)
;
$repository
->
expects
(
$this
->
once
(
)
)
->
method
(
'findByCustom'
)
->
willReturn
(
[
]
)
;
$this
->em =
$this
->
createEntityManagerMock
(
$repository
)
;
$this
->registry =
$this
->
createRegistryMock
(
$this
->em
)
;
$this
->validator =
$this
->
createValidator
(
)
;
$this
->validator->
initialize
(
$this
->context
)
;
$entity1
=
new
SingleIntIdEntity
(
1, 'foo'
)
;
$this
->validator->
validate
(
$entity1
,
$constraint
)
;
$this
->
assertNoViolation
(
)
;
}