/** * {@inheritdoc} */ public function read($path) { $response = $this->client->download($path); $result = new FlysystemMetadata(FlysystemMetadata::TYPE_FILE, $path); $result->contents = (string) $response->getBody(); return $result->toArray(); }
public function testDownload() { $client = $this->getMockBuilder('\\GuzzleHttp\\Client')->getMock(); $accessToken = '123456789'; $content = 'downloaded file content'; $assertRequest = function ($request) use($accessToken) { return $request instanceof Request && $request->getMethod() == 'GET' && $request->getUri()->getHost() == 'api.onedrive.com' && $request->getUri()->getPath() == '/v1.0/drive/root:/some%20pdf%20document.pdf' && $request->getHeader('authorization') == ['bearer ' . $accessToken]; }; $response = $this->getResponseWithFileMetadata(); $assertRequestFileDownload = function ($request) use($accessToken) { return $request instanceof Request && $request->getMethod() == 'GET' && $request->getUri()->getHost() == 'example.org' && $request->getUri()->getPath() == '/some/download/url' && $request->getHeader('authorization') == ['bearer ' . $accessToken]; }; $responseFileDownload = new Response('200', [], $content); $client->expects($this->exactly(2))->method('send')->withConsecutive([$this->callback($assertRequest)], [$this->callback($assertRequestFileDownload)])->willReturn($response, $responseFileDownload); $oneDriveClient = new OneDriveClient($accessToken, $client); $response = $oneDriveClient->download('some pdf document.pdf'); $this->assertEquals($content, (string) $response->getBody()); }