-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathMockConnector.php
50 lines (41 loc) · 1.17 KB
/
MockConnector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
namespace Platformsh\Client\Tests;
use GuzzleHttp\ClientInterface;
use Platformsh\Client\Connection\Connector;
class MockConnector extends Connector
{
protected array $mockValues = [];
protected int $mockStatus = 200;
/**
* Set the response that all future API calls should return.
*
* @param array $values The response body, which will be encoded as JSON.
* @param int $status The HTTP status code.
*/
public function setMockResult(array $values, int $status = 200): void
{
$this->mockValues = $values;
$this->mockStatus = $status;
$this->client = null;
}
public function isLoggedIn(): bool
{
$this->session->set('refreshToken', 'test');
// @todo test the login method
return true;
}
/**
* @inheritdoc
*
* Add a mock handler so that API responses will be intercepted with the
* mockStatus and mockValues properties.
*/
public function getClient(): ClientInterface
{
return MockClient::create([
'mockStatus' => $this->mockStatus,
'mockValues' => $this->mockValues,
]);
}
}