/**
  * Test unstar()
  *
  * @param array $data Data provider array
  *
  * @return void
  * @throws \Exception
  * @dataProvider dataProviderUnstar
  */
 public function testUnstar(array $data)
 {
     $lib = new LibraryType();
     $lib->id = 123;
     $dirItem = new DirectoryItem();
     $dirItem->type = 'file';
     $dirItem->path = '/some/path';
     $mockedClient = $this->getMockBuilder('\\Seafile\\Client\\Http\\Client')->getMock();
     $mockedClient->expects(self::any())->method('getConfig')->with('base_uri')->willReturn('https://example.com/test/');
     $mockedClient->expects(self::any())->method('request')->with('DELETE')->willReturn(new Response($data['responseCode']));
     /** @var Client $mockedClient */
     $starredFileResource = new StarredFile($mockedClient);
     self::assertSame($data['result'], $starredFileResource->unstar($lib, $dirItem));
 }
Beispiel #2
0
 * }
 */
$cfgFile = getenv("HOME") . "/.seafile-php-sdk/cfg.json";
if (!is_readable($tokenFile)) {
    throw new Exception($tokenFile . ' is not readable or does not exist.');
}
if (!is_readable($cfgFile)) {
    throw new Exception($cfgFile . ' is not readable or does not exist.');
}
$token = json_decode(file_get_contents($tokenFile));
$cfg = json_decode(file_get_contents($cfgFile));
$client = new Client(['base_uri' => $cfg->baseUri, 'debug' => true, 'handler' => $stack, 'headers' => ['Content-Type' => 'application/json', 'Authorization' => 'Token ' . $token->token]]);
$libraryResource = new Library($client);
$directoryResource = new Directory($client);
$fileResource = new File($client);
$starredFileResource = new StarredFile($client);
// get all starred files
$logger->log(Logger::INFO, "#################### Getting all starred files");
$dirItems = $starredFileResource->getAll();
if (!empty($dirItems)) {
    foreach ($dirItems as $dirItem) {
        var_dump($dirItem);
    }
    $logger->log(Logger::INFO, "#################### Unstarring files...");
    foreach ($dirItems as $dirItem) {
        $lib = $libraryResource->getById($dirItem->repo);
        $starredFileResource->unstar($lib, $dirItem);
    }
    $logger->log(Logger::INFO, "#################### Sleeping 10s before starring them again...");
    sleep(10);
    foreach ($dirItems as $dirItem) {