Skip to content
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
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<php>
<const name="REDIS_HOST" value="localhost"/>
<const name="REDIS_PORT" value="6379"/>
<const name="TEST_PREFIX" value="SPLITIO_TEST:."/>
</php>

<testsuites>
Expand Down
34 changes: 0 additions & 34 deletions src/SplitIO/Component/Cache/SplitCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,6 @@ private static function getSplitNameFromCacheKey($key)
return str_replace($cacheKeyPrefix, '', $key);
}

/**
* @param string $splitName
* @param string $split JSON representation
* @return boolean
*/
public function addSplit($splitName, $split)
{
$cache = Di::getCache();
$cacheItem = $cache->getItem(self::getCacheKeyForSplit($splitName));
$cacheItem->set($split);
return $cache->save($cacheItem);
}

/**
* @param string $splitName
* @return boolean
*/
public function removeSplit($splitName)
{
return Di::getCache()->deleteItem(self::getCacheKeyForSplit($splitName));
}

/**
* @param long $changeNumber
* @return boolean
*/
public function setChangeNumber($changeNumber)
{
$since_cached_item = Di::getCache()->getItem(self::getCacheKeyForSinceParameter());
$since_cached_item->set($changeNumber);

return Di::getCache()->save($since_cached_item);
}

/**
* @return long
*/
Expand Down
19 changes: 0 additions & 19 deletions src/SplitIO/Component/Cache/SplitCacheInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,6 @@

