Skip to content

[FSSDK-9022] Dev Containers and bug bash #269

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 44 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
38f9db1
Add bug bash autoloader
mikechu-optimizely May 30, 2023
91aa14c
Initial version of decide tests
mikechu-optimizely May 30, 2023
0051573
Fix autoloads; DRY print to console
mikechu-optimizely May 30, 2023
c31820a
Refactor and clean using
mikechu-optimizely May 30, 2023
833e6bb
Refactor; Fix array outputs
mikechu-optimizely May 31, 2023
785389f
Better output in linux env
mikechu-optimizely May 31, 2023
47fcac7
Add notification on decide test
mikechu-optimizely May 31, 2023
e7c18c7
Output log to ensure logx impression sent
mikechu-optimizely May 31, 2023
610279a
Verify error is logged for invalid flag
mikechu-optimizely May 31, 2023
2d1b5a1
Add devcontainer config
mikechu-optimizely Jun 1, 2023
af21844
Install dependencies in devcontainer
mikechu-optimizely Jun 1, 2023
1567ac2
Update decide instructions
mikechu-optimizely Jun 1, 2023
12a9b70
Add postCreateCommand shell postCreateCommand
mikechu-optimizely Jun 1, 2023
e59ed4b
Fix path on postCreateCommand
mikechu-optimizely Jun 1, 2023
a15ce19
Finish devcontainer config
mikechu-optimizely Jun 1, 2023
3a13a5e
Refine decide.php
mikechu-optimizely Jun 1, 2023
82faf92
Renamed files & their refs
mikechu-optimizely Jun 2, 2023
e05a86f
Instruction update
mikechu-optimizely Jun 2, 2023
00a2522
Add DecideAll skeleton
mikechu-optimizely Jun 2, 2023
cc16486
Initial DecideAll test
mikechu-optimizely Jun 2, 2023
8453c4a
Finish DecideAll test; Decide fixes
mikechu-optimizely Jun 2, 2023
8774b37
DecideForKeys skeleton
mikechu-optimizely Jun 2, 2023
626c7d4
Add decide for keys; update other decide classes
mikechu-optimizely Jun 5, 2023
96bb0c0
Comment DecideForKeys test calls
mikechu-optimizely Jun 5, 2023
fcb1ee4
Track event test class skeleton
mikechu-optimizely Jun 5, 2023
aabd432
Update attributes in decide tests
mikechu-optimizely Jun 5, 2023
5378d93
Add track event tests
mikechu-optimizely Jun 5, 2023
165c566
DRY $onTrackEvent and use in negative test
mikechu-optimizely Jun 5, 2023
bb0eeaf
Event Key instead of "name"
mikechu-optimizely Jun 5, 2023
b29dead
Forced Decision skeleton
mikechu-optimizely Jun 5, 2023
e7781de
Add PHP documentation links
mikechu-optimizely Jun 5, 2023
035747e
Initial attempt forced decision tests
mikechu-optimizely Jun 5, 2023
01af3ee
Remove sensitive info
mikechu-optimizely Jun 5, 2023
94d211e
Added second part for forced decisions - not necessary, just a advanc…
Mat001 Jun 6, 2023
353aa31
Delete ForcedDecision.php
Mat001 Jun 9, 2023
155dc12
Rename ForcedDecisionPart2.php to ForcedDecision.php
Mat001 Jun 9, 2023
df5089b
Update ForcedDecision.php
Mat001 Jun 9, 2023
79c7e7b
Update OptiConfig.php
Mat001 Jun 9, 2023
aab2a60
Update EventBuilder.php SDK minor release bump
Mat001 Jun 9, 2023
ead6580
Update EventBuilderTest.php release version bump in the test to 3.10.0
Mat001 Jun 9, 2023
4eae743
Update EventBuilder.php-revert
Mat001 Jun 9, 2023
d714b04
Update EventBuilderTest.php - revert
Mat001 Jun 9, 2023
52808f8
Merge branch 'master' into mike/bug-bash-php8
mikechu-optimizely Jun 22, 2023
3810ed3
Merge remote-tracking branch 'origin/mike/bug-bash-php8' into mike/bu…
mikechu-optimizely Jun 22, 2023
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
Prev Previous commit
Next Next commit
Add decide for keys; update other decide classes
  • Loading branch information
