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
55 changes: 38 additions & 17 deletions src/Api/NoBatchingContinuousCachingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ protected function onError(HitAbstract $hit): void
protected function sendHit(HitAbstract $hit): void
{
$header = [
FlagshipConstant::HEADER_CONTENT_TYPE => FlagshipConstant::HEADER_APPLICATION_JSON,
];
FlagshipConstant::HEADER_CONTENT_TYPE => FlagshipConstant::HEADER_APPLICATION_JSON,
];

$requestBody = $hit->toApiKeys();
$now = $this->getNow();
Expand All @@ -68,8 +68,8 @@ protected function sendHit(HitAbstract $hit): void
FlagshipConstant::TRACKING_MANAGER,
FlagshipConstant::HIT_SENT_SUCCESS,
[
FlagshipConstant::SEND_HIT,
$this->getLogFormat(null, $url, $requestBody, $header, $this->getNow() - $now),
FlagshipConstant::SEND_HIT,
$this->getLogFormat(null, $url, $requestBody, $header, $this->getNow() - $now),
]
);
} catch (Exception $exception) {
Expand All @@ -79,12 +79,23 @@ protected function sendHit(HitAbstract $hit): void
FlagshipConstant::TRACKING_MANAGER,
FlagshipConstant::UNEXPECTED_ERROR_OCCURRED,
[
FlagshipConstant::SEND_HIT,
$this->getLogFormat($exception->getMessage(), $url, $requestBody, $header, $this->getNow() - $now),
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);
$troubleshooting->setLabel(TroubleshootingLabel::SEND_HIT_ROUTE_ERROR)
->setLogLevel(LogLevel::ERROR)
->setFlagshipInstanceId($this->flagshipInstanceId)
->setHttpRequestBody($requestBody)
->setHttpRequestHeaders($header)
->setHttpRequestMethod("POST")
->setHttpRequestUrl($url)
->setHttpResponseBody($exception->getMessage())
->setHttpResponseTime($this->getNow() - $now)
->setTraffic(100)->setConfig($this->config)
->setVisitorId($this->flagshipInstanceId)
;
$this->addTroubleshootingHit($troubleshooting);
$this->sendTroubleshootingQueue();
}
Expand Down Expand Up @@ -117,8 +128,8 @@ public function activateFlag(Activate $hit): void
FlagshipConstant::TRACKING_MANAGER,
FlagshipConstant::HIT_SENT_SUCCESS,
[
FlagshipConstant::SEND_ACTIVATE,
$this->getLogFormat(null, $url, $requestBody, $headers, $this->getNow() - $now),
FlagshipConstant::SEND_ACTIVATE,
$this->getLogFormat(null, $url, $requestBody, $headers, $this->getNow() - $now),
]
);
} catch (Exception $exception) {
Expand All @@ -128,22 +139,29 @@ public function activateFlag(Activate $hit): void
FlagshipConstant::TRACKING_MANAGER,
FlagshipConstant::UNEXPECTED_ERROR_OCCURRED,
[
FlagshipConstant::SEND_ACTIVATE,
$this->getLogFormat($exception->getMessage(), $url, $requestBody, $headers, $this->getNow() - $now),
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);
$troubleshooting->setLabel(TroubleshootingLabel::SEND_ACTIVATE_HIT_ROUTE_ERROR)
->setFlagshipInstanceId($this->flagshipInstanceId)
->setHttpRequestBody($requestBody)
->setHttpRequestHeaders($headers)
->setHttpRequestMethod("POST")
->setHttpRequestUrl($url)
->setHttpResponseBody($exception->getMessage())
->setHttpResponseTime($this->getNow() - $now)
->setLogLevel(LogLevel::ERROR)
->setTraffic(100)->setConfig($this->config)
->setVisitorId($this->flagshipInstanceId);
$this->addTroubleshootingHit($troubleshooting);
$this->sendTroubleshootingQueue();
}
}

/**
* @param string $visitorId
* @return void
*/

protected function notConsent(string $visitorId): void
{
$keysToFlush = $this->commonNotConsent($visitorId);
Expand All @@ -157,7 +175,10 @@ protected function notConsent(string $visitorId): void

public function addTroubleshootingHit(Troubleshooting $hit): void
{
$this->sendTroubleshooting($hit);
if (!$this->isTroubleshootingActivated()) {
return;
}
$this->sendTroubleshooting($hit);
}

public function addUsageHit(UsageHit $hit): void
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/FlagshipConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class FlagshipConstant
/**
* SDK version
*/
public const SDK_VERSION = "4.1.0";
public const SDK_VERSION = "4.1.1";

public const GET_FLAG = 'GET_FLAG';

Expand Down
22 changes: 14 additions & 8 deletions tests/Api/NoBatchingContinuousCachingStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
namespace Flagship\Api;

use Exception;
use Flagship\Config\DecisionApiConfig;
use Flagship\Enum\EventCategory;
use Flagship\Enum\FlagshipConstant;
use Flagship\Hit\Page;
use Flagship\Hit\Event;
use Flagship\Hit\Activate;
use Flagship\Hit\ActivateBatch;
use Flagship\Hit\UsageHit;
use Flagship\Hit\Event;
use Flagship\Hit\HitAbstract;
use Flagship\Hit\Page;
use Flagship\Hit\Troubleshooting;
use Flagship\Traits\LogTrait;
use Flagship\Hit\ActivateBatch;
use PHPUnit\Framework\TestCase;
use Flagship\Enum\EventCategory;
use Flagship\Hit\Troubleshooting;
use Flagship\Enum\FlagshipConstant;
use Flagship\Config\DecisionApiConfig;
use PHPUnit\Framework\MockObject\MockObject;

class NoBatchingContinuousCachingStrategyTest extends TestCase
{
Expand Down Expand Up @@ -527,6 +528,9 @@ public function testAddTroubleshootingHit()

$httpClientMock = $this->getMockForAbstractClass('Flagship\Utils\HttpClientInterface');

/**
* @var NoBatchingContinuousCachingStrategy| MockObject
*/
$strategy = $this->getMockForAbstractClass(
"Flagship\Api\NoBatchingContinuousCachingStrategy",
[
Expand All @@ -537,12 +541,14 @@ public function testAddTroubleshootingHit()
true,
false,
true,
["sendTroubleshooting"]
["sendTroubleshooting", 'isTroubleshootingActivated']
);

$troubleshooting = new Troubleshooting();
$troubleshooting->setConfig($config);

$strategy->expects($this->once())->method('isTroubleshootingActivated')->willReturn(true);

$strategy->expects($this->once())->method('sendTroubleshooting')->with($troubleshooting);

$strategy->addTroubleshootingHit($troubleshooting);
Expand Down