public function testFollowersUnauthenticated() { $transportMock = $this->getTransportMock(); $transportMock->expects($this->once())->method('send')->will($this->returnValue($this->getResultUnauthorized())); $user = new User($transportMock); $user->setCredentials(new Authentication\Basic('username', 'password')); // Ensure login/logout process also works $user->login(); $user->logout(); $user->clearCredentials(); $this->setExpectedException('GitHub\\API\\AuthenticationException'); // Try without authentication $result = $user->followers(); }
use GitHub\API\AuthenticationException; // Lets access the User API $user = new User(); /** * Perform operations that require no authentication */ // Get details for user 'dsyph3r' var_dump($user->get('dsyph3r')); // Get users 'dsyph3r' is following var_dump($user->following('dsyph3r')); /** * Perform operations that require authentication */ // Set user credentials and login $user->setCredentials(new Authentication\Basic('username', 'password')); $user->login(); try { // Check if your following user var_dump($user->isFollowing("octocat")); // Update some user details var_dump($user->update(array('location' => 'Wales, United Kingdom'))); // Get all emails for user var_dump($user->emails()->all()); // Add key for user var_dump($user->keys()->create("New Key", "ssh-rsa CCC")); } catch (AuthenticationException $exception) { echo $exception->getMessage(); } // Finally lets logout $user->logout();