mikechu-optimizely committed Jun 5, 2023
commit 626c7d4a6f3bad28a45626657810c695e3a37907
9 changes: 5 additions & 4 deletions bug-bash/Decide.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testWithVariationsOfDecideOptions(): void
// verify in logs that impression event of this decision was dispatched
public function verifyLogsImpressionsEventsDispatched(): void
{
// Create a new flag with an A/B Test eg "product_version"
// 💡️ Create a new flag with an A/B Test eg "product_version"
$featureFlagKey = 'product_version';
$logger = new DefaultLogger(Logger::DEBUG);
$localOptimizelyClient = new Optimizely(datafile: null, logger: $logger, sdkKey: SDK_KEY);
Expand All @@ -79,15 +79,15 @@ public function verifyLogsImpressionsEventsDispatched(): void
// verify on Results page that impression even was created
public function verifyResultsPageInYourProjectShowsImpressionEvent(): void
{
print "Go to your project's results page and verify decisions events are showing (might be a 5 min delay)";
print "Go to your project's results page and verify decisions events are showing (5 min delay)";
}

// verify that decision listener contains correct information
public function verifyDecisionListenerWasCalled(): void
{
// Check that this was called during the...
$onDecision = function ($type, $userId, $attributes, $decisionInfo) {
print ">>> [NotificationCenter] OnDecision:
print ">>> [$this->outputTag] OnDecision:
type: $type,
userId: $userId,
attributes: " . print_r($attributes, true) . "
Expand Down Expand Up @@ -117,6 +117,7 @@ public function verifyAnInvalidFlagKeyIsHandledCorrectly(): void
private Optimizely $optimizelyClient;
private string $userId;
private ?OptimizelyUserContext $userContext;
private string $outputTag = "Decide";

public function __construct()
{
Expand All @@ -131,7 +132,7 @@ private function printDecision($decision, $message): void
{
$enabled = $decision->getEnabled() ? "true" : "false";

print ">>> [Decision] $message:
print ">>> [$this->outputTag] $message:
enabled: $enabled,
flagKey: {$decision->getFlagKey()},
ruleKey: {$decision->getRuleKey()},
Expand Down
9 changes: 5 additions & 4 deletions bug-bash/DecideAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public function testWithVariousCombinationsOfOptions(): void
// verify in logs that impression event of this decision was dispatched
public function verifyLogImpressionEventDispatched(): void
{
// *** Be sure you have >=1 of your project's flags has an EXPERIMENT type
// 💡️ Be sure you have >=1 of your project's flags has an EXPERIMENT type
$logger = new DefaultLogger(Logger::DEBUG);
$localOptimizelyClient = new Optimizely(datafile: null, logger: $logger, sdkKey: SDK_KEY);
$localUserContext = $localOptimizelyClient->createUserContext($this->userId);

// review the DEBUG output, ensuring you see an impression log for each *EXPERIMENT* with a message like
// "Dispatching impression event to URL https://logx.optimizely.com/v1/events with params..."
// Rollout flag types will not dispatch and impression event
// ⚠️ Rollout flag types should not dispatch and impression event
$localUserContext->decideAll();
}

Expand All @@ -85,7 +85,7 @@ public function verifyDecisionListenerContainsCorrectInformation(): void
{
// Check that this was called for each of your project flag keys
$onDecision = function ($type, $userId, $attributes, $decisionInfo) {
print ">>> [NotificationCenter] OnDecision:
print ">>> [$this->outputTag] OnDecision:
type: $type,
userId: $userId,
attributes: " . print_r($attributes, true) . "
Expand All @@ -102,6 +102,7 @@ public function verifyDecisionListenerContainsCorrectInformation(): void
private Optimizely $optimizelyClient;
private string $userId;
private ?OptimizelyUserContext $userContext;
private string $outputTag = "Decide All";

public function __construct()
{
Expand All @@ -118,7 +119,7 @@ private function printDecisions($decisions, $message): void
foreach ($decisions as $decision) {
$enabled = $decision->getEnabled() ? "true" : "false";

print ">>> [Decision #$count] $message:
print ">>> [$this->outputTag #$count] $message:
enabled: $enabled,
flagKey: {$decision->getFlagKey()},
ruleKey: {$decision->getRuleKey()},
Expand Down
88 changes: 85 additions & 3 deletions bug-bash/DecideForKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
const SDK_KEY = 'K4UmaV5Pk7cEh2hbcjgwe';

// 2. Check that you have 3+ flag keys in your project and add them here
const FLAG_KEYS = ['product_sort', 'marketing_banner'];
const FLAG_KEYS = ['product_sort', 'marketing_banner', 'product_version'];

// 3. Uncomment each scenario 1 by 1 modifying the contents of the method
// to test additional scenarios.

$test = new DecideForKeysTests();

$test->verifyDecisionProperties();
$test->testWithVariationsOfDecideOptions();
$test->verifyLogsImpressionsEventsDispatched();
$test->verifyResultsPageInYourProjectShowsImpressionEvent();
$test->verifyDecisionListenerWasCalled();
$test->verifyAnInvalidFlagKeyIsHandledCorrectly();

// 4. Change the current folder into the bug-bash directory if you've not already
// cd bug-bash/
Expand All @@ -34,9 +39,86 @@
class DecideForKeysTests
{

// verify decision return properties with default DecideOptions
public function verifyDecisionProperties(): void
{
$decision = $this->userContext->decideForKeys(FLAG_KEYS);

$this->printDecisions($decision, "Check that the following decisions' properties are expected");
}

// test decide w all options: DISABLE_DECISION_EVENT, ENABLED_FLAGS_ONLY, IGNORE_USER_PROFILE_SERVICE, INCLUDE_REASONS, EXCLUDE_VARIABLES (will need to add variables)
public function testWithVariationsOfDecideOptions(): void
{
$options = [
OptimizelyDecideOption::INCLUDE_REASONS,
// OptimizelyDecideOption::DISABLE_DECISION_EVENT,
// OptimizelyDecideOption::ENABLED_FLAGS_ONLY, // ⬅️ Disable some of your flags
// OptimizelyDecideOption::IGNORE_USER_PROFILE_SERVICE,
// OptimizelyDecideOption::EXCLUDE_VARIABLES,
];

$decision = $this->userContext->decideForKeys(FLAG_KEYS, $options);

$this->printDecisions($decision, "Modify the OptimizelyDecideOptions and check all the decisions' are as expected");
}

// verify in logs that impression event of this decision was dispatched
public function verifyLogsImpressionsEventsDispatched(): void
{
// 💡️ Be sure that your FLAG_KEYS array above includes A/B Test eg "product_version"
$logger = new DefaultLogger(Logger::DEBUG);
$localOptimizelyClient = new Optimizely(datafile: null, logger: $logger, sdkKey: SDK_KEY);
$localUserContext = $localOptimizelyClient->createUserContext($this->userId);

// review the DEBUG output, ensuring you see an impression log for each experiment type in your FLAG_KEYS
// "Dispatching impression event to URL https://logx.optimizely.com/v1/events with params..."
// ⚠️ Your Rollout type flags should not have impression events
$localUserContext->decideForKeys(FLAG_KEYS);
}

// verify on Results page that impression even was created
public function verifyResultsPageInYourProjectShowsImpressionEvent(): void
{
print "Go to your project's results page and verify decisions events are showing (5 min delay)";
}

// verify that decision listener contains correct information
public function verifyDecisionListenerWasCalled(): void
{
// Check that this was called during the...
$onDecision = function ($type, $userId, $attributes, $decisionInfo) {
print ">>> [$this->outputTag] OnDecision:
type: $type,
userId: $userId,
attributes: " . print_r($attributes, true) . "
decisionInfo: " . print_r($decisionInfo, true) . "\r\n";
};
$this->optimizelyClient->notificationCenter->addNotificationListener(
NotificationType::DECISION,
$onDecision
);

// ...decide.
$this->userContext->decide(FLAG_KEY);
}

// verify that invalid flag key is handled correctly
public function verifyAnInvalidFlagKeyIsHandledCorrectly(): void
{
$logger = new DefaultLogger(Logger::ERROR);
$localOptimizelyClient = new Optimizely(datafile: null, logger: $logger, sdkKey: SDK_KEY);
$userId = 'user-' . mt_rand(10, 99);
$localUserContext = $localOptimizelyClient->createUserContext($userId);

// ensure you see an error -- Optimizely.ERROR: FeatureFlag Key "a_key_not_in_the_project" is not in datafile.
$localUserContext->decide("a_key_not_in_the_project");
}

private Optimizely $optimizelyClient;
private string $userId;
private ?OptimizelyUserContext $userContext;
private string $outputTag = "Decide For Keys";

public function __construct()
{
Expand All @@ -53,7 +135,7 @@ private function printDecisions($decisions, $message): void
foreach ($decisions as $decision) {
$enabled = $decision->getEnabled() ? "true" : "false";

print ">>> [Decision #$count] $message:
print ">>> [$this->outputTag #$count] $message:
enabled: $enabled,
flagKey: {$decision->getFlagKey()},
ruleKey: {$decision->getRuleKey()},
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy