public function testUpdateUnauthenticated() { $transportMock = $this->getTransportMock(); // Changes for the user $changes = array('name' => 'dsyph3r'); $transportMock->expects($this->once())->method('send')->will($this->returnValue($this->getResultUnauthorized())); $user = new User($transportMock); $this->setExpectedException('GitHub\\API\\AuthenticationException'); // Try without authentication $result = $user->update($changes); }
use GitHub\API\User\User; 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();