forked from contentful/contentful.php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCase.php
More file actions
156 lines (136 loc) · 4.85 KB
/
TestCase.php
File metadata and controls
156 lines (136 loc) · 4.85 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* This file is part of the contentful/contentful package.
*
* @copyright 2015-2021 Contentful GmbH
* @license MIT
*/
declare(strict_types=1);
namespace Contentful\Tests\Delivery;
use Cache\Adapter\PHPArray\ArrayCachePool;
use Contentful\Delivery\Client;
use Contentful\Delivery\Client\JsonDecoderClientInterface;
use Contentful\Delivery\ClientOptions;
use Contentful\Tests\TestCase as BaseTestCase;
use Psr\Cache\CacheItemPoolInterface;
class TestCase extends BaseTestCase
{
public const ENV_VAR_HOST = 'CONTENTFUL_CDA_SDK_TESTING_URL';
/**
* @var CacheItemPoolInterface
*/
protected static $cache;
public static function setUpBeforeClass(): void
{
self::$cache = new ArrayCachePool();
}
protected function getClient(string $key): Client
{
$config = $this->getClientConfiguration($key);
return new Client(
$config['token'],
$config['space'],
$config['environment'],
$config['options']
);
}
private function getClientConfiguration(string $key): array
{
$config = [
'default' => [],
'default_preview' => [
'token' => 'e5e8d4c5c122cf28fc1af3ff77d28bef78a3952957f15067bbc29f2f0dde0b50',
'options' => ClientOptions::create()
->usingPreviewApi(),
],
'default_cache' => [
'options' => ClientOptions::create()
->withCache(self::$cache),
],
'default_cache_autowarmup' => [
'options' => ClientOptions::create()
->withCache(self::$cache, true),
],
'default_cache_autowarmup_content' => [
'options' => ClientOptions::create()
->withCache(self::$cache, true, true),
],
'default_klingon' => [
'options' => ClientOptions::create()
->withDefaultLocale('tlh'),
],
'default_invalid' => [
'token' => 'e5e8d4c5c122cf28fc1af3ff77d28bef78a3952957f15067bbc29f2f0dde0b50',
],
'new' => [
'token' => '668efbfd9e398181166dec5df5a500aded96dbca2916646a3c7ec37082a7b756',
'space' => '88dyiqcr7go8',
],
'new_preview' => [
'token' => '81c469d7241ca02349388602dfc14107157063a6901c378a56e1835d688970bf',
'space' => '88dyiqcr7go8',
'options' => ClientOptions::create()
->usingPreviewApi(),
],
'new_limited_permissions' => [
'token' => '8857df140f638519fc7218095a6711d8baa6db8b303797e6d9900e46ced2a7ea',
'space' => '88dyiqcr7go8',
'environment' => 'secondary-environment',
],
'rate_limit' => [
'token' => '8740056d546471e0640d189615470cc12ce2d3188332352ecfb53edac59c4963',
'space' => 'bc32cj3kyfet',
'options' => ClientOptions::create()
->usingPreviewApi(),
],
'low_memory' => [
'token' => '265b7a9d3307c5019d1d5ca97dab8e7e06d46d2e16d5d6bf584d5981cb3471c2',
'space' => 'rtei2u35b4tn',
'options' => ClientOptions::create()
->withLowMemoryResourcePool(),
],
];
if (!isset($config[$key])) {
throw new \InvalidArgumentException(\sprintf('Key "%s" is not a valid value.', $key));
}
$defaultOptions = ClientOptions::create();
if ($testingUrl = \getenv(self::ENV_VAR_HOST)) {
$defaultOptions->withHost($testingUrl);
}
$default = [
'token' => 'b4c0n73n7fu1',
'space' => 'cfexampleapi',
'environment' => 'master',
'options' => $defaultOptions,
];
return \array_merge($default, $config[$key]);
}
/**
* @param ClientOptions $options
*/
protected function getJsonDecoderClient(
string $spaceId,
string $environment = 'master',
ClientOptions $options = null
): JsonDecoderClientInterface {
return new Client('irrelevant', $spaceId, $environment, $options);
}
protected function getHost(string $default = 'https://cdn.contentful.com/'): string
{
return \getenv(self::ENV_VAR_HOST) ?: $default;
}
protected function skipIfApiCoverage()
{
if (\getenv(self::ENV_VAR_HOST)) {
$this->markTestSkipped('This configuration blocks tests that should not be run when in the coverage proxy environment.');
}
}
protected function runOnApiCoverage(): bool
{
if (!\getenv(self::ENV_VAR_HOST)) {
$this->markTestAsPassed();
return false;
}
return true;
}
}