Пример #1
0
 public function test_should_set_array_of_blobs()
 {
     $this->blob->shouldReceive('path')->once()->andReturn('_posts/2015-10-31-new-post.md');
     $this->blob->shouldReceive('sha')->once()->andReturn('1234567890wertyuiop');
     $tree = new WordPress_GitHub_Sync_Tree(new stdClass());
     $blobs = $tree->set_blobs(array($this->blob))->blobs();
     $this->assertCount(1, $blobs);
     $this->assertSame($this->blob, $blobs[0]);
 }
Пример #2
0
 /**
  * Retrieves a tree by sha recursively from the GitHub API
  *
  * @param string $sha Commit sha to retrieve tree from.
  *
  * @return WordPress_GitHub_Sync_Tree|WP_Error
  */
 protected function tree_recursive($sha)
 {
     if ($cache = $this->app->cache()->fetch_tree($sha)) {
         return $cache;
     }
     $data = $this->call('GET', $this->tree_endpoint() . '/' . $sha . '?recursive=1');
     if (is_wp_error($data)) {
         return $data;
     }
     foreach ($data->tree as $index => $thing) {
         // We need to remove the trees because
         // the recursive tree includes both
         // the subtrees as well the subtrees' blobs.
         if ('tree' === $thing->type) {
             unset($data->tree[$index]);
         }
     }
     $tree = new WordPress_GitHub_Sync_Tree($data);
     $tree->set_blobs($this->blobs($data->tree));
     return $this->app->cache()->set_tree($sha, $tree);
 }