diff --git a/CHANGES.txt b/CHANGES.txt index f29a0545..70908803 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,6 @@ +7.1.5 (Oct 28, 2022) + - Updated phpdocs for `ClientInterface`. + 7.1.4 (Sep 6, 2022) - Updated dependencies to allow `psr/log` 2 and 3. - Removed `phpdocumentor/phpdocumentor` dependency. diff --git a/README.md b/README.md index 0d6333f0..051e1c2c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Split SDK for PHP -[![Build Status](https://api.travis-ci.com/splitio/php-client.svg?branch=master)](https://api.travis-ci.com/splitio/php-client) +[![build status](https://github.com/splitio/php-client/actions/workflows/ci.yml/badge.svg)](https://github.com/splitio/php-client/actions) +[![Latest stable](https://img.shields.io/packagist/v/splitsoftware/split-sdk-php)](https://packagist.org/packages/splitsoftware/split-sdk-php) +[![Documentation](https://img.shields.io/badge/php_client-documentation-informational)](https://help.split.io/hc/en-us/articles/360020350372-PHP-SDK) 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. diff --git a/src/SplitIO/Sdk/ClientInterface.php b/src/SplitIO/Sdk/ClientInterface.php index e4fbe4e6..67fd1666 100644 --- a/src/SplitIO/Sdk/ClientInterface.php +++ b/src/SplitIO/Sdk/ClientInterface.php @@ -29,7 +29,7 @@ interface ClientInterface * *

* This method does not throw any exceptions. - * It also never returns null. + * It also never returns null. * * @param $key * @param $featureName @@ -74,7 +74,7 @@ public function getTreatment($key, $featureName, array $attributes = null); * @param $key * @param $featureName * @param $attributes - * @return string + * @return array */ public function getTreatmentWithConfig($key, $featureName, array $attributes = null); diff --git a/src/SplitIO/Sdk/LocalhostClient.php b/src/SplitIO/Sdk/LocalhostClient.php index 7a8b51a4..618f0113 100644 --- a/src/SplitIO/Sdk/LocalhostClient.php +++ b/src/SplitIO/Sdk/LocalhostClient.php @@ -191,9 +191,11 @@ public function getTreatmentWithConfig($key, $featureName, array $attributes = n */ public function getTreatments($key, $featureNames, array $attributes = null) { + $result = array(); + $splitNames = InputValidator::validateFeatureNames($featureNames, "getTreatments"); if (is_null($splitNames)) { - return null; + return $result; } $key = InputValidator::validateKey($key, "getTreatments"); @@ -201,8 +203,6 @@ public function getTreatments($key, $featureNames, array $attributes = null) return array_fill_keys($splitNames, TreatmentEnum::CONTROL); } - $result = array(); - foreach ($splitNames as $split) { $result[$split] = $this->getTreatment($key["matchingKey"], $split, $attributes); }; @@ -215,9 +215,11 @@ public function getTreatments($key, $featureNames, array $attributes = null) */ public function getTreatmentsWithConfig($key, $featureNames, array $attributes = null) { + $result = array(); + $splitNames = InputValidator::validateFeatureNames($featureNames, "getTreatmentsWithConfig"); if (is_null($splitNames)) { - return null; + return $result; } $key = InputValidator::validateKey($key, "getTreatmentsWithConfig"); @@ -225,8 +227,6 @@ public function getTreatmentsWithConfig($key, $featureNames, array $attributes = return array_fill_keys($splitNames, array('treatment' => TreatmentEnum::CONTROL, 'config' => null)); } - $result = array(); - foreach ($splitNames as $split) { $result[$split] = $this->getTreatmentWithConfig($key["matchingKey"], $split, $attributes); }; diff --git a/src/SplitIO/Version.php b/src/SplitIO/Version.php index 816ba9d5..bffb80b6 100644 --- a/src/SplitIO/Version.php +++ b/src/SplitIO/Version.php @@ -3,5 +3,5 @@ class Version { - const CURRENT = '7.1.4'; + const CURRENT = '7.1.5'; } diff --git a/tests/Suite/InputValidation/GetTreatmentValidationTest.php b/tests/Suite/InputValidation/GetTreatmentValidationTest.php index b81c8dc1..312ab2ac 100644 --- a/tests/Suite/InputValidation/GetTreatmentValidationTest.php +++ b/tests/Suite/InputValidation/GetTreatmentValidationTest.php @@ -366,6 +366,23 @@ public function testGetTreatmentWithConfigWithNotExistantSplitName() $this->assertEquals('control', $result['treatment']); } + public function testGetTreatmentWitConfigWithhNullFeatureName() + { + $splitSdk = $this->getFactoryClient(); + + $logger = $this->getMockedLogger(); + + $logger->expects($this->once()) + ->method('critical') + ->with($this->equalTo("getTreatmentWithConfig: you passed a null split name, split name must be a non-empty" + . " string.")); + + $result = $splitSdk->getTreatmentWithConfig('some_key', null); + $this->assertEquals('control', $result['treatment']); + $this->assertEquals(null, $result['config']); + + } + public static function tearDownAfterClass(): void { Utils\Utils::cleanCache(); diff --git a/tests/Suite/InputValidation/GetTreatmentsValidationTest.php b/tests/Suite/InputValidation/GetTreatmentsValidationTest.php index ac552efb..7e8d9da6 100644 --- a/tests/Suite/InputValidation/GetTreatmentsValidationTest.php +++ b/tests/Suite/InputValidation/GetTreatmentsValidationTest.php @@ -407,6 +407,34 @@ public function testGetTreatmenstConfigWithoutExistingFeatureName() $this->assertEquals('control', $treatmentResult['some_feature_non_existant']['treatment']); } + public function testGetTreatmenstConfigWithNullFeatures() + { + $splitSdk = $this->getFactoryClient(); + + $logger = $this->getMockedLogger(); + + $logger->expects($this->once()) + ->method('critical') + ->with($this->equalTo('getTreatmentsWithConfig: featureNames must be a non-empty array.')); + + $treatmentResult = $splitSdk->getTreatmentsWithConfig("some_key", null); + $this->assertEquals(array(), $treatmentResult); + } + + public function testGetTreatmenstConfigWithEmptyFeatures() + { + $splitSdk = $this->getFactoryClient(); + + $logger = $this->getMockedLogger(); + + $logger->expects($this->once()) + ->method('critical') + ->with($this->equalTo('getTreatmentsWithConfig: featureNames must be a non-empty array.')); + + $treatmentResult = $splitSdk->getTreatmentsWithConfig("some_key", array()); + $this->assertEquals(array(), $treatmentResult); + } + public static function tearDownAfterClass(): void { Utils\Utils::cleanCache(); diff --git a/tests/Suite/Sdk/SdkClientTest.php b/tests/Suite/Sdk/SdkClientTest.php index 33d47c23..a26ab3fa 100644 --- a/tests/Suite/Sdk/SdkClientTest.php +++ b/tests/Suite/Sdk/SdkClientTest.php @@ -49,8 +49,8 @@ public function testLocalClientYAML() $this->assertEquals('on', $splitSdk->getTreatment('test', 'other_feature_2')); $this->assertEquals('off', $splitSdk->getTreatment('key', 'other_feature_3')); $this->assertEquals('on', $splitSdk->getTreatment('key_whitelist', 'other_feature_3')); - $this->assertEquals('control', $splitSdk->getTreatment(true, 'other_feature_3')); + $this->assertEquals('control', $splitSdk->getTreatment('some', null)); $result = $splitSdk->getTreatments('only_key', array('my_feature', 'other_feature')); $this->assertEquals('off', $result["my_feature"]); @@ -63,6 +63,12 @@ public function testLocalClientYAML() $result = $splitSdk->getTreatments(true, array(true, 'other_feature')); $this->assertEquals('control', $result["other_feature"]); + $result = $splitSdk->getTreatments("some", array()); + $this->assertEquals(array(), $result); + + $result = $splitSdk->getTreatments("some", null); + $this->assertEquals(array(), $result); + $result = $splitSdk->getTreatmentWithConfig('only_key', 'my_feature'); $this->assertEquals('off', $result["treatment"]); $this->assertEquals( @@ -105,6 +111,10 @@ public function testLocalClientYAML() $this->assertEquals('control', $result["treatment"]); $this->assertEquals(null, $result["config"]); + $result = $splitSdk->getTreatmentWithConfig('some', null); + $this->assertEquals('control', $result["treatment"]); + $this->assertEquals(null, $result["config"]); + $result = $splitSdk->getTreatmentsWithConfig('only_key', array('my_feature', 'other_feature')); $this->assertEquals('off', $result['my_feature']["treatment"]); $this->assertEquals( @@ -127,6 +137,12 @@ public function testLocalClientYAML() $result['my_feature']["config"] ); + $result = $splitSdk->getTreatmentsWithConfig('some', array()); + $this->assertEquals(array(), $result); + + $result = $splitSdk->getTreatmentsWithConfig('some', null); + $this->assertEquals(array(), $result); + $this->assertEquals(4, count($splitManager->splitNames())); $splitView = $splitManager->split("my_feature");