protected function AcquiadamServiceTest::setUp in Media: Acquia DAM 8
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ AcquiadamServiceTest.php, line 227
Class
- AcquiadamServiceTest
- Acquia DAM REST extension tests.
Namespace
Drupal\Tests\media_acquiadam\UnitCode
protected function setUp() {
parent::setUp();
$dam_client = $this
->getMockBuilder(Client::class)
->disableOriginalConstructor()
->getMock();
$dam_client
->expects($this
->any())
->method('getFolder')
->willReturnCallback(function ($folderId) {
return $this
->getFolderData($folderId);
});
$dam_client
->expects($this
->any())
->method('getTopLevelFolders')
->willReturn($this
->getTopLevelFoldersData());
$dam_client
->method('getAsset')
->willReturnMap([
[
$this
->getAssetData()->id,
TRUE,
$this
->getAssetData(),
],
[
$this
->getAssetData()->id,
FALSE,
$this
->getAssetData(),
],
]);
// We need to make sure we get our mocked class instead of the original.
$acquiadam_client_factory = $this
->getMockBuilder(ClientFactory::class)
->disableOriginalConstructor()
->getMock();
$acquiadam_client_factory
->expects($this
->any())
->method('get')
->willReturn($dam_client);
$acquiadam_asset_data = $this
->getMockBuilder(AssetDataInterface::class)
->disableOriginalConstructor()
->getMock();
$this->container = new ContainerBuilder();
$this->container
->set('string_translation', $this
->getStringTranslationStub());
$this->container
->set('config.factory', $this
->getConfigFactoryStub());
$this->container
->set('logger.factory', $this
->getLoggerFactoryStub());
$this->container
->set('media_acquiadam.client_factory', $acquiadam_client_factory);
$this->container
->set('media_acquiadam.asset_data', $acquiadam_asset_data);
\Drupal::setContainer($this->container);
$this->acquiaDamClient = Acquiadam::create($this->container);
}