generated from DJTommek/php-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTestUtils.php
51 lines (41 loc) · 1.19 KB
/
TestUtils.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
51
<?php declare(strict_types=1);
namespace Tests;
use App\Cache\NetteCachePsr16;
use DJTommek\Coordinates\Coordinates;
use GuzzleHttp\Handler\MockHandler;
use Nette\Caching\Storages\DevNullStorage;
final class TestUtils
{
public static function randomLat(): float
{
return random_int(-89_999_999, 89_999_999) / 1_000_000;
}
public static function randomLon(): float
{
return random_int(-179_999_999, 179_999_999) / 1_000_000;
}
public static function randomCoords(): Coordinates
{
return new Coordinates(
self::randomLat(),
self::randomLon(),
);
}
/**
* @return array{\GuzzleHttp\Client, MockHandler}
*/
public static function createMockedHttpClient(array $defaultConfig = []): array
{
$mockHandler = new \GuzzleHttp\Handler\MockHandler();
$handlerStack = \GuzzleHttp\HandlerStack::create($mockHandler);
assert(array_key_exists('handler', $defaultConfig) === false);
$defaultConfig['handler'] = $handlerStack;
$httpClient = new \GuzzleHttp\Client($defaultConfig);
return [$httpClient, $mockHandler];
}
public static function createDevNullCache(): \Psr\SimpleCache\CacheInterface
{
$storage = new DevNullStorage();
return new NetteCachePsr16($storage);
}
}