diff --git a/CHANGELOG.md b/CHANGELOG.md index aa44b9a..c96a1c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,15 +63,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Redesigned models to use private properties instead of public properties. - Implemented object notation with getter and setter functions for all models. -<<<<<<< HEAD - **Unit and E2E Testing** -======= -- **Unit and E2E Testing** ->>>>>>> origin/feat/personalize-meg - - Set up Test framework using `Jest` - Wrote unit and E2E tests to ensure nothing breaks while pushing new code - - Ensure criticla components are working properly on every build + - Ensure critical components are working properly on every build [1.0.0] - 2024-06-11 diff --git a/src/Api/GetFlag.php b/src/Api/GetFlag.php index c34068c..9acac33 100644 --- a/src/Api/GetFlag.php +++ b/src/Api/GetFlag.php @@ -138,7 +138,7 @@ public function get( // Evaluate Rollout Rules $rollOutRules = FunctionUtil::getSpecificRulesBasedOnType($feature, CampaignTypeEnum::ROLLOUT); if (count($rollOutRules) > 0 && !$isEnabled) { - $megGroupWinnerCampaigns = []; + $megGroupWinnerCampaigns = []; foreach ($rollOutRules as $rule) { $evaluateRuleResult = $ruleEvaluationUtil->evaluateRule( $settings, @@ -157,7 +157,10 @@ public function get( 'rolloutKey' => $rule->getKey(), 'rolloutVariationId' => $rule->getVariations()[0]->getId() ]; + $ruleStatus[$rule->getRuleKey()] = "Passed"; break; + } else { + $ruleStatus[$rule->getRuleKey()] = "Failed"; } } @@ -191,7 +194,7 @@ public function get( $experimentRules = FunctionUtil::getAllExperimentRules($feature); $experimentRulesToEvaluate = []; - $megGroupWinnerCampaigns = []; + $megGroupWinnerCampaigns = []; foreach ($experimentRules as $rule) { $evaluateRuleResult = $ruleEvaluationUtil->evaluateRule( $settings, @@ -217,7 +220,10 @@ public function get( 'experimentVariationId' => $evaluateRuleResult['whitelistedObject']['variationId'], ]); } + $ruleStatus[$rule->getRuleKey()] = "Passed"; break; + } else { + $ruleStatus[$rule->getRuleKey()] = "Failed"; } } diff --git a/src/Api/TrackEvent.php b/src/Api/TrackEvent.php index d56a854..5ab4dfd 100644 --- a/src/Api/TrackEvent.php +++ b/src/Api/TrackEvent.php @@ -103,4 +103,4 @@ private function createImpressionForTrack(SettingsModel $settings, string $event $networkUtil->sendPostApiRequest($properties, $payload); } } -?> \ No newline at end of file +?> diff --git a/src/Packages/SegmentationEvaluator/Evaluators/SegmentEvaluator.php b/src/Packages/SegmentationEvaluator/Evaluators/SegmentEvaluator.php index 08b739e..36684c2 100644 --- a/src/Packages/SegmentationEvaluator/Evaluators/SegmentEvaluator.php +++ b/src/Packages/SegmentationEvaluator/Evaluators/SegmentEvaluator.php @@ -89,10 +89,10 @@ public function some($dslNodes, $customVariables): bool if ($key === SegmentOperatorValueEnum::FEATURE_ID) { $featureIdObject = $dsl->$key; - + $featureIdKey = array_key_first(get_object_vars($featureIdObject)); $featureIdValue = $featureIdObject->$featureIdKey; - + if (in_array($featureIdValue, ['on', 'off'])) { $features = $this->settings->getFeatures(); $feature = null; @@ -138,19 +138,19 @@ public function every($dslNodes, $customVariables): bool $locationMap = []; foreach ($dslNodes as $dsl) { if (isset($dsl->{SegmentOperatorValueEnum::COUNTRY}) || isset($dsl->{SegmentOperatorValueEnum::REGION}) || isset($dsl->{SegmentOperatorValueEnum::CITY})) { - $this->addLocationValuesToMap($dsl, $locationMap); + $this->addLocationValuesToMap($dsl, $locationMap); if (count($locationMap) === count($dslNodes)) { return $this->checkLocationPreSegmentation($locationMap); } continue; - } + } if (!$this->isSegmentationValid($dsl, $customVariables)) { return false; } - } + } return true; } - + public function addLocationValuesToMap($dsl, &$locationMap): void { if (isset($dsl->{SegmentOperatorValueEnum::COUNTRY})) { @@ -162,12 +162,12 @@ public function addLocationValuesToMap($dsl, &$locationMap): void if (isset($dsl->{SegmentOperatorValueEnum::CITY})) { $locationMap[SegmentOperatorValueEnum::CITY] = $dsl->{SegmentOperatorValueEnum::CITY}; } - } + } public function checkLocationPreSegmentation($locationMap): bool { $ipAddress = $this->context->getIpAddress(); // Use the getter method - + if (empty($ipAddress)) { LogManager::instance()->info('To evaluate location pre-segmentation, please pass ipAddress in the context object'); return false; @@ -176,19 +176,19 @@ public function checkLocationPreSegmentation($locationMap): bool if (empty($this->context->getVwo()) || empty($this->context->getVwo()->getLocation())) { return false; } - + return $this->valuesMatch($locationMap, $this->context->getVwo()->getLocation()); } - + public function checkUserAgentParser($uaParserMap): bool { $userAgent = $this->context->getUserAgent(); // Use the getter method - + if (empty($userAgent)) { LogManager::instance()->info('To evaluate user agent related segments, please pass userAgent in the context object'); return false; - } - + } + if (empty($this->context->getVwo()) || empty($this->context->getVwo()->getUaInfo())) { return false; } @@ -280,4 +280,4 @@ interface Segmentation { public function isSegmentationValid($dsl, $properties); } -?> \ No newline at end of file +?> diff --git a/src/Packages/SegmentationEvaluator/Evaluators/SegmentOperandEvaluator.php b/src/Packages/SegmentationEvaluator/Evaluators/SegmentOperandEvaluator.php index 6c461af..e5121cd 100644 --- a/src/Packages/SegmentationEvaluator/Evaluators/SegmentOperandEvaluator.php +++ b/src/Packages/SegmentationEvaluator/Evaluators/SegmentOperandEvaluator.php @@ -253,4 +253,4 @@ private function isValidNumericComparison($operandValue, $tagValue, callable $co } } -?> \ No newline at end of file +?> diff --git a/src/Utils/VWOGatewayServiceUtil.php b/src/Utils/VWOGatewayServiceUtil.php new file mode 100644 index 0000000..2b57cc0 --- /dev/null +++ b/src/Utils/VWOGatewayServiceUtil.php @@ -0,0 +1,75 @@ +info('Invalid URL. Please provide a valid URL for vwo helper VWOGatewayService'); + return false; + } + + try { + $request = new RequestModel( + UrlService::getBaseUrl(), + 'GET', + $endpoint, + $queryParams, + null, + null, + UrlService::getProtocol(), + UrlService::getPort() + ); + + $response = $networkInstance->get($request); + + if ($response instanceof ResponseModel) { + return $response->getData(); + } else { + LogManager::instance()->error('Failed to get a valid response from the network request.'); + return false; + } + } catch (\Exception $err) { + LogManager::instance()->error('Error occurred while sending GET request: ' . $err->getMessage()); + return false; + } + } + + public static function getQueryParamForLocationPreSegment($ipAddress) { + return [ + 'ipAddress' => $ipAddress + ]; + } + + public static function getQueryParamForUaParser($userAgent) { + return [ + 'userAgent' => urlencode($userAgent) + ]; + } +} diff --git a/src/VWO.php b/src/VWO.php index 3dc141d..021cacb 100644 --- a/src/VWO.php +++ b/src/VWO.php @@ -70,7 +70,6 @@ private static function setInstance($options) // Fetch settings and build VWO instance $settings = self::$vwoBuilder->getSettings(); } - if ($settings) { self::$instance = self::$vwoBuilder->build($settings); } @@ -113,7 +112,7 @@ public static function init($options = []) $instance = new VWO($options); return self::$instance; - } catch (\Throwable $error) { + } catch (\Throwable $error) { $msg = sprintf('API - %s failed to execute. Trace: %s. ', $apiName, $error->getMessage()); $logMessage = sprintf('[ERROR]: VWO-SDK %s %s', (new \DateTime())->format(DATE_ISO8601), $msg); file_put_contents("php://stdout", $logMessage . PHP_EOL);