protected function AssetImageHelperTest::setUp in Media: Acquia DAM 8
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ AssetImageHelperTest.php, line 190
Class
- AssetImageHelperTest
- Tests integration of the AssetImageHelper service.
Namespace
Drupal\Tests\media_acquiadam\UnitCode
protected function setUp() {
parent::setUp();
$http_client = $this
->getMockBuilder(GuzzleClient::class)
->disableOriginalConstructor()
->getMock();
$file_system = $this
->getMockBuilder(FileSystem::class)
->disableOriginalConstructor()
->setMethods([
'copy',
])
->getMockForAbstractClass();
$file_system
->method('copy')
->willReturnCallback(function ($source, $target) {
return is_string($target) ? $target . '_copy' : $target . '_blah';
});
$mime_type_guesser = $this
->getMockBuilder(MimeTypeGuesserInterface::class)
->disableOriginalConstructor()
->getMock();
$mime_type_guesser
->method('guess')
->willReturnCallback(function ($uri) {
$map = [
'public://nothing.jpg' => 'image/jpg',
'public://nothing.mov' => 'video/quicktime',
'public://nothing.pdf' => 'application/pdf',
];
return $map[$uri] ?? FALSE;
});
$image_factory = $this
->getMockBuilder(ImageFactory::class)
->disableOriginalConstructor()
->getMock();
$this->container = new ContainerBuilder();
$this->container
->set('http_client', $http_client);
$this->container
->set('file_system', $file_system);
$this->container
->set('file.mime_type.guesser', $mime_type_guesser);
$this->container
->set('image.factory', $image_factory);
$this->container
->set('config.factory', $this
->getConfigFactoryStub());
\Drupal::setContainer($this->container);
$this->assetImageHelper = $this
->getMockedAssetImageHelper();
}