/** * {@inheritdoc} */ public function rename($path, $newpath) { $response = $this->client->rename($path, $newpath); $responseContent = json_decode((string) $response->getBody()); $result = new FlysystemMetadata(FlysystemMetadata::TYPE_FILE, $newpath); $this->updateFlysystemMetadataFromResponseContent($result, $responseContent); return $result->toArray(); }
public function testRename() { $client = $this->getMockBuilder('\\GuzzleHttp\\Client')->getMock(); $accessToken = '123456789'; $content = json_encode(['name' => 'new filename.txt', 'parentReference' => ['path' => '/drive/root:/some folder']]); $assertRequest = function ($request) use($accessToken, $content) { return $request instanceof Request && $request->getMethod() == 'PATCH' && $request->getUri()->getHost() == 'api.onedrive.com' && $request->getUri()->getPath() == '/v1.0/drive/root:/old%20filename.txt' && $request->getHeader('authorization') == ['bearer ' . $accessToken] && $request->getHeader('content-type') == ['application/json'] && (string) $request->getBody() == $content; }; $response = new Response(200, [], 'test response'); $client->expects($this->once())->method('send')->with($this->callback($assertRequest))->willReturn($response); $oneDriveClient = new OneDriveClient($accessToken, $client); $result = $oneDriveClient->rename('old filename.txt', 'some folder/new filename.txt'); $this->assertEquals($response, $result); }