@@ 42-57 (lines=16) @@ | ||
39 | $this->getApiToken()->shouldReturn('<jwt_token>'); |
|
40 | } |
|
41 | ||
42 | function it_should_throw_authentication_exception_if_api_key_is_invalid( |
|
43 | HttpClient $httpClient, |
|
44 | MessageFactory $messageFactory, |
|
45 | RequestInterface $tokenRequest, |
|
46 | ResponseInterface $tokenResponse, |
|
47 | StreamInterface $tokenStream |
|
48 | ) { |
|
49 | $messageFactory->createRequest('POST', self::LOGIN_ENDPOINT, [], http_build_query(['api_key' => '<api key>']))->willReturn($tokenRequest); |
|
50 | $httpClient->sendRequest($tokenRequest)->willReturn($tokenResponse); |
|
51 | $tokenResponse->getStatusCode()->willReturn(401); |
|
52 | $tokenResponse->getBody()->willReturn($tokenStream); |
|
53 | $tokenStream->__toString()->willReturn('{"message": "Invalid Credentials", "code": 401}'); |
|
54 | ||
55 | $this->shouldThrow(AuthenticationException::class)->during('auth'); |
|
56 | $this->isAuthenticated()->shouldReturn(false); |
|
57 | } |
|
58 | ||
59 | function it_should_throw_invalid_response_exception_if_invalid_json( |
|
60 | HttpClient $httpClient, |
|
@@ 59-74 (lines=16) @@ | ||
56 | $this->isAuthenticated()->shouldReturn(false); |
|
57 | } |
|
58 | ||
59 | function it_should_throw_invalid_response_exception_if_invalid_json( |
|
60 | HttpClient $httpClient, |
|
61 | MessageFactory $messageFactory, |
|
62 | RequestInterface $tokenRequest, |
|
63 | ResponseInterface $tokenResponse, |
|
64 | StreamInterface $tokenStream |
|
65 | ) { |
|
66 | $messageFactory->createRequest('POST', self::LOGIN_ENDPOINT, [], http_build_query(['api_key' => '<api key>']))->willReturn($tokenRequest); |
|
67 | $httpClient->sendRequest($tokenRequest)->willReturn($tokenResponse); |
|
68 | $tokenResponse->getStatusCode()->willReturn(200); |
|
69 | $tokenResponse->getBody()->willReturn($tokenStream); |
|
70 | $tokenStream->__toString()->willReturn('{"invalid JSON",}'); |
|
71 | ||
72 | $this->shouldThrow(InvalidResponseException::class)->during('auth'); |
|
73 | $this->isAuthenticated()->shouldReturn(false); |
|
74 | } |
|
75 | } |
|
76 |