From 53e1abe3f619fde26bf9489742ce3460fd54a957 Mon Sep 17 00:00:00 2001 From: Heihokon Date: Mon, 29 Jan 2024 14:58:39 -0600 Subject: [PATCH 1/9] update ANALYTIC_HIT_ALLOCATION --- src/Enum/FlagshipConstant.php | 2 +- src/Visitor/VisitorStrategyAbstract.php | 6 ++++-- tests/Visitor/DefaultStrategyTest.php | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Enum/FlagshipConstant.php b/src/Enum/FlagshipConstant.php index 08a7ce97..df0c883c 100644 --- a/src/Enum/FlagshipConstant.php +++ b/src/Enum/FlagshipConstant.php @@ -205,5 +205,5 @@ class FlagshipConstant const LOG_FORMAT_RESPONSE_STATUS = 'RESPONSE_STATUS'; const LOG_FORMAT_DURATION = 'DURATION'; - const ANALYTIC_HIT_ALLOCATION = 20; + const ANALYTIC_HIT_ALLOCATION = 1; } diff --git a/src/Visitor/VisitorStrategyAbstract.php b/src/Visitor/VisitorStrategyAbstract.php index 04fc17c3..c4e19f40 100644 --- a/src/Visitor/VisitorStrategyAbstract.php +++ b/src/Visitor/VisitorStrategyAbstract.php @@ -365,10 +365,12 @@ public function sendSdkConfigAnalyticHit() } $uniqueId = $this->getVisitor()->getVisitorId() . $this->getCurrentDateTime()->format("Y-m-d"); $hash = $this->getMurmurHash()->murmurHash3Int32($uniqueId); - $traffic = $hash % 100; - if ($traffic >= FlagshipConstant::ANALYTIC_HIT_ALLOCATION) { + $traffic = $hash % 1000; + + if ($traffic > FlagshipConstant::ANALYTIC_HIT_ALLOCATION) { return; } + $visitor = $this->getVisitor(); $config = $this->getConfig(); $bucketingUrl = null; diff --git a/tests/Visitor/DefaultStrategyTest.php b/tests/Visitor/DefaultStrategyTest.php index 01759f24..82b5f0b8 100644 --- a/tests/Visitor/DefaultStrategyTest.php +++ b/tests/Visitor/DefaultStrategyTest.php @@ -2162,7 +2162,8 @@ public function testSendAnalyticsHit() $configManager->setDecisionManager($decisionManager) ->setTrackingManager($trackingManagerMock); - $visitor = new VisitorDelegate(new Container(), $configManager, "visitorId", false, [], true); + $visitor = new VisitorDelegate(new Container(), $configManager, + "b8808e0a-d268-4d53-bf17-d88bbaac9638", false, [], true); $analytic = new UsageHit(); $analytic->setLabel(TroubleshootingLabel::SDK_CONFIG) @@ -2179,14 +2180,13 @@ public function testSendAnalyticsHit() ->setSdkStatus($visitor->getSdkStatus()) ->setFlagshipInstanceId($flagshipInstanceId); - $uniqueId = $visitor->getVisitorId() . (new DateTime())->format("Y-m-d"); - + $uniqueId = $visitor->getVisitorId() . "2024-01-29"; $trackingManagerMock->expects($this->once())->method("addUsageHit")->with($analytic); $murmurHashMock->expects($this->exactly(2)) ->method('murmurHash3Int32')->with($uniqueId) - ->willReturnOnConsecutiveCalls(100, 50); + ->willReturnOnConsecutiveCalls(10, 0); $defaultStrategy = new DefaultStrategy($visitor); $defaultStrategy->setFlagshipInstanceId($flagshipInstanceId); From 9cbe37dd945247dd43b02ab2b539210dd8d7c9b0 Mon Sep 17 00:00:00 2001 From: Heihokon Date: Fri, 2 Feb 2024 17:13:25 -0600 Subject: [PATCH 2/9] fix troubleshooting logLevel issue --- src/Hit/Diagnostic.php | 29 ++++++++++++++++++++++++- src/Visitor/VisitorStrategyAbstract.php | 2 ++ tests/Hit/TroubleshootingTest.php | 2 ++ tests/Visitor/DefaultStrategyTest.php | 20 +++++++++++------ 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/Hit/Diagnostic.php b/src/Hit/Diagnostic.php index a851d0f0..edc8b487 100644 --- a/src/Hit/Diagnostic.php +++ b/src/Hit/Diagnostic.php @@ -73,6 +73,11 @@ class Diagnostic extends HitAbstract */ private $sdkConfigMode; + /** + * @var numeric + */ + private $sdkConfigLogLeve; + /** * @var bool */ @@ -288,7 +293,6 @@ class Diagnostic extends HitAbstract private $flagshipInstanceId; - public function __construct($type) { parent::__construct($type); @@ -1293,6 +1297,26 @@ public function setHitContent($hitContent) return $this; } + /** + * @return float|int|string + */ + public function getSdkConfigLogLeve() + { + return $this->sdkConfigLogLeve; + } + + /** + * @param float|int|string $sdkConfigLogLeve + * @return Diagnostic + */ + public function setSdkConfigLogLeve($sdkConfigLogLeve) + { + $this->sdkConfigLogLeve = $sdkConfigLogLeve; + return $this; + } + + + public function toApiKeys() { $customVariable = [ @@ -1330,6 +1354,9 @@ public function toApiKeys() if ($this->getSdkStatus() !== null) { $customVariable["sdk.status"] = FlagshipStatus::getStatusName($this->getSdkStatus()); } + if ($this->getSdkConfigLogLeve() !== null) { + $customVariable["sdk.config.logLevel"] = LogLevel::getLogName($this->getSdkConfigLogLeve()); + } if ($this->getSdkConfigMode() !== null) { $customVariable["sdk.config.mode"] = DecisionMode::getDecisionModeName($this->getSdkConfigMode()); } diff --git a/src/Visitor/VisitorStrategyAbstract.php b/src/Visitor/VisitorStrategyAbstract.php index c4e19f40..a4caea01 100644 --- a/src/Visitor/VisitorStrategyAbstract.php +++ b/src/Visitor/VisitorStrategyAbstract.php @@ -384,6 +384,7 @@ public function sendSdkConfigAnalyticHit() ->setLogLevel(LogLevel::INFO) ->setVisitorId($this->getFlagshipInstanceId()) ->setSdkConfigMode($config->getDecisionMode()) + ->setSdkConfigLogLeve($config->getLogLevel()) ->setSdkConfigTimeout($config->getTimeout()) ->setSdkConfigTrackingManagerConfigStrategy($config->getCacheStrategy()) ->setSdkConfigBucketingUrl($bucketingUrl) @@ -446,6 +447,7 @@ public function sendFetchFlagsTroubleshooting($troubleshootingData, $flagsDTO, $ ->setVisitorIsAuthenticated(!!$visitor->getAnonymousId()) ->setHttpResponseTime(($this->getNow() - $now)) ->setSdkConfigMode($config->getDecisionMode()) + ->setSdkConfigLogLeve($config->getLogLevel()) ->setSdkConfigTimeout($config->getTimeout()) ->setSdkConfigBucketingUrl($bucketingUrl) ->setSdkConfigFetchThirdPartyData($fetchThirdPartyData) diff --git a/tests/Hit/TroubleshootingTest.php b/tests/Hit/TroubleshootingTest.php index 3c0ef044..a1352ec6 100644 --- a/tests/Hit/TroubleshootingTest.php +++ b/tests/Hit/TroubleshootingTest.php @@ -104,6 +104,7 @@ public function testConstruct() ->setStackOriginVersion($stackOriginVersion) ->setSdkStatus($sdkStatus) ->setSdkConfigMode($sdkConfigMode) + ->setSdkConfigLogLeve($config->getLogLevel()) ->setSdkConfigCustomLogManager(true) ->setSdkConfigCustomCacheManager(true) ->setSdkConfigStatusListener(false) @@ -162,6 +163,7 @@ public function testConstruct() 'stack.origin.name' => $stackOriginName, 'stack.origin.version' => $stackOriginVersion, 'sdk.status' => FlagshipStatus::getStatusName($sdkStatus), + 'sdk.config.logLevel' => LogLevel::getLogName($config->getLogLevel()), 'sdk.config.mode' => DecisionMode::getDecisionModeName($sdkConfigMode), 'sdk.config.customLogManager' => 'true', 'sdk.config.customCacheManager' => 'true', diff --git a/tests/Visitor/DefaultStrategyTest.php b/tests/Visitor/DefaultStrategyTest.php index 82b5f0b8..36488c6b 100644 --- a/tests/Visitor/DefaultStrategyTest.php +++ b/tests/Visitor/DefaultStrategyTest.php @@ -714,8 +714,8 @@ public function testFetchFlagsTroubleshootingData() $matcher = $this->exactly(4); $trackingManagerMock->expects($matcher) - ->method("addTroubleshootingHit")->with($this->callback(function ($param) use($matcher) { - switch ($matcher->getInvocationCount()){ + ->method("addTroubleshootingHit")->with($this->callback(function ($param) use ($matcher) { + switch ($matcher->getInvocationCount()) { case 1: case 3: { @@ -2126,7 +2126,7 @@ public function testFetchVisitorCampaigns() public function testSendAnalyticsHit() { $bucketingUrl = "https://terst.com"; - $config = new BucketingConfig($bucketingUrl,'envId', 'apiKey'); + $config = new BucketingConfig($bucketingUrl, 'envId', 'apiKey'); $visitorId = "visitorId"; $httpClientMock = $this->getMockForAbstractClass( @@ -2162,13 +2162,20 @@ public function testSendAnalyticsHit() $configManager->setDecisionManager($decisionManager) ->setTrackingManager($trackingManagerMock); - $visitor = new VisitorDelegate(new Container(), $configManager, - "b8808e0a-d268-4d53-bf17-d88bbaac9638", false, [], true); + $visitor = new VisitorDelegate( + new Container(), + $configManager, + "b8808e0a-d268-4d53-bf17-d88bbaac9638", + false, + [], + true + ); $analytic = new UsageHit(); $analytic->setLabel(TroubleshootingLabel::SDK_CONFIG) ->setLogLevel(LogLevel::INFO) ->setVisitorId($flagshipInstanceId) + ->setSdkConfigLogLeve($config->getLogLevel()) ->setSdkConfigMode($config->getDecisionMode()) ->setSdkConfigTimeout($config->getTimeout()) ->setSdkConfigTrackingManagerConfigStrategy($config->getCacheStrategy()) @@ -2185,7 +2192,7 @@ public function testSendAnalyticsHit() $trackingManagerMock->expects($this->once())->method("addUsageHit")->with($analytic); $murmurHashMock->expects($this->exactly(2)) - ->method('murmurHash3Int32')->with($uniqueId) + ->method('murmurHash3Int32') ->willReturnOnConsecutiveCalls(10, 0); $defaultStrategy = new DefaultStrategy($visitor); @@ -2199,6 +2206,5 @@ public function testSendAnalyticsHit() $config->setDisableDeveloperUsageTracking(true); $defaultStrategy->sendSdkConfigAnalyticHit(); - } } From 45745367c578c3f19a96de0021364b3f996d61e3 Mon Sep 17 00:00:00 2001 From: Heihokon Date: Tue, 6 Feb 2024 11:54:46 -0600 Subject: [PATCH 3/9] fix Troubleshooting label issue --- src/Api/BatchingCachingStrategyAbstract.php | 5 +-- .../NoBatchingContinuousCachingStrategy.php | 35 +++++++++++++++++++ src/Decision/ApiManager.php | 3 +- src/Decision/BucketingManager.php | 2 +- src/Enum/TroubleshootingLabel.php | 1 + ...oBatchingContinuousCachingStrategyTest.php | 10 ++++-- 6 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/Api/BatchingCachingStrategyAbstract.php b/src/Api/BatchingCachingStrategyAbstract.php index 73cb9f1c..56ed3331 100644 --- a/src/Api/BatchingCachingStrategyAbstract.php +++ b/src/Api/BatchingCachingStrategyAbstract.php @@ -6,6 +6,7 @@ use Flagship\Config\FlagshipConfig; use Flagship\Enum\FlagshipConstant; use Flagship\Enum\HitCacheFields; +use Flagship\Enum\LogLevel; use Flagship\Enum\TroubleshootingLabel; use Flagship\Hit\Activate; use Flagship\Hit\ActivateBatch; @@ -341,7 +342,7 @@ protected function sendActivateHit() $this->cacheHit($this->activatePoolQueue); $troubleshooting = new Troubleshooting(); $troubleshooting->setLabel(TroubleshootingLabel::SEND_ACTIVATE_HIT_ROUTE_ERROR) - ->setLogLevel("ERROR") + ->setLogLevel(LogLevel::ERROR) ->setVisitorId($this->flagshipInstanceId) ->setFlagshipInstanceId($this->flagshipInstanceId) ->setTraffic(100) @@ -468,7 +469,7 @@ public function sendBatch() $this->cacheHit($this->hitsPoolQueue); $troubleshooting = new Troubleshooting(); $troubleshooting->setLabel(TroubleshootingLabel::SEND_BATCH_HIT_ROUTE_RESPONSE_ERROR) - ->setLogLevel("ERROR") + ->setLogLevel(LogLevel::ERROR) ->setVisitorId($this->flagshipInstanceId) ->setFlagshipInstanceId($this->flagshipInstanceId) ->setTraffic(100) diff --git a/src/Api/NoBatchingContinuousCachingStrategy.php b/src/Api/NoBatchingContinuousCachingStrategy.php index f15f8d84..aa37ff52 100644 --- a/src/Api/NoBatchingContinuousCachingStrategy.php +++ b/src/Api/NoBatchingContinuousCachingStrategy.php @@ -3,6 +3,8 @@ namespace Flagship\Api; use Flagship\Enum\FlagshipConstant; +use Flagship\Enum\LogLevel; +use Flagship\Enum\TroubleshootingLabel; use Flagship\Hit\Activate; use Flagship\Hit\ActivateBatch; use Flagship\Hit\UsageHit; @@ -77,6 +79,22 @@ protected function sendHit(HitAbstract $hit) [FlagshipConstant::SEND_HIT, $this->getLogFormat($exception->getMessage(), $url, $requestBody, $header, $this->getNow() - $now)] ); + $troubleshooting = new Troubleshooting(); + $troubleshooting->setLabel(TroubleshootingLabel::SEND_HIT_ROUTE_ERROR) + ->setLogLevel(LogLevel::ERROR) + ->setVisitorId($this->flagshipInstanceId) + ->setFlagshipInstanceId($this->flagshipInstanceId) + ->setTraffic(100) + ->setConfig($this->config) + ->setHttpRequestBody($requestBody) + ->setHttpRequestHeaders($header) + ->setHttpRequestMethod("POST") + ->setHttpRequestUrl($url) + ->setHttpResponseBody($exception->getMessage()) + ->setHttpResponseTime($this->getNow() - $now) + ; + $this->addTroubleshootingHit($troubleshooting); + $this->sendTroubleshootingQueue(); } } @@ -119,6 +137,23 @@ public function activateFlag(Activate $hit) [FlagshipConstant::SEND_ACTIVATE, $this->getLogFormat($exception->getMessage(), $url, $requestBody, $headers, $this->getNow() - $now)] ); + + $troubleshooting = new Troubleshooting(); + $troubleshooting->setLabel(TroubleshootingLabel::SEND_ACTIVATE_HIT_ROUTE_ERROR) + ->setLogLevel(LogLevel::ERROR) + ->setVisitorId($this->flagshipInstanceId) + ->setFlagshipInstanceId($this->flagshipInstanceId) + ->setTraffic(100) + ->setConfig($this->config) + ->setHttpRequestBody($requestBody) + ->setHttpRequestHeaders($headers) + ->setHttpRequestMethod("POST") + ->setHttpRequestUrl($url) + ->setHttpResponseBody($exception->getMessage()) + ->setHttpResponseTime($this->getNow() - $now) + ; + $this->addTroubleshootingHit($troubleshooting); + $this->sendTroubleshootingQueue(); } } diff --git a/src/Decision/ApiManager.php b/src/Decision/ApiManager.php index 7bef4749..5afc09d4 100644 --- a/src/Decision/ApiManager.php +++ b/src/Decision/ApiManager.php @@ -6,6 +6,7 @@ use Exception; use Flagship\Enum\FlagshipConstant; use Flagship\Enum\FlagshipField; +use Flagship\Enum\LogLevel; use Flagship\Enum\TroubleshootingLabel; use Flagship\Hit\Troubleshooting; use Flagship\Model\TroubleshootingData; @@ -74,7 +75,7 @@ public function getCampaigns(VisitorAbstract $visitor) $troubleshooting = new Troubleshooting(); $troubleshooting->setLabel(TroubleshootingLabel::GET_CAMPAIGNS_ROUTE_RESPONSE_ERROR) - ->setLogLevel("ERROR") + ->setLogLevel(LogLevel::ERROR) ->setVisitorId($visitor->getVisitorId()) ->setAnonymousId($visitor->getAnonymousId()) ->setVisitorContext($visitor->getContext()) diff --git a/src/Decision/BucketingManager.php b/src/Decision/BucketingManager.php index 27c275fd..d41f9566 100644 --- a/src/Decision/BucketingManager.php +++ b/src/Decision/BucketingManager.php @@ -171,7 +171,7 @@ protected function getBucketingFile() $troubleshooting->setLabel(TroubleshootingLabel::SDK_BUCKETING_FILE_ERROR) ->setFlagshipInstanceId($this->getFlagshipInstanceId()) ->setTraffic(0) - ->setLogLevel("ERROR") + ->setLogLevel(LogLevel::ERROR) ->setConfig($this->getConfig()) ->setHttpRequestMethod("GET") ->setHttpRequestUrl($url) diff --git a/src/Enum/TroubleshootingLabel.php b/src/Enum/TroubleshootingLabel.php index bcba9629..dc359a5e 100644 --- a/src/Enum/TroubleshootingLabel.php +++ b/src/Enum/TroubleshootingLabel.php @@ -22,4 +22,5 @@ class TroubleshootingLabel const SDK_BUCKETING_FILE_ERROR= "SDK_BUCKETING_FILE_ERROR"; const SDK_BUCKETING_FILE = "SDK_BUCKETING_FILE"; const SDK_CONFIG = "SDK_CONFIG"; + const SEND_HIT_ROUTE_ERROR = 'SEND_HIT_ROUTE_ERROR'; } diff --git a/tests/Api/NoBatchingContinuousCachingStrategyTest.php b/tests/Api/NoBatchingContinuousCachingStrategyTest.php index c6b43d15..b723afea 100644 --- a/tests/Api/NoBatchingContinuousCachingStrategyTest.php +++ b/tests/Api/NoBatchingContinuousCachingStrategyTest.php @@ -142,7 +142,7 @@ public function testAddHitFailed() true, true, true, - ["cacheHit","flushHits","logErrorSprintf"] + ["cacheHit","flushHits","logErrorSprintf", "addTroubleshootingHit", "sendTroubleshootingQueue"] ); $strategy->expects($this->never())->method("flushHits"); @@ -152,6 +152,7 @@ public function testAddHitFailed() $strategy->expects($this->once())->method("cacheHit")->with([$page]); + $requestBody = $page->toApiKeys(); $url = FlagshipConstant::HIT_EVENT_URL; @@ -186,6 +187,9 @@ public function testAddHitFailed() ] ); + $strategy->expects($this->once())->method("addTroubleshootingHit"); + $strategy->expects($this->once())->method("sendTroubleshootingQueue"); + $this->assertCount(0, $strategy->getHitsPoolQueue()); $this->assertCount(0, $strategy->getActivatePoolQueue()); $strategy->addHit($page); @@ -381,7 +385,7 @@ public function testActivateFlagFailed() true, true, true, - ["cacheHit","flushHits","logErrorSprintf"] + ["cacheHit","flushHits","logErrorSprintf", "addTroubleshootingHit", "sendTroubleshootingQueue"] ); $strategy->expects($this->never())->method("flushHits"); @@ -425,6 +429,8 @@ public function testActivateFlagFailed() [FlagshipConstant::SEND_ACTIVATE, $logMessage ] ] ); + $strategy->expects($this->once())->method("addTroubleshootingHit"); + $strategy->expects($this->once())->method("sendTroubleshootingQueue"); $this->assertCount(0, $strategy->getHitsPoolQueue()); $this->assertCount(0, $strategy->getActivatePoolQueue()); From b77be9461e06487e72a0aa261cf34f73528598e6 Mon Sep 17 00:00:00 2001 From: Heihokon Date: Fri, 9 Feb 2024 11:46:43 -0600 Subject: [PATCH 4/9] Fix visitor context array indexing --- src/Hit/Diagnostic.php | 2 +- tests/Hit/TroubleshootingTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Hit/Diagnostic.php b/src/Hit/Diagnostic.php index edc8b487..bd7f2de1 100644 --- a/src/Hit/Diagnostic.php +++ b/src/Hit/Diagnostic.php @@ -1443,7 +1443,7 @@ public function toApiKeys() if (is_array($this->getVisitorContext())) { $context = $this->getVisitorContext(); foreach ($context as $index => $item) { - $customVariable["visitor.context.$index"] = is_string($item) ? $item : json_encode($item); + $customVariable["visitor.context.[$index]"] = is_string($item) ? $item : json_encode($item); } } diff --git a/tests/Hit/TroubleshootingTest.php b/tests/Hit/TroubleshootingTest.php index a1352ec6..86a18587 100644 --- a/tests/Hit/TroubleshootingTest.php +++ b/tests/Hit/TroubleshootingTest.php @@ -185,8 +185,8 @@ public function testConstruct() 'http.response.code' => (string)$httpResponseCode, "http.response.body" => json_encode($httpResponseBody), 'http.response.time' => (string)$httpResponseTime, - 'visitor.context.key1' => 'value1', - 'visitor.context.key2' => 'value2', + 'visitor.context.[key1]' => 'value1', + 'visitor.context.[key2]' => 'value2', 'visitor.consent' => 'true', 'visitor.assignments.key1' => 'value1', 'visitor.assignments.key2' => 'value2', From 2daef297df0ef6681b336b379c9038557377561c Mon Sep 17 00:00:00 2001 From: Heihokon Date: Wed, 28 Feb 2024 16:24:40 -0600 Subject: [PATCH 5/9] Refactor BucketingManager class - Adding a condition to check if the visitor has consented before sending context. - Simplifying the code by removing unnecessary variable assignments. - Optimizing the code by directly returning the result of the isMatchTargeting and checkAndTargeting methods. --- src/Decision/BucketingManager.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Decision/BucketingManager.php b/src/Decision/BucketingManager.php index d41f9566..cfe921b8 100644 --- a/src/Decision/BucketingManager.php +++ b/src/Decision/BucketingManager.php @@ -77,7 +77,7 @@ public function __construct(HttpClientInterface $httpClient, BucketingConfig $co */ protected function sendContext(VisitorAbstract $visitor) { - if (count($visitor->getContext()) <= self::NB_MIN_CONTEXT_KEYS) { + if (count($visitor->getContext()) <= self::NB_MIN_CONTEXT_KEYS || !$visitor->hasConsented()) { return; } @@ -276,8 +276,7 @@ private function getVisitorCampaigns( ) { $visitorCampaigns = []; foreach ($variationGroups as $variationGroup) { - $check = $this->isMatchTargeting($variationGroup, $visitor); - if ($check) { + if ($this->isMatchTargeting($variationGroup, $visitor)) { $variations = $this->getVariation( $variationGroup, $visitor @@ -409,8 +408,7 @@ private function isMatchTargeting($variationGroup, VisitorAbstract $visitor) $innerTargetings = $targetingGroup[FlagshipField::FIELD_TARGETINGS]; - $check = $this->checkAndTargeting($innerTargetings, $visitor); - if ($check) { + if ($this->checkAndTargeting($innerTargetings, $visitor)) { return true; } } From 68dd79ec1b3e21ff08174214a7dd057b79cadca0 Mon Sep 17 00:00:00 2001 From: Heihokon Date: Wed, 28 Feb 2024 16:24:50 -0600 Subject: [PATCH 6/9] Update log method to use logInfo instead of logError --- src/Visitor/NoConsentStrategy.php | 2 +- src/Visitor/PanicStrategy.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Visitor/NoConsentStrategy.php b/src/Visitor/NoConsentStrategy.php index 014e78b5..9a2c3c9e 100644 --- a/src/Visitor/NoConsentStrategy.php +++ b/src/Visitor/NoConsentStrategy.php @@ -66,7 +66,7 @@ protected function fetchVisitorCampaigns(VisitorAbstract $visitor) */ private function log($functionName) { - $this->logError( + $this->logInfo( $this->getVisitor()->getConfig(), sprintf( FlagshipConstant::METHOD_DEACTIVATED_CONSENT_ERROR, diff --git a/src/Visitor/PanicStrategy.php b/src/Visitor/PanicStrategy.php index 99ae7986..c22f1aea 100644 --- a/src/Visitor/PanicStrategy.php +++ b/src/Visitor/PanicStrategy.php @@ -22,7 +22,7 @@ class PanicStrategy extends DefaultStrategy public function setConsent($hasConsented) { $this->visitor->hasConsented = $hasConsented; - $this->logError( + $this->logInfo( $this->getVisitor()->getConfig(), sprintf( FlagshipConstant::METHOD_DEACTIVATED_SEND_CONSENT_ERROR, @@ -146,7 +146,7 @@ protected function fetchVisitorCampaigns(VisitorAbstract $visitor) */ private function log($functionName) { - $this->logError( + $this->logInfo( $this->getVisitor()->getConfig(), sprintf( FlagshipConstant::METHOD_DEACTIVATED_ERROR, From 29c8941415f51a78944cd2b579895bbd9385183b Mon Sep 17 00:00:00 2001 From: Heihokon Date: Wed, 28 Feb 2024 16:25:04 -0600 Subject: [PATCH 7/9] Update log level to info in test files --- tests/Visitor/NoConsentStrategyTest.php | 4 ++-- tests/Visitor/PanicStrategyTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Visitor/NoConsentStrategyTest.php b/tests/Visitor/NoConsentStrategyTest.php index afb838f2..50c25942 100644 --- a/tests/Visitor/NoConsentStrategyTest.php +++ b/tests/Visitor/NoConsentStrategyTest.php @@ -35,7 +35,7 @@ public function testMethods() true, true, true, - ['error'] + ['info'] ); $trackerManager = $this->getMockForAbstractClass( @@ -82,7 +82,7 @@ public function testMethods() $visitor = new VisitorDelegate(new Container(), $configManager, $visitorId, false, [], true); - $logManagerStub->expects($this->exactly(4))->method('error') + $logManagerStub->expects($this->exactly(4))->method('info') ->withConsecutive( $logMessageBuild('activateModification'), $logMessageBuild('activateModification'), diff --git a/tests/Visitor/PanicStrategyTest.php b/tests/Visitor/PanicStrategyTest.php index b9a69168..ed094282 100644 --- a/tests/Visitor/PanicStrategyTest.php +++ b/tests/Visitor/PanicStrategyTest.php @@ -36,7 +36,7 @@ public function testMethods() true, true, true, - ['error'] + ['info'] ); $trackerManager = $this->getMockForAbstractClass( @@ -88,7 +88,7 @@ public function testMethods() $visitor = new VisitorDelegate(new Container(), $configManager, "visitorId", false, [], true); - $logManagerStub->expects($this->exactly(11))->method('error') + $logManagerStub->expects($this->exactly(11))->method('info') ->withConsecutive( $logMessageBuild('updateContext'), $logMessageBuild('updateContextCollection'), From be254cb9c4c81df72c5dbd3f26986c956c065dfe Mon Sep 17 00:00:00 2001 From: Heihokon Date: Wed, 28 Feb 2024 16:25:11 -0600 Subject: [PATCH 8/9] Update BucketingManagerTest.php with additional test cases --- tests/Decision/BucketingManagerTest.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/Decision/BucketingManagerTest.php b/tests/Decision/BucketingManagerTest.php index 6e2d6ae1..3aa4af2a 100644 --- a/tests/Decision/BucketingManagerTest.php +++ b/tests/Decision/BucketingManagerTest.php @@ -215,19 +215,24 @@ public function testSendContext() $configManager->setConfig($config)->setTrackingManager($trackerManager); $visitor = new VisitorDelegate($containerMock, $configManager, $visitorId, false, $visitorContext, true); - $httpClientMock->expects($this->exactly(2)) + $httpClientMock->expects($this->exactly(3)) ->method('get') ->willReturn( new HttpResponse(204, json_decode('{"campaigns":[{}]}', true)) ); - $trackerManager->expects($this->exactly(2))->method("addHit"); + $trackerManager->expects($this->exactly(3))->method("addHit"); $bucketingManager->getCampaignModifications($visitor); //Test empty context $visitor = new VisitorDelegate($containerMock, $configManager, $visitorId, false, [], true); $bucketingManager->getCampaignModifications($visitor); + + //Test visitor has not consented + $visitor = new VisitorDelegate($containerMock, $configManager, $visitorId, false, $visitorContext, false); + $bucketingManager->getCampaignModifications($visitor); + } public function testGetVariation() From a41d6ef580fdbf1d763d2a6b6638e6e1c59b6b60 Mon Sep 17 00:00:00 2001 From: Heihokon Date: Thu, 29 Feb 2024 10:36:49 -0600 Subject: [PATCH 9/9] Update SDK version to 3.2.1 --- src/Enum/FlagshipConstant.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Enum/FlagshipConstant.php b/src/Enum/FlagshipConstant.php index df0c883c..4b4e0b3d 100644 --- a/src/Enum/FlagshipConstant.php +++ b/src/Enum/FlagshipConstant.php @@ -60,7 +60,7 @@ class FlagshipConstant /** * SDK version */ - const SDK_VERSION = "3.2.0"; + const SDK_VERSION = "3.2.1"; const GET_FLAG = 'GET_FLAG';