public function it_returns_a_list_of_Projects_on_findProjects(Api $client, Repositories $repoApi, Repository $api, MessageInterface $response, MessageInterface $singleResponse) { $client->api('Repositories\\Repository')->willReturn($api); $client->api('Repositories')->willReturn($repoApi); $api->get('foo', 'bar')->willReturn($singleResponse); $repoApi->all('foo')->willReturn($response); $singleResponse->getContent()->willReturn('{"full_name": "foo/bar"}'); $response->getContent()->willReturn('[{"full_name": "foo/bar"}]'); $projects = $this->findProjects('foo/[bar|bazz]+$'); $projects->shouldBeArray(); $projects['foo/bar']->shouldHaveType('Rs\\Issues\\Project'); $projects['foo/bar']->shouldHaveType('Rs\\Issues\\Bitbucket\\BitbucketProject'); }
/** * {@inheritdoc} */ public function findProjects($name) { return $this->requestProjects($name, function ($name) { list($user) = explode('/', $name); $api = $this->api->api('Repositories'); /* @var Repositories $api */ $data = json_decode($api->all($user)->getContent(), true); if (isset($data['error'])) { throw new \InvalidArgumentException($data['error']['message']); } return $data; }, 'full_name'); }
public function it_returns_its_issues(Api $client, Issues $issuesApi, PullRequests $mergesApi, MessageInterface $response) { $client->api('Repositories\\Issues')->willReturn($issuesApi); $client->api('Repositories\\PullRequests')->willReturn($mergesApi); $response->getContent()->shouldBeCalled()->willReturn('{ "issues":[{"status" : "open"},{ "status" : "closed"}], "values":[{"status" : "open"},{ "status" : "closed"}] }'); $issuesApi->all('foo', 'bar', ['state' => 'OPEN'])->shouldBeCalled()->willReturn($response); $mergesApi->all('foo', 'bar', ['state' => 'OPEN'])->shouldBeCalled()->willReturn($response); $result = $this->getIssues(); $result->shouldHaveCount(2); $result[0]->shouldHaveType('Rs\\Issues\\Bitbucket\\BitbucketIssue'); $result[0]->getType()->shouldBe('issue'); $result[1]->shouldHaveType('Rs\\Issues\\Bitbucket\\BitbucketIssue'); $result[1]->getType()->shouldBe('pull'); }
/** * @param Api $api * @param string $type * @param array $criteria * * @return Issue[] */ private function findIssues(Api $api, $type, array $criteria) { /* @var Issues|PullRequests $api */ list($username, $repo) = explode('/', $this->getName()); $issues = json_decode($api->all($username, $repo, $criteria)->getContent(), true); $newIssues = []; $key = 'issue' === $type ? 'issues' : 'values'; foreach ((array) $issues[$key] as $issue) { if ('open' !== $issue['status'] && 'new' !== $issue['status']) { continue; } $newIssues[] = new BitbucketIssue($issue, $type, $this->getUrl()); } return $newIssues; }