Skip to content

updated phpdocs #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
4 changes: 2 additions & 2 deletions src/SplitIO/Sdk/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface ClientInterface
*
* <p>
* This method does not throw any exceptions.
* It also never returns null.
* It also never returns null.
*
* @param $key
* @param $featureName
Expand Down Expand Up @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions src/SplitIO/Sdk/LocalhostClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,18 @@ 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");
if (is_null($key)) {
return array_fill_keys($splitNames, TreatmentEnum::CONTROL);
}

$result = array();

foreach ($splitNames as $split) {
$result[$split] = $this->getTreatment($key["matchingKey"], $split, $attributes);
};
Expand All @@ -215,18 +215,18 @@ 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");
if (is_null($key)) {
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);
};
Expand Down
2 changes: 1 addition & 1 deletion src/SplitIO/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

class Version
{
const CURRENT = '7.1.4';
const CURRENT = '7.1.5';
}
17 changes: 17 additions & 0 deletions tests/Suite/InputValidation/GetTreatmentValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
28 changes: 28 additions & 0 deletions tests/Suite/InputValidation/GetTreatmentsValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 17 additions & 1 deletion tests/Suite/Sdk/SdkClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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");
Expand Down