Skip to content

Commit 429e18a

Browse files
authored
Merge pull request #2 from launchdarkly/eb/ch115106/type-hints
add more type hints
2 parents bc7c16f + aa3a89f commit 429e18a

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

src/DatabaseFeatureRequesterTestBase.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DatabaseFeatureRequesterTestBase extends \PHPUnit\Framework\TestCase
2121
* @param string $prefix the key prefix; may be empty/null, in which case we should
2222
* use whatever the default prefix is for this database integration.
2323
*/
24-
protected function clearExistingData($prefix): void
24+
protected function clearExistingData(?string $prefix): void
2525
{
2626
throw new \RuntimeException("test class did not implement clearExistingData");
2727
}
@@ -35,7 +35,7 @@ protected function clearExistingData($prefix): void
3535
*
3636
* @return an implementation instance
3737
*/
38-
protected function makeRequester($prefix): FeatureRequester
38+
protected function makeRequester(?string $prefix): FeatureRequester
3939
{
4040
throw new \RuntimeException("test class did not implement makeRequester");
4141
}
@@ -50,15 +50,20 @@ protected function makeRequester($prefix): FeatureRequester
5050
* @param int $version the version number
5151
* @param string $json the JSON data
5252
*/
53-
protected function putSerializedItem($prefix, $namespace, $key, $version, $json): void
53+
protected function putSerializedItem(
54+
?string $prefix,
55+
string $namespace,
56+
string $key,
57+
int $version,
58+
string $json): void
5459
{
5560
throw new \RuntimeException("test class did not implement putSerializedItem");
5661
}
5762

5863
/**
5964
* @dataProvider prefixParameters
6065
*/
61-
public function testGetFeature($prefix)
66+
public function testGetFeature(?string $prefix)
6267
{
6368
$this->clearExistingData($prefix);
6469
$fr = $this->makeRequester($prefix);
@@ -78,7 +83,7 @@ public function testGetFeature($prefix)
7883
/**
7984
* @dataProvider prefixParameters
8085
*/
81-
public function testGetMissingFeature($prefix)
86+
public function testGetMissingFeature(?string $prefix)
8287
{
8388
$this->clearExistingData($prefix);
8489
$fr = $this->makeRequester($prefix);
@@ -90,7 +95,7 @@ public function testGetMissingFeature($prefix)
9095
/**
9196
* @dataProvider prefixParameters
9297
*/
93-
public function testGetDeletedFeature($prefix)
98+
public function testGetDeletedFeature(?string $prefix)
9499
{
95100
$this->clearExistingData($prefix);
96101
$fr = $this->makeRequester($prefix);
@@ -108,7 +113,7 @@ public function testGetDeletedFeature($prefix)
108113
/**
109114
* @dataProvider prefixParameters
110115
*/
111-
public function testGetAllFeatures($prefix)
116+
public function testGetAllFeatures(?string $prefix)
112117
{
113118
$this->clearExistingData($prefix);
114119
$fr = $this->makeRequester($prefix);
@@ -139,7 +144,7 @@ public function testGetAllFeatures($prefix)
139144
/**
140145
* @dataProvider prefixParameters
141146
*/
142-
public function testAllFeaturesWithEmptyStore($prefix)
147+
public function testAllFeaturesWithEmptyStore(?string $prefix)
143148
{
144149
$this->clearExistingData($prefix);
145150
$fr = $this->makeRequester($prefix);
@@ -151,7 +156,7 @@ public function testAllFeaturesWithEmptyStore($prefix)
151156
/**
152157
* @dataProvider prefixParameters
153158
*/
154-
public function testGetSegment($prefix)
159+
public function testGetSegment(?string $prefix)
155160
{
156161
$this->clearExistingData($prefix);
157162
$fr = $this->makeRequester($prefix);
@@ -170,7 +175,7 @@ public function testGetSegment($prefix)
170175
/**
171176
* @dataProvider prefixParameters
172177
*/
173-
public function testGetMissingSegment($prefix)
178+
public function testGetMissingSegment(?string $prefix)
174179
{
175180
$this->clearExistingData($prefix);
176181
$fr = $this->makeRequester($prefix);
@@ -182,7 +187,7 @@ public function testGetMissingSegment($prefix)
182187
/**
183188
* @dataProvider prefixParameters
184189
*/
185-
public function testGetDeletedSegment($prefix)
190+
public function testGetDeletedSegment(?string $prefix)
186191
{
187192
$this->clearExistingData($prefix);
188193
$fr = $this->makeRequester($prefix);
@@ -221,7 +226,7 @@ public function testPrefixIndependence()
221226
$this->verifyForPrefix($this->makeRequester($prefix2), $flagKey, $segmentKey, $version2);
222227
}
223228

224-
private function setupForPrefix($prefix, $flagKey, $segmentKey, $flagVersion)
229+
private function setupForPrefix(?string $prefix, string $flagKey, string $segmentKey, int $flagVersion)
225230
{
226231
$segmentVersion = $flagVersion * 2;
227232
$this->putSerializedItem($prefix, 'features', $flagKey, $flagVersion,
@@ -230,7 +235,7 @@ private function setupForPrefix($prefix, $flagKey, $segmentKey, $flagVersion)
230235
self::makeSegmentJson($flagKey, $segmentVersion));
231236
}
232237

233-
private function verifyForPrefix($fr, $flagKey, $segmentKey, $flagVersion)
238+
private function verifyForPrefix(FeatureRequester $fr, string $flagKey, string $segmentKey, int $flagVersion)
234239
{
235240
$segmentVersion = $flagVersion * 2;
236241

@@ -256,7 +261,7 @@ public function prefixParameters()
256261
];
257262
}
258263

259-
private static function makeFlagJson($key, $version, $deleted = false)
264+
private static function makeFlagJson(string $key, int $version, bool $deleted = false)
260265
{
261266
return json_encode(array(
262267
'key' => $key,
@@ -278,7 +283,7 @@ private static function makeFlagJson($key, $version, $deleted = false)
278283
));
279284
}
280285

281-
private static function makeSegmentJson($key, $version, $deleted = false)
286+
private static function makeSegmentJson(string $key, int $version, bool $deleted = false)
282287
{
283288
return json_encode(array(
284289
'key' => $key,

tests/DatabaseFeatureRequesterTestBaseTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,27 @@ class DatabaseFeatureRequesterTestBaseTest extends DatabaseFeatureRequesterTestB
9494
{
9595
const DEFAULT_PREFIX = 'defaultprefix';
9696

97-
protected function clearExistingData($prefix): void
97+
protected function clearExistingData(?string $prefix): void
9898
{
9999
FakeDatabase::$data[$this->actualPrefix($prefix)] = [ 'features' => [], 'segments' => [] ];
100100
}
101101

102-
protected function makeRequester($prefix): FeatureRequester
102+
protected function makeRequester(?string $prefix): FeatureRequester
103103
{
104104
return new FakeDatabaseFeatureRequester($this->actualPrefix($prefix));
105105
}
106106

107-
protected function putSerializedItem($prefix, $namespace, $key, $version, $json): void
107+
protected function putSerializedItem(
108+
?string $prefix,
109+
string $namespace,
110+
string $key,
111+
int $version,
112+
string $json): void
108113
{
109114
FakeDatabase::putSerializedItem($this->actualPrefix($prefix), $namespace, $key, $json);
110115
}
111116

112-
private function actualPrefix($prefix): string
117+
private function actualPrefix(?string $prefix): string
113118
{
114119
return ($prefix === null || $prefix === '') ? self::DEFAULT_PREFIX : $prefix;
115120
}

0 commit comments

Comments
 (0)