protected function MediaEntityHelperTest::setMockedDrupalServices in Media: Acquia DAM 8
Sets Drupal mocked services into a container.
Parameters
\Drupal\Core\DependencyInjection\ContainerBuilder $container: The container to set mocks into.
1 call to MediaEntityHelperTest::setMockedDrupalServices()
- MediaEntityHelperTest::setUp in tests/
src/ Unit/ MediaEntityHelperTest.php
File
- tests/
src/ Unit/ MediaEntityHelperTest.php, line 162
Class
- MediaEntityHelperTest
- Testing of the Media Entity helper class.
Namespace
Drupal\Tests\media_acquiadam\UnitCode
protected function setMockedDrupalServices(ContainerBuilder $container) {
$media_bundle = $this
->getMockBuilder(\stdClass::class)
->setMethods([
'getFieldMap',
])
->getMock();
$media_bundle
->method('getFieldMap')
->willReturn([
'file' => 'phpunit_file_field',
]);
$entity_storage = $this
->getMockBuilder(EntityStorageInterface::class)
->disableOriginalConstructor()
->getMock();
$entity_storage
->method('load')
->willReturnMap([
[
$this
->getMockedFileEntity()
->id(),
$this
->getMockedFileEntity(),
],
[
'acquiadam',
$media_bundle,
],
]);
$entity_storage
->method('loadByProperties')
->willReturnMap([
[
[
'uri' => 'private://assets/replaced/' . $this
->getAssetData()->filename,
],
[
$this
->getMockedFileEntity(),
],
],
[
[
'uri' => 'private://assets/replaced/Micro turbine 60.jpg',
],
[
$this
->getMockedFileEntity(),
],
],
]);
$entity_type_manager = $this
->getMockBuilder(EntityTypeManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$entity_type_manager
->method('getStorage')
->willReturnMap([
[
'file',
$entity_storage,
],
[
'media_type',
$entity_storage,
],
]);
$container
->set('entity_type.manager', $entity_type_manager);
}