/** * Test rename() * * @return void */ public function testRename() { $getAllResponse = new Response(200, ['Content-Type' => 'application/json'], file_get_contents(__DIR__ . '/../../assets/DirectoryTest_getAll.json')); $mkdirResponse = new Response(200, ['Content-Type' => 'text/plain']); $mockedClient = $this->getMockBuilder('\\Seafile\\Client\\Http\\Client')->getMock(); $mockedClient->method('getConfig')->willReturn('http://example.com/'); $expectUri = 'http://example.com/repos/some-crazy-id/dir/?p=test_dir'; $expectParams = ['headers' => ['Accept' => "application/json"], 'multipart' => [['name' => "operation", 'contents' => "rename"], ['name' => "newname", 'contents' => "test_dir_renamed"]]]; // @todo: Test more thoroughly. For example make sure request() gets called with POST twice (a, then b) $mockedClient->expects(self::any())->method('request')->with(self::logicalOr(self::equalTo('GET'), self::equalTo('POST')))->will(self::returnCallback(function ($method, $uri, $params) use($getAllResponse, $mkdirResponse, $expectUri, $expectParams) { if ($method === 'GET') { return $getAllResponse; } if ($expectUri === $uri && $expectParams === $params) { return $mkdirResponse; } return new Response(500); })); /** * @var Client $mockedClient */ $directoryResource = new Directory($mockedClient); $lib = new Library(); $lib->id = 'some-crazy-id'; self::assertTrue($directoryResource->rename($lib, 'test_dir', 'test_dir_renamed')); }