getMockBuilder(StreamInterface::class) ->disableOriginalConstructor() ->getMock(); $stream->method('getContents')->willReturn('value'); $mediaSource = $this->getMockBuilder(MediaSource::class) ->disableOriginalConstructor() ->getMock(); $mediaSource->method('getFileInfo')->willReturn(['mime' => 'text/css']); $mediaSource->method('getFileStream')->willReturn($stream); $mediaAsset = $this->getMockBuilder(MediaAsset::class) ->disableOriginalConstructor() ->getMock(); $mediaAsset->method('getMediaSource')->willReturn($mediaSource); $mediaAsset->method('getMediaIdentifier')->willReturn('value'); $httpSource = $this->getMockBuilder(HttpSource::class) ->disableOriginalConstructor() ->getMock(); $mediaAssetHttpSource = $this->getMockBuilder(MediaAsset::class) ->disableOriginalConstructor() ->getMock(); $mediaAssetHttpSource->method('getMediaSource')->willReturn($httpSource); $mediaAssetHttpSource->method('getMediaIdentifier')->willReturn('value'); return [ ['exist.css', 'data:text/css;base64,' . base64_encode('value')], [$mediaAsset, 'data:text/css;base64,' . base64_encode('value')], [$mediaAssetHttpSource, 'value'], ['http://google.com/styles.css', 'http://google.com/styles.css'] ]; } /** * Test encoder * @dataProvider resourceProvider */ public function testEncode($data, $expected) { $directoryStorage = $this->getMockBuilder(\tao_models_classes_service_StorageDirectory::class) ->disableOriginalConstructor() ->getMock(); $file = $this->getMockBuilder(File::class) ->disableOriginalConstructor() ->getMock(); $file->method('exists')->willReturn(true); $file->method('read')->willReturn('value'); $file->method('getMimeType')->willReturn('text/css'); $directoryStorage->method('getFile')->with('exist.css')->willReturn($file); $encoder = new Base64fileEncoder($directoryStorage); $this->assertEquals($expected, $encoder->encode($data)); } public function testEncodeException() { $this->expectException(ExceptionMissingAsset::class); $directoryStorage = $this->getMockBuilder(\tao_models_classes_service_StorageDirectory::class) ->disableOriginalConstructor() ->getMock(); $file = $this->getMockBuilder(File::class) ->disableOriginalConstructor() ->getMock(); $file->method('exists')->willReturn(false); $directoryStorage->method('getFile')->with('notExist.css')->willReturn($file); $encoder = new Base64fileEncoder($directoryStorage); $this->assertEquals('doesn\'t mater', $encoder->encode('notExist.css')); } }