Пример #1
0
 public function it_should_throw_on_login_if_model_doesnt_exist(HttpClient $client, HostInterface $host, Factory $factory)
 {
     $this->beConstructedWith($client, $factory, Helper::fakeUser(['Id' => null]));
     $host->isFree()->willReturn(true);
     $host->getPrimaryKeyValue()->willReturn(1);
     $this->shouldThrow('\\Pisa\\GizmoAPI\\Exceptions\\RequirementException')->duringLogin($host);
 }
Пример #2
0
 /**
  * @return  void
  * @throws  Exception on error
  */
 public function login(HostInterface $host)
 {
     //Currently Gizmo never returns anything but 204, so we never should catch an error
     //That's why we have to do some checks beforehand
     if (!$this->exists()) {
         throw new RequirementException("User doesn't exist");
     } elseif ($this->isLoggedIn()) {
         throw new RequirementException("User is already logged in");
     } elseif (!$host->isFree()) {
         throw new RequirementException("Someone is already logged in to that host");
     }
     $response = $this->client->post('Users/UserLogin', ['userId' => $this->getPrimaryKeyValue(), 'hostId' => $host->getPrimaryKeyValue()]);
     if ($response === null) {
         throw new InternalException("Response failed");
     }
     $response->assertEmpty();
     $response->assertStatusCodes(204);
 }