Skip to content

Commit df2ceb8

Browse files
Merge pull request #3 from optimizely/devel
Merge changes into master
2 parents 0aabb4a + 3133189 commit df2ceb8

File tree

4 files changed

+132
-8
lines changed

4 files changed

+132
-8
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Optimizely PHP SDK
2-
[![Build Status](https://travis-ci.com/optimizely/optimizely-testing-sdk-php.svg?token=xoLe5GgfDMgLPXDntAq3&branch=master)](https://travis-ci.com/optimizely/optimizely-testing-sdk-php)
3-
[![Coverage Status](https://coveralls.io/repos/github/optimizely/optimizely-testing-sdk-php/badge.svg?branch=master&t=4n6YBV)](https://coveralls.io/github/optimizely/optimizely-testing-sdk-php?branch=add_coveralls)
2+
[![Build Status](https://travis-ci.com/optimizely/php-sdk.svg?token=xoLe5GgfDMgLPXDntAq3&branch=master)](https://travis-ci.com/optimizely/php-sdk)
3+
[![Coverage Status](https://coveralls.io/repos/github/optimizely/php-sdk/badge.svg?t=90ED5t)](https://coveralls.io/github/optimizely/php-sdk)
44
[![Apache 2.0](https://img.shields.io/github/license/nebula-plugins/gradle-extra-configurations-plugin.svg)](http://www.apache.org/licenses/LICENSE-2.0)
55

66
This repository houses the PHP SDK for Optimizely Full Stack.

src/Optimizely/ProjectConfig.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,21 @@ public function getEvent($eventKey)
215215
return new Event();
216216
}
217217

218+
/**
219+
* @param $audienceId string ID of the audience.
220+
*
221+
* @return Audience Entity corresponding to the ID.
222+
* Dummy entity is returned if ID is invalid.
223+
*/
224+
public function getAudience($audienceId)
225+
{
226+
if (isset($this->_audienceIdMap[$audienceId])) {
227+
return $this->_audienceIdMap[$audienceId];
228+
}
229+
230+
return new Audience();
231+
}
232+
218233
/**
219234
* @param $attributeKey string Key of the attribute.
220235
*

tests/OptimizelyTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ public function setUp()
4545
->getMock();
4646
}
4747

48-
public function testInit()
49-
{
50-
$this->markTestSkipped('To be implemented.');
51-
}
52-
5348
public function testInitValidEventDispatcher()
5449
{
5550
$validDispatcher = new ValidEventDispatcher();

tests/ProjectConfigTest.php

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
include('TestData.php');
2020

2121
use Optimizely\Entity\Attribute;
22+
use Optimizely\Entity\Audience;
2223
use Optimizely\Entity\Event;
2324
use Optimizely\Entity\Experiment;
2425
use Optimizely\Entity\Group;
@@ -36,7 +37,108 @@ protected function setUp()
3637

3738
public function testInit()
3839
{
39-
$this->markTestSkipped('To be implemented.');
40+
// Check version
41+
$version = new \ReflectionProperty(ProjectConfig::class, '_version');
42+
$version->setAccessible(true);
43+
$this->assertEquals('2', $version->getValue($this->config));
44+
45+
// Check account ID
46+
$accountId = new \ReflectionProperty(ProjectConfig::class, '_accountId');
47+
$accountId->setAccessible(true);
48+
$this->assertEquals('1592310167', $accountId->getValue($this->config));
49+
50+
// Check project ID
51+
$projectId = new \ReflectionProperty(ProjectConfig::class, '_projectId');
52+
$projectId->setAccessible(true);
53+
$this->assertEquals('7720880029', $projectId->getValue($this->config));
54+
55+
// Check revision
56+
$revision = new \ReflectionProperty(ProjectConfig::class, '_revision');
57+
$revision->setAccessible(true);
58+
$this->assertEquals('15', $revision->getValue($this->config));
59+
60+
// Check group ID map
61+
$groupIdMap = new \ReflectionProperty(ProjectConfig::class, '_groupIdMap');
62+
$groupIdMap->setAccessible(true);
63+
$this->assertEquals([
64+
'7722400015' => $this->config->getGroup('7722400015')
65+
], $groupIdMap->getValue($this->config));
66+
67+
// Check experiment key map
68+
$experimentKeyMap = new \ReflectionProperty(ProjectConfig::class, '_experimentKeyMap');
69+
$experimentKeyMap->setAccessible(true);
70+
$this->assertEquals([
71+
'test_experiment' => $this->config->getExperimentFromKey('test_experiment'),
72+
'group_experiment_1' => $this->config->getExperimentFromKey('group_experiment_1'),
73+
'group_experiment_2' => $this->config->getExperimentFromKey('group_experiment_2')
74+
], $experimentKeyMap->getValue($this->config));
75+
76+
// Check experiment ID map
77+
$experimentIdMap = new \ReflectionProperty(ProjectConfig::class, '_experimentIdMap');
78+
$experimentIdMap->setAccessible(true);
79+
$this->assertEquals([
80+
'7716830082' => $this->config->getExperimentFromId('7716830082'),
81+
'7723330021' => $this->config->getExperimentFromId('7723330021'),
82+
'7718750065' => $this->config->getExperimentFromId('7718750065')
83+
], $experimentIdMap->getValue($this->config));
84+
85+
// Check event key map
86+
$eventKeyMap = new \ReflectionProperty(ProjectConfig::class, '_eventKeyMap');
87+
$eventKeyMap->setAccessible(true);
88+
$this->assertEquals([
89+
'purchase' => $this->config->getEvent('purchase')
90+
], $eventKeyMap->getValue($this->config));
91+
92+
// Check attribute key map
93+
$attributeKeyMap = new \ReflectionProperty(ProjectConfig::class, '_attributeKeyMap');
94+
$attributeKeyMap->setAccessible(true);
95+
$this->assertEquals([
96+
'device_type' => $this->config->getAttribute('device_type'),
97+
'location' => $this->config->getAttribute('location')
98+
], $attributeKeyMap->getValue($this->config));
99+
100+
// Check audience ID map
101+
$audienceIdMap = new \ReflectionProperty(ProjectConfig::class, '_audienceIdMap');
102+
$audienceIdMap->setAccessible(true);
103+
$this->assertEquals([
104+
'7718080042' => $this->config->getAudience('7718080042')
105+
], $audienceIdMap->getValue($this->config));
106+
107+
// Check variation key map
108+
$variationKeyMap = new \ReflectionProperty(ProjectConfig::class, '_variationKeyMap');
109+
$variationKeyMap->setAccessible(true);
110+
$this->assertEquals([
111+
'test_experiment' => [
112+
'control' => $this->config->getVariationFromKey('test_experiment', 'control'),
113+
'variation' => $this->config->getVariationFromKey('test_experiment', 'variation')
114+
],
115+
'group_experiment_1' => [
116+
'group_exp_1_var_1' => $this->config->getVariationFromKey('group_experiment_1', 'group_exp_1_var_1'),
117+
'group_exp_1_var_2' => $this->config->getVariationFromKey('group_experiment_1', 'group_exp_1_var_2')
118+
],
119+
'group_experiment_2' => [
120+
'group_exp_2_var_1' => $this->config->getVariationFromKey('group_experiment_2', 'group_exp_2_var_1'),
121+
'group_exp_2_var_2' => $this->config->getVariationFromKey('group_experiment_2', 'group_exp_2_var_2')
122+
]
123+
], $variationKeyMap->getValue($this->config));
124+
125+
// Check variation ID map
126+
$variationIdMap = new \ReflectionProperty(ProjectConfig::class, '_variationIdMap');
127+
$variationIdMap->setAccessible(true);
128+
$this->assertEquals([
129+
'test_experiment' => [
130+
'7722370027' => $this->config->getVariationFromId('test_experiment', '7722370027'),
131+
'7721010009' => $this->config->getVariationFromId('test_experiment', '7721010009')
132+
],
133+
'group_experiment_1' => [
134+
'7722260071' => $this->config->getVariationFromId('group_experiment_1', '7722260071'),
135+
'7722360022' => $this->config->getVariationFromId('group_experiment_1', '7722360022')
136+
],
137+
'group_experiment_2' => [
138+
'7713030086' => $this->config->getVariationFromId('group_experiment_2', '7713030086'),
139+
'7725250007' => $this->config->getVariationFromId('group_experiment_2', '7725250007')
140+
]
141+
], $variationIdMap->getValue($this->config));
40142
}
41143

42144
public function testGetAccountId()
@@ -98,6 +200,18 @@ public function testGetEventInvalidKey()
98200
$this->assertEquals(new Event(), $this->config->getEvent('invalid_key'));
99201
}
100202

203+
public function testGetAudienceValidId()
204+
{
205+
$audience = $this->config->getAudience('7718080042');
206+
$this->assertEquals('7718080042', $audience->getId());
207+
$this->assertEquals('iPhone users in San Francisco', $audience->getName());
208+
}
209+
210+
public function testGetAudienceInvalidKey()
211+
{
212+
$this->assertEquals(new Audience(), $this->config->getAudience('invalid_id'));
213+
}
214+
101215
public function testGetAttributeValidKey()
102216
{
103217
$attribute = $this->config->getAttribute('device_type');

0 commit comments

Comments
 (0)