public function testUnsuccessfulResult() { $result = Result::fromInvalidCredentials(); $this->assertFalse($result->isSuccess()); $this->expectException(InvalidArgumentException::class); $result->getIdentity(); }
public function authenticate(string $username, string $password) : Result { $identity = $this->identityHandler->createIdentity($username, $password); try { $resultSet = $this->resultSetClient->execute((new Command($this->identityLayout, [$this->usernameField => '==' . $this->resultSetClient->quoteString($username), '-find' => null]))->withIdentity($identity)); } catch (InvalidResponseException $e) { $errorCode = $e->getCode(); if (401 === $errorCode) { return Result::fromInvalidCredentials(); } throw $e; } if ($resultSet->isEmpty()) { throw InvalidResultException::fromEmptyResultSet(); } return Result::fromIdentity($identity); }