Skip to content

Commit 9c74c41

Browse files
committed
Merge branch 'master' of github.com:splitio/php-client
2 parents ac52618 + 6dba2e7 commit 9c74c41

File tree

8 files changed

+77
-11
lines changed

8 files changed

+77
-11
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
7.1.5 (Oct 28, 2022)
2+
- Updated phpdocs for `ClientInterface`.
3+
14
7.1.4 (Sep 6, 2022)
25
- Updated dependencies to allow `psr/log` 2 and 3.
36
- Removed `phpdocumentor/phpdocumentor` dependency.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Split SDK for PHP
22

3-
[![Build Status](https://api.travis-ci.com/splitio/php-client.svg?branch=master)](https://api.travis-ci.com/splitio/php-client)
3+
[![build status](https://github.com/splitio/php-client/actions/workflows/ci.yml/badge.svg)](https://github.com/splitio/php-client/actions)
4+
[![Latest stable](https://img.shields.io/packagist/v/splitsoftware/split-sdk-php)](https://packagist.org/packages/splitsoftware/split-sdk-php)
5+
[![Documentation](https://img.shields.io/badge/php_client-documentation-informational)](https://help.split.io/hc/en-us/articles/360020350372-PHP-SDK)
46

57
This SDK is designed to work with Split, the platform for controlled rollouts, serving features to your users via the Split feature flag to manage your complete customer experience.
68

src/SplitIO/Sdk/ClientInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface ClientInterface
2929
*
3030
* <p>
3131
* This method does not throw any exceptions.
32-
* It also never returns null.
32+
* It also never returns null.
3333
*
3434
* @param $key
3535
* @param $featureName
@@ -74,7 +74,7 @@ public function getTreatment($key, $featureName, array $attributes = null);
7474
* @param $key
7575
* @param $featureName
7676
* @param $attributes
77-
* @return string
77+
* @return array
7878
*/
7979
public function getTreatmentWithConfig($key, $featureName, array $attributes = null);
8080

src/SplitIO/Sdk/LocalhostClient.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,18 @@ public function getTreatmentWithConfig($key, $featureName, array $attributes = n
191191
*/
192192
public function getTreatments($key, $featureNames, array $attributes = null)
193193
{
194+
$result = array();
195+
194196
$splitNames = InputValidator::validateFeatureNames($featureNames, "getTreatments");
195197
if (is_null($splitNames)) {
196-
return null;
198+
return $result;
197199
}
198200

199201
$key = InputValidator::validateKey($key, "getTreatments");
200202
if (is_null($key)) {
201203
return array_fill_keys($splitNames, TreatmentEnum::CONTROL);
202204
}
203205

204-
$result = array();
205-
206206
foreach ($splitNames as $split) {
207207
$result[$split] = $this->getTreatment($key["matchingKey"], $split, $attributes);
208208
};
@@ -215,18 +215,18 @@ public function getTreatments($key, $featureNames, array $attributes = null)
215215
*/
216216
public function getTreatmentsWithConfig($key, $featureNames, array $attributes = null)
217217
{
218+
$result = array();
219+
218220
$splitNames = InputValidator::validateFeatureNames($featureNames, "getTreatmentsWithConfig");
219221
if (is_null($splitNames)) {
220-
return null;
222+
return $result;
221223
}
222224

223225
$key = InputValidator::validateKey($key, "getTreatmentsWithConfig");
224226
if (is_null($key)) {
225227
return array_fill_keys($splitNames, array('treatment' => TreatmentEnum::CONTROL, 'config' => null));
226228
}
227229

228-
$result = array();
229-
230230
foreach ($splitNames as $split) {
231231
$result[$split] = $this->getTreatmentWithConfig($key["matchingKey"], $split, $attributes);
232232
};

src/SplitIO/Version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
class Version
55
{
6-
const CURRENT = '7.1.4';
6+
const CURRENT = '7.1.5';
77
}

tests/Suite/InputValidation/GetTreatmentValidationTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,23 @@ public function testGetTreatmentWithConfigWithNotExistantSplitName()
366366
$this->assertEquals('control', $result['treatment']);
367367
}
368368

369+
public function testGetTreatmentWitConfigWithhNullFeatureName()
370+
{
371+
$splitSdk = $this->getFactoryClient();
372+
373+
$logger = $this->getMockedLogger();
374+
375+
$logger->expects($this->once())
376+
->method('critical')
377+
->with($this->equalTo("getTreatmentWithConfig: you passed a null split name, split name must be a non-empty"
378+
. " string."));
379+
380+
$result = $splitSdk->getTreatmentWithConfig('some_key', null);
381+
$this->assertEquals('control', $result['treatment']);
382+
$this->assertEquals(null, $result['config']);
383+
384+
}
385+
369386
public static function tearDownAfterClass(): void
370387
{
371388
Utils\Utils::cleanCache();

tests/Suite/InputValidation/GetTreatmentsValidationTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,34 @@ public function testGetTreatmenstConfigWithoutExistingFeatureName()
407407
$this->assertEquals('control', $treatmentResult['some_feature_non_existant']['treatment']);
408408
}
409409

410+
public function testGetTreatmenstConfigWithNullFeatures()
411+
{
412+
$splitSdk = $this->getFactoryClient();
413+
414+
$logger = $this->getMockedLogger();
415+
416+
$logger->expects($this->once())
417+
->method('critical')
418+
->with($this->equalTo('getTreatmentsWithConfig: featureNames must be a non-empty array.'));
419+
420+
$treatmentResult = $splitSdk->getTreatmentsWithConfig("some_key", null);
421+
$this->assertEquals(array(), $treatmentResult);
422+
}
423+
424+
public function testGetTreatmenstConfigWithEmptyFeatures()
425+
{
426+
$splitSdk = $this->getFactoryClient();
427+
428+
$logger = $this->getMockedLogger();
429+
430+
$logger->expects($this->once())
431+
->method('critical')
432+
->with($this->equalTo('getTreatmentsWithConfig: featureNames must be a non-empty array.'));
433+
434+
$treatmentResult = $splitSdk->getTreatmentsWithConfig("some_key", array());
435+
$this->assertEquals(array(), $treatmentResult);
436+
}
437+
410438
public static function tearDownAfterClass(): void
411439
{
412440
Utils\Utils::cleanCache();

tests/Suite/Sdk/SdkClientTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public function testLocalClientYAML()
4949
$this->assertEquals('on', $splitSdk->getTreatment('test', 'other_feature_2'));
5050
$this->assertEquals('off', $splitSdk->getTreatment('key', 'other_feature_3'));
5151
$this->assertEquals('on', $splitSdk->getTreatment('key_whitelist', 'other_feature_3'));
52-
5352
$this->assertEquals('control', $splitSdk->getTreatment(true, 'other_feature_3'));
53+
$this->assertEquals('control', $splitSdk->getTreatment('some', null));
5454

5555
$result = $splitSdk->getTreatments('only_key', array('my_feature', 'other_feature'));
5656
$this->assertEquals('off', $result["my_feature"]);
@@ -63,6 +63,12 @@ public function testLocalClientYAML()
6363
$result = $splitSdk->getTreatments(true, array(true, 'other_feature'));
6464
$this->assertEquals('control', $result["other_feature"]);
6565

66+
$result = $splitSdk->getTreatments("some", array());
67+
$this->assertEquals(array(), $result);
68+
69+
$result = $splitSdk->getTreatments("some", null);
70+
$this->assertEquals(array(), $result);
71+
6672
$result = $splitSdk->getTreatmentWithConfig('only_key', 'my_feature');
6773
$this->assertEquals('off', $result["treatment"]);
6874
$this->assertEquals(
@@ -105,6 +111,10 @@ public function testLocalClientYAML()
105111
$this->assertEquals('control', $result["treatment"]);
106112
$this->assertEquals(null, $result["config"]);
107113

114+
$result = $splitSdk->getTreatmentWithConfig('some', null);
115+
$this->assertEquals('control', $result["treatment"]);
116+
$this->assertEquals(null, $result["config"]);
117+
108118
$result = $splitSdk->getTreatmentsWithConfig('only_key', array('my_feature', 'other_feature'));
109119
$this->assertEquals('off', $result['my_feature']["treatment"]);
110120
$this->assertEquals(
@@ -127,6 +137,12 @@ public function testLocalClientYAML()
127137
$result['my_feature']["config"]
128138
);
129139

140+
$result = $splitSdk->getTreatmentsWithConfig('some', array());
141+
$this->assertEquals(array(), $result);
142+
143+
$result = $splitSdk->getTreatmentsWithConfig('some', null);
144+
$this->assertEquals(array(), $result);
145+
130146
$this->assertEquals(4, count($splitManager->splitNames()));
131147

132148
$splitView = $splitManager->split("my_feature");

0 commit comments

Comments
 (0)