Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
norberttech committed Mar 3, 2019
1 parent 7c3f680 commit a5663e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
20 changes: 12 additions & 8 deletions Tests/Twig/TelemetryExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ public function test_app_insights_php_function_without_user_id()
var appInsights=window.appInsights||function(a){
function b(a){c[a]=function(){var b=arguments;c.queue.push(function(){c[a].apply(c,b)})}}var c={config:a},d=document,e=window;setTimeout(function(){var b=d.createElement("script");b.src=a.url||"https://az416426.vo.msecnd.net/scripts/a/ai.0.js",d.getElementsByTagName("script")[0].parentNode.appendChild(b)});try{c.cookie=d.cookie}catch(a){}c.queue=[];for(var f=["Event","Exception","Metric","PageView","Trace","Dependency"];f.length;)b("track"+f.pop());if(b("setAuthenticatedUserContext"),b("clearAuthenticatedUserContext"),b("startTrackEvent"),b("stopTrackEvent"),b("startTrackPage"),b("stopTrackPage"),b("flush"),!a.disableExceptionTracking){f="onerror",b("_"+f);var g=e[f];e[f]=function(a,b,d,e,h){var i=g&&g(a,b,d,e,h);return!0!==i&&c["_"+f](a,b,d,e,h),i}}return c
}({
instrumentationKey:"instrumentation_key"
instrumentationKey:"instrumentation_key",
disableCorrelationHeaders: false
});
window.appInsights=appInsights;
window.appInsights.context.operation.id="operation_id";
window.appInsights.queue&&0===appInsights.queue.length&&appInsights.trackPageView();
window.appInsights.queue.push(function () {
appInsights.context.operation.id = 'operation_id';
});
window.appInsights.trackPageView();
</script>
TWIG
, $twigExtension->appInsightsPHP()
Expand All @@ -56,13 +58,15 @@ public function test_app_insights_php_function_with_user_id()
var appInsights=window.appInsights||function(a){
function b(a){c[a]=function(){var b=arguments;c.queue.push(function(){c[a].apply(c,b)})}}var c={config:a},d=document,e=window;setTimeout(function(){var b=d.createElement("script");b.src=a.url||"https://az416426.vo.msecnd.net/scripts/a/ai.0.js",d.getElementsByTagName("script")[0].parentNode.appendChild(b)});try{c.cookie=d.cookie}catch(a){}c.queue=[];for(var f=["Event","Exception","Metric","PageView","Trace","Dependency"];f.length;)b("track"+f.pop());if(b("setAuthenticatedUserContext"),b("clearAuthenticatedUserContext"),b("startTrackEvent"),b("stopTrackEvent"),b("startTrackPage"),b("stopTrackPage"),b("flush"),!a.disableExceptionTracking){f="onerror",b("_"+f);var g=e[f];e[f]=function(a,b,d,e,h){var i=g&&g(a,b,d,e,h);return!0!==i&&c["_"+f](a,b,d,e,h),i}}return c
}({
instrumentationKey:"instrumentation_key"
instrumentationKey:"instrumentation_key",
disableCorrelationHeaders: false
});
window.appInsights=appInsights;
window.appInsights.context.operation.id="operation_id";
window.appInsights.queue.push(function () {
appInsights.context.operation.id = 'operation_id';
});
window.appInsights.setAuthenticatedUserContext("norbert@orzechowicz.pl");
window.appInsights.queue&&0===appInsights.queue.length&&appInsights.trackPageView();
window.appInsights.trackPageView();
</script>
TWIG
, $twigExtension->appInsightsPHP('norbert@orzechowicz.pl')
Expand Down
7 changes: 3 additions & 4 deletions Twig/TelemetryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ function b(a){c[a]=function(){var b=arguments;c.queue.push(function(){c[a].apply
appInsights.context.operation.id = '%s';
});\n
JS
, $this->client->getContext()->getInstrumentationKey(), $this->client->getContext()->getOperationContext()->getId()
, $this->client->getContext()->getInstrumentationKey(),
$this->client->getContext()->getOperationContext()->getId()
);

$script .= sprintf("window.appInsights.context.operation.id=\"%s\";\n", $this->client->getContext()->getOperationContext()->getId());

if ($userId) {
$script .= sprintf("window.appInsights.setAuthenticatedUserContext(\"%s\");\n", $userId);
}

$script .= "window.appInsights.queue&&0===appInsights.queue.length&&appInsights.trackPageView();\n";
$script .= "window.appInsights.trackPageView();\n";

$script .= '</script>';

Expand Down

0 comments on commit a5663e8

Please sign in to comment.