/** * @param $employee Employee */ public function sync($employee) { $repositories = $this->githubRestClient->listUserRepositories($employee->username()); foreach ($repositories as $repository) { $this->repositoryRepository->save($repository); } }
public function testListUserRepositories() { $this->mockRequest->expects($this->once())->method('expectsJson')->willReturn($this->mockRequest); $this->mockRequest->expects($this->once())->method('uri')->with($this->equalTo('https://api.github.com/users/jgiovaresco/repos'))->willReturn($this->mockRequest); $this->mockRequest->expects($this->once())->method('send')->willReturn(new \Httpful\Response('[{ "id": 123, "name": ".vim" },{ "id": 124, "name": "repocount" }]', "HTTP/1.1 200 OK\n\t\t\t\t\tContent-Type: application/json\n\t\t\t\t\tConnection: keep-alive\n\t\t\t\t\tTransfer-Encoding: chunked\r\n", $req = \Httpful\Request::init()->sendsAndExpects(\Httpful\Mime::JSON))); $repositories = $this->gitHubRestClient->listUserRepositories(Employee::builder()->withId('123')->withUsername('jgiovaresco')->build()); expect($repositories)->to->have->length(2); expect($repositories[0]->name())->to->equal('.vim'); expect($repositories[1]->name())->to->equal('repocount'); }