interface SplitCacheInterface
{
/**
* @param string $splitName
* @param string $split JSON representation
* @return boolean
*/
public function addSplit($splitName, $split);

/**
* @param string $splitName
* @return boolean
*/
public function removeSplit($splitName);

/**
* @param long $changeNumber
* @return boolean
*/
public function setChangeNumber($changeNumber);

/**
* @return long
*/
Expand Down
27 changes: 9 additions & 18 deletions tests/Suite/Attributes/SdkAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,10 @@
use SplitIO\Component\Cache\SplitCache;
use SplitIO\Component\Common\Di;

use SplitIO\Test\Utils;

class SdkAttributesTest extends \PHPUnit\Framework\TestCase
{
private function addSplitsInCache()
{
$splitChanges = file_get_contents(__DIR__."/files/splitChanges.json");
$this->assertJson($splitChanges);

$splitCache = new SplitCache();

$splitChanges = json_decode($splitChanges, true);
$splits = $splitChanges['splits'];

foreach ($splits as $split) {
$splitName = $split['name'];
$this->assertTrue($splitCache->addSplit($splitName, json_encode($split)));
}
}

private function addSegmentsInCache()
{
$segmentCache = new SegmentCache();
Expand All @@ -50,7 +36,7 @@ public function testClient()
$this->assertTrue(is_string(\SplitIO\version()));

$parameters = array('scheme' => 'redis', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'timeout' => 881);
$options = array();
$options = array('prefix' => TEST_PREFIX);

$sdkConfig = array(
'log' => array('adapter' => 'stdout', 'level' => 'info'),
Expand All @@ -62,7 +48,7 @@ public function testClient()
$splitSdk = $splitFactory->client();

//Populating the cache.
$this->addSplitsInCache();
Utils\Utils::addSplitsInCache(file_get_contents(__DIR__."/files/splitChanges.json"));
$this->addSegmentsInCache();

//Assertions
Expand Down Expand Up @@ -268,4 +254,9 @@ private function betweenOperator(\SplitIO\Sdk\ClientInterface $splitSdk)
$this->assertEquals('off', $splitSdk->getTreatment('user1', 'user_attr_btw_datetime_1458240947021_and_1458246884077', array()));
$this->assertEquals('off', $splitSdk->getTreatment('user1', 'user_attr_btw_datetime_1458240947021_and_1458246884077', null));
}

public static function tearDownAfterClass(): void
{
Utils\Utils::cleanCache();
}
}
2 changes: 1 addition & 1 deletion tests/Suite/Component/TrafficTypeTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private function getMockedLogger()
public function testTrafficTypeWarning()
{
$parameters = array('scheme' => 'redis', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'timeout' => 881);
$options = array();
$options = array('prefix' => TEST_PREFIX);

$sdkConfig = array(
'log' => array('adapter' => 'stdout'),
Expand Down
8 changes: 4 additions & 4 deletions tests/Suite/DynamicConfigurations/EvaluatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class EvaluatorTest extends \PHPUnit\Framework\TestCase
public function testSplitWithoutConfigurations()
{
$parameters = array('scheme' => 'redis', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'timeout' => 881);
$options = array();
$options = array('prefix' => TEST_PREFIX);

$sdkConfig = array(
'log' => array('adapter' => 'stdout'),
Expand Down Expand Up @@ -89,7 +89,7 @@ public function testSplitWithoutConfigurations()
public function testSplitWithConfigurations()
{
$parameters = array('scheme' => 'redis', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'timeout' => 881);
$options = array();
$options = array('prefix' => TEST_PREFIX);

$sdkConfig = array(
'log' => array('adapter' => 'stdout'),
Expand Down Expand Up @@ -117,7 +117,7 @@ public function testSplitWithConfigurations()
public function testSplitWithConfigurationsButKilled()
{
$parameters = array('scheme' => 'redis', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'timeout' => 881);
$options = array();
$options = array('prefix' => TEST_PREFIX);

$sdkConfig = array(
'log' => array('adapter' => 'stdout'),
Expand Down Expand Up @@ -145,7 +145,7 @@ public function testSplitWithConfigurationsButKilled()
public function testSplitWithConfigurationsButKilledWithConfigsOnDefault()
{
$parameters = array('scheme' => 'redis', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'timeout' => 881);
$options = array();
$options = array('prefix' => TEST_PREFIX);

$sdkConfig = array(
'log' => array('adapter' => 'stdout'),
Expand Down
4 changes: 2 additions & 2 deletions tests/Suite/DynamicConfigurations/SplitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SplitTest extends \PHPUnit\Framework\TestCase
public function testSplitWithoutConfigurations()
{
$parameters = array('scheme' => 'redis', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'timeout' => 881);
$options = array();
$options = array('prefix' => TEST_PREFIX);

$sdkConfig = array(
'log' => array('adapter' => 'stdout'),
Expand Down Expand Up @@ -65,7 +65,7 @@ public function testSplitWithoutConfigurations()
public function testSplitWithConfigurations()
{
$parameters = array('scheme' => 'redis', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'timeout' => 881);
$options = array();
$options = array('prefix' => TEST_PREFIX);

$sdkConfig = array(
'log' => array('adapter' => 'stdout'),
Expand Down
30 changes: 12 additions & 18 deletions tests/Suite/Engine/HashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use SplitIO\Engine\Hash\HashAlgorithmEnum;
use SplitIO\Grammar\Split;
use SplitIO\Split as SplitApp;
use SplitIO\Component\Common\Di;

use SplitIO\Test\Utils;

class HashTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -74,26 +77,12 @@ public function testMurmur3HashFunction()
}
}

private function addSplitsInCache()
{
$splitChanges = file_get_contents(__DIR__."/../../files/algoSplits.json");
$this->assertJson($splitChanges);

$splitCache = new SplitCache();

$splitChanges = json_decode($splitChanges, true);
$splits = $splitChanges['splits'];

foreach ($splits as $split) {
$splitName = $split['name'];
$this->assertTrue($splitCache->addSplit($splitName, json_encode($split)));
}
}

public function testAlgoField()
{
Di::set(Di::KEY_FACTORY_TRACKER, false);

$parameters = array('scheme' => 'redis', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'timeout' => 881);
$options = array();
$options = array('prefix' => TEST_PREFIX);

$sdkConfig = array(
'log' => array('adapter' => 'stdout'),
Expand All @@ -105,7 +94,7 @@ public function testAlgoField()
$splitFactory->client();

//Populating the cache.
$this->addSplitsInCache();
Utils\Utils::addSplitsInCache(file_get_contents(__DIR__."/../../files/algoSplits.json"));

$cases = array(
array( // Split with algo = 1. Should use legacy function
Expand Down Expand Up @@ -138,4 +127,9 @@ public function testAlgoField()
$this->assertInstanceof($case['class'], $hasher);
}
}

public static function tearDownAfterClass(): void
{
Utils\Utils::cleanCache();
}
}
2 changes: 1 addition & 1 deletion tests/Suite/InputValidation/FactoryTrackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FactoryTrackerTest extends \PHPUnit\Framework\TestCase
private function getFactoryClient()
{
$parameters = array('scheme' => 'redis', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'timeout' => 881);
$options = array();
$options = array('prefix' => TEST_PREFIX);

$sdkConfig = array(
'log' => array('adapter' => 'stdout'),
Expand Down
9 changes: 8 additions & 1 deletion tests/Suite/InputValidation/GetTreatmentValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
use SplitIO\Component\Common\Di;
use SplitIO\Sdk\Key;

use SplitIO\Test\Utils;

class GetTreatmentValidationTest extends \PHPUnit\Framework\TestCase
{
private function getFactoryClient()
{
Di::set(Di::KEY_FACTORY_TRACKER, false);
$parameters = array('scheme' => 'redis', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'timeout' => 881);
$options = array();
$options = array('prefix' => TEST_PREFIX);

$sdkConfig = array(
'log' => array('adapter' => 'stdout'),
Expand Down Expand Up @@ -363,4 +365,9 @@ public function testGetTreatmentWithConfigWithNotExistantSplitName()
$result = $splitSdk->getTreatmentWithConfig('some_key_non_existant', 'some_feature_non_existant');
$this->assertEquals('control', $result['treatment']);
}

public static function tearDownAfterClass(): void
{
Utils\Utils::cleanCache();
}
}
9 changes: 8 additions & 1 deletion tests/Suite/InputValidation/GetTreatmentsValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
use SplitIO\Component\Common\Di;
use SplitIO\Sdk\Key;

use SplitIO\Test\Utils;

class GetTreatmentsValidationTest extends \PHPUnit\Framework\TestCase
{
private function getFactoryClient()
{
Di::set(Di::KEY_FACTORY_TRACKER, false);
$parameters = array('scheme' => 'redis', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'timeout' => 881);
$options = array();
$options = array('prefix' => TEST_PREFIX);

$sdkConfig = array(
'log' => array('adapter' => 'stdout'),
Expand Down Expand Up @@ -404,4 +406,9 @@ public function testGetTreatmenstConfigWithoutExistingFeatureName()

$this->assertEquals('control', $treatmentResult['some_feature_non_existant']['treatment']);
}

public static function tearDownAfterClass(): void
{
Utils\Utils::cleanCache();
}
}
2 changes: 1 addition & 1 deletion tests/Suite/InputValidation/ManagerValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private function getFactoryClient()
{
Di::set(Di::KEY_FACTORY_TRACKER, false);
$parameters = array('scheme' => 'redis', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'timeout' => 881);
$options = array();
$options = array('prefix' => TEST_PREFIX);

$sdkConfig = array(
'log' => array('adapter' => 'stdout'),
Expand Down
9 changes: 8 additions & 1 deletion tests/Suite/InputValidation/TrackValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
use SplitIO\Component\Common\Di;
use SplitIO\Sdk\Validator\InputValidator;

use SplitIO\Test\Utils;

class TrackValidationTest extends \PHPUnit\Framework\TestCase
{
private function getFactoryClient()
{
Di::set(Di::KEY_FACTORY_TRACKER, false);
$parameters = array('scheme' => 'redis', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'timeout' => 881);
$options = array();
$options = array('prefix' => TEST_PREFIX);

$sdkConfig = array(
'log' => array('adapter' => 'stdout'),
Expand Down Expand Up @@ -513,4 +515,9 @@ public function testTrackWithEventGreaterThan32KB()

$this->assertEquals(false, $splitSdk->track('some_key', 'some_traffic', 'some_event', 1, $properties));
}

public static function tearDownAfterClass(): void
{
Utils\Utils::cleanCache();
}
}
2 changes: 1 addition & 1 deletion tests/Suite/Matchers/MatchersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private function setupSplitApp()
'port' => 6379,
'timeout' => 881
);
$options = array('prefix' => '');
$options = array('prefix' => TEST_PREFIX);
$sdkConfig = array(
'log' => array('adapter' => 'stdout', 'level' => 'info'),
'cache' => array('adapter' => 'predis',
Expand Down
Loading