Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #36 from carusogabriel/phpunit
Browse files Browse the repository at this point in the history
Use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase
  • Loading branch information
JakubOleksy authored Jan 25, 2018
2 parents 5434b28 + 32963c3 commit 8383318
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Tests/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

require_once 'vendor/autoload.php';
require_once 'vendor/autoload.php';
8 changes: 5 additions & 3 deletions Tests/Channel/Contracts/Utils_Test.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php
namespace ApplicationInsights\Channel\Contracts;

use PHPUnit\Framework\TestCase;

/**
* Contains tests for Utils class
*/
class Utils_Test extends \PHPUnit_Framework_TestCase
class Utils_Test extends TestCase
{
public function testConvertMillisecondsToTimeSpan()
{
$this->assertEquals(Utils::convertMillisecondsToTimeSpan(0), "00:00:00.000");
$this->assertEquals(Utils::convertMillisecondsToTimeSpan(0), "00:00:00.000");
$this->assertEquals(Utils::convertMillisecondsToTimeSpan(1), "00:00:00.001", "milliseconds digit 1");
$this->assertEquals(Utils::convertMillisecondsToTimeSpan(10), "00:00:00.010", "milliseconds digit 2");
$this->assertEquals(Utils::convertMillisecondsToTimeSpan(100), "00:00:00.100", "milliseconds digit 3");
Expand All @@ -28,4 +30,4 @@ public function testConvertMillisecondsToTimeSpan()
$this->assertEquals(Utils::convertMillisecondsToTimeSpan(-1), "00:00:00.000", "invalid input");

}
}
}
8 changes: 5 additions & 3 deletions Tests/Channel/Telemetry_Channel_Test.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
<?php
namespace ApplicationInsights\Channel\Tests;

use PHPUnit\Framework\TestCase;

/**
* Contains tests for TelemetrySender class
*/
class Telemetry_Channel_Test extends \PHPUnit_Framework_TestCase
class Telemetry_Channel_Test extends TestCase
{
public function testConstructor()
{
$telemetryChannel = new \ApplicationInsights\Channel\Telemetry_Channel();
$this->assertEquals($telemetryChannel->getEndpointUrl(), 'https://dc.services.visualstudio.com/v2/track', 'Default Endpoint URL is incorrect.');
$this->assertEquals($telemetryChannel->getQueue(), [], 'Queue should be empty by default.');
}

public function testEndpointUrl()
{
$telemetryChannel = new \ApplicationInsights\Channel\Telemetry_Channel();
$telemetryChannel->setEndpointUrl('http://foo.com');
$this->assertEquals($telemetryChannel->getEndpointUrl(), 'http://foo.com');
}

public function testQueue()
{
$telemetryChannel = new \ApplicationInsights\Channel\Telemetry_Channel();
Expand Down
16 changes: 9 additions & 7 deletions Tests/Current_Session_Test.php
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
<?php
namespace ApplicationInsights\Tests;

use PHPUnit\Framework\TestCase;

/**
* Contains tests for Current_Session class
*/
class Current_Session_Test extends \PHPUnit_Framework_TestCase
class Current_Session_Test extends TestCase
{
private $sessionId;
private $sessionCreatedTime;
private $sessionLastRenewedTime;

protected function setUp()
{
$this->sessionId = \ApplicationInsights\Channel\Contracts\Utils::returnGuid();
$this->sessionCreatedTime = time();
$this->sessionLastRenewedTime = time() - 10000;
Utils::setSessionCookie($this->sessionId, $this->sessionCreatedTime, $this->sessionLastRenewedTime);
}

protected function tearDown()
{
Utils::clearSessionCookie();
}

/**
* Verifies the object is constructed properly.
*/
public function testConstructor()
{
$currentSession = new \ApplicationInsights\Current_Session();

$this->assertEquals($currentSession->id, $this->sessionId);
$this->assertEquals($currentSession->sessionCreated, $this->sessionCreatedTime);
$this->assertEquals($currentSession->sessionLastRenewed, $this->sessionLastRenewedTime);
}

/**
* Verifies the object is constructed properly.
*/
public function testConstructorWithNoCookie()
{
Utils::clearSessionCookie();
$currentSession = new \ApplicationInsights\Current_Session();

$this->assertEquals($currentSession->id, NULL);
$this->assertEquals($currentSession->sessionCreated, NULL);
$this->assertEquals($currentSession->sessionLastRenewed, NULL);
Expand Down
18 changes: 10 additions & 8 deletions Tests/Current_User_Test.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
<?php
namespace ApplicationInsights\Tests;

use PHPUnit\Framework\TestCase;

/**
* Contains tests for Current_User class
*/
class Current_User_Test extends \PHPUnit_Framework_TestCase
class Current_User_Test extends TestCase
{
private $userId;

protected function setUp()
{
$this->userId = \ApplicationInsights\Channel\Contracts\Utils::returnGuid();
Utils::setUserCookie($this->userId);
}

protected function tearDown()
{
Utils::clearUserCookie();
}

/**
* Verifies the object is constructed properly.
*/
public function testConstructor()
{
$currentUser = new \ApplicationInsights\Current_User();

$this->assertEquals($currentUser->id, $this->userId);
}

/**
* Verifies the object is constructed properly.
*/
public function testConstructorWithNoCookie()
{
Utils::clearUserCookie();
$currentUser = new \ApplicationInsights\Current_User();

$this->assertTrue($currentUser->id != NULL && $currentUser->id != $this->userId);
}

}
6 changes: 4 additions & 2 deletions Tests/Telemetry_Client_Test.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
namespace ApplicationInsights\Tests;

use PHPUnit\Framework\TestCase;

/**
* Contains tests for Telemetry_Client class
*/
class Telemetry_Client_Test extends \PHPUnit_Framework_TestCase
class Telemetry_Client_Test extends TestCase
{
private $_telemetryClient;

Expand Down Expand Up @@ -47,7 +49,7 @@ public function testCompleteException()
$searchStrings = array("\\");
$replaceStrings = array("\\\\");

$expectedString = str_replace($searchStrings, $replaceStrings, '[{"ver":1,"name":"Microsoft.ApplicationInsights.Exception","time":"TIME_PLACEHOLDER","sampleRate":100,"iKey":"'. Utils::getTestInstrumentationKey() . '","tags":{"ai.application.ver":"1.0.0.0","ai.device.id":"my_device_id","ai.device.ip":"127.0.0.1","ai.device.language":"EN","ai.device.locale":"EN","ai.device.model":"my_device_model","ai.device.network":5,"ai.device.oemName":"my_device_oem_name","ai.device.os":"Window","ai.device.osVersion":"8","ai.device.roleInstance":"device role instance","ai.device.roleName":"device role name","ai.device.screenResolution":"1920x1080","ai.device.type":"PC","ai.device.vmName":"device vm name","ai.location.ip":"127.0.0.0","ai.operation.id":"my_operation_id","ai.operation.name":"my_operation_name","ai.operation.parentId":"my_operation_parent_id","ai.operation.rootId":"my_operation_rood","ai.session.id":"my_session_id","ai.session.isFirst":"false","ai.session.isNew":"false","ai.user.id":"my_user_id","ai.user.accountAcquisitionDate":"1/1/2014","ai.user.accountId":"my_account_id","ai.user.userAgent":"my_user_agent","ai.internal.sdkVersion":"SDK_VERSION_STRING"},"data":{"baseData":{"ver":2,"handledAt":"UserCode","exceptions":[{"typeName":"Exception","message":"testException in G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php on line 130","hasFullStack":true,"id":1,"parsedStack":[{"level":"14","method":"main","assembly":"PHPUnit_TextUI_Command","fileName":"C:\\Users\\jakubo\\AppData\\Local\\Microsoft\\VisualStudio\\12.0\\Extensions\\DEVSENSE\\PHP Tools for Visual Studio 2013 1.14.5747\\phpunit-3.7.phar","line":52},{"level":"13","method":"run","assembly":"PHPUnit_TextUI_Command","fileName":"phar://C:/Users/jakubo/AppData/Local/Microsoft/VisualStudio/12.0/Extensions/DEVSENSE/PHP Tools for Visual Studio 2013 1.14.5747/phpunit-3.7.phar/phpunit/TextUI/Command.php","line":100},{"level":"12","method":"doRun","assembly":"PHPUnit_TextUI_TestRunner","fileName":"phar://C:/Users/jakubo/AppData/Local/Microsoft/VisualStudio/12.0/Extensions/DEVSENSE/PHP Tools for Visual Studio 2013 1.14.5747/phpunit-3.7.phar/phpunit/TextUI/Command.php","line":149},{"level":"11","method":"run","assembly":"PHPUnit_Framework_TestSuite","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\TextUI\\TestRunner.php","line":440},{"level":"10","method":"run","assembly":"PHPUnit_Framework_TestSuite","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestSuite.php","line":722},{"level":"9","method":"run","assembly":"PHPUnit_Framework_TestCase","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestSuite.php","line":722},{"level":"8","method":"run","assembly":"PHPUnit_Framework_TestResult","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestCase.php","line":724},{"level":"7","method":"runBare","assembly":"PHPUnit_Framework_TestCase","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestResult.php","line":612},{"level":"6","method":"runTest","assembly":"PHPUnit_Framework_TestCase","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestCase.php","line":768},{"level":"5","method":"invokeArgs","assembly":"ReflectionMethod","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestCase.php","line":908},{"level":"4","method":"testCompleteException","assembly":"ApplicationInsights\\Tests\\Telemetry_Client_Test"},{"level":"3","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Telemetry_Client_Test.php","line":37},{"level":"2","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php","line":133},{"level":"1","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php","line":133},{"level":"0","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php","line":133}]}],"properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"},"measurements":{"duration_inner":42}},"baseType":"ExceptionData"}}]');
$expectedString = str_replace($searchStrings, $replaceStrings, '[{"ver":1,"name":"Microsoft.ApplicationInsights.Exception","time":"TIME_PLACEHOLDER","sampleRate":100,"iKey":"'. Utils::getTestInstrumentationKey() . '","tags":{"ai.application.ver":"1.0.0.0","ai.device.id":"my_device_id","ai.device.ip":"127.0.0.1","ai.device.language":"EN","ai.device.locale":"EN","ai.device.model":"my_device_model","ai.device.network":5,"ai.device.oemName":"my_device_oem_name","ai.device.os":"Window","ai.device.osVersion":"8","ai.device.roleInstance":"device role instance","ai.device.roleName":"device role name","ai.device.screenResolution":"1920x1080","ai.device.type":"PC","ai.device.vmName":"device vm name","ai.location.ip":"127.0.0.0","ai.operation.id":"my_operation_id","ai.operation.name":"my_operation_name","ai.operation.parentId":"my_operation_parent_id","ai.operation.rootId":"my_operation_rood","ai.session.id":"my_session_id","ai.session.isFirst":"false","ai.session.isNew":"false","ai.user.id":"my_user_id","ai.user.accountAcquisitionDate":"1/1/2014","ai.user.accountId":"my_account_id","ai.user.userAgent":"my_user_agent","ai.internal.sdkVersion":"SDK_VERSION_STRING"},"data":{"baseData":{"ver":2,"handledAt":"UserCode","exceptions":[{"typeName":"Exception","message":"testException in G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php on line 130","hasFullStack":true,"id":1,"parsedStack":[{"level":"14","method":"main","assembly":"PHPUnit_TextUI_Command","fileName":"C:\\Users\\jakubo\\AppData\\Local\\Microsoft\\VisualStudio\\12.0\\Extensions\\DEVSENSE\\PHP Tools for Visual Studio 2013 1.14.5747\\phpunit-3.7.phar","line":52},{"level":"13","method":"run","assembly":"PHPUnit_TextUI_Command","fileName":"phar://C:/Users/jakubo/AppData/Local/Microsoft/VisualStudio/12.0/Extensions/DEVSENSE/PHP Tools for Visual Studio 2013 1.14.5747/phpunit-3.7.phar/phpunit/TextUI/Command.php","line":100},{"level":"12","method":"doRun","assembly":"PHPUnit_TextUI_TestRunner","fileName":"phar://C:/Users/jakubo/AppData/Local/Microsoft/VisualStudio/12.0/Extensions/DEVSENSE/PHP Tools for Visual Studio 2013 1.14.5747/phpunit-3.7.phar/phpunit/TextUI/Command.php","line":149},{"level":"11","method":"run","assembly":"PHPUnit_Framework_TestSuite","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\TextUI\\TestRunner.php","line":440},{"level":"10","method":"run","assembly":"PHPUnit_Framework_TestSuite","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestSuite.php","line":722},{"level":"9","method":"run","assembly":"PHPUnit\\Framework\\TestCase","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestSuite.php","line":722},{"level":"8","method":"run","assembly":"PHPUnit_Framework_TestResult","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestCase.php","line":724},{"level":"7","method":"runBare","assembly":"PHPUnit\\Framework\\TestCase","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestResult.php","line":612},{"level":"6","method":"runTest","assembly":"PHPUnit\\Framework\\TestCase","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestCase.php","line":768},{"level":"5","method":"invokeArgs","assembly":"ReflectionMethod","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestCase.php","line":908},{"level":"4","method":"testCompleteException","assembly":"ApplicationInsights\\Tests\\Telemetry_Client_Test"},{"level":"3","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Telemetry_Client_Test.php","line":37},{"level":"2","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php","line":133},{"level":"1","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php","line":133},{"level":"0","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php","line":133}]}],"properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"},"measurements":{"duration_inner":42}},"baseType":"ExceptionData"}}]');
$expectedValue = json_decode($expectedString, true);

$this->assertEquals($this->removeMachineSpecificExceptionData($queue), $this->removeMachineSpecificExceptionData($expectedValue));
Expand Down
26 changes: 14 additions & 12 deletions Tests/Telemetry_Context_Test.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
namespace ApplicationInsights\Tests;

use PHPUnit\Framework\TestCase;

/**
* Contains tests for Telemetry_Context class
*/
class Telemetry_Context_Test extends \PHPUnit_Framework_TestCase
class Telemetry_Context_Test extends TestCase
{
public function testInstrumentationKey()
{
Expand All @@ -13,7 +15,7 @@ public function testInstrumentationKey()
$telemetryContext->setInstrumentationKey($instrumentationKey);
$this->assertEquals($instrumentationKey, $telemetryContext->getInstrumentationKey());
}

public function testDeviceContext()
{
$telemetryContext = new \ApplicationInsights\Telemetry_Context();
Expand All @@ -23,7 +25,7 @@ public function testDeviceContext()
$context = $telemetryContext->getDeviceContext();
$this->assertEquals($context, Utils::getSampleDeviceContext());
}

public function testApplicationContext()
{
$telemetryContext = new \ApplicationInsights\Telemetry_Context();
Expand All @@ -33,12 +35,12 @@ public function testApplicationContext()
$context = $telemetryContext->getApplicationContext();
$this->assertEquals($context, Utils::getSampleApplicationContext());
}

public function testUserContext()
{
$telemetryContext = new \ApplicationInsights\Telemetry_Context();
$context = $telemetryContext->getUserContext();

$defaultUserContext = new \ApplicationInsights\Channel\Contracts\User();
$currentUser = new \ApplicationInsights\Current_User();
$defaultUserContext->setId($currentUser->id);
Expand All @@ -48,7 +50,7 @@ public function testUserContext()
$context = $telemetryContext->getUserContext();
$this->assertEquals($context, Utils::getSampleUserContext());
}

public function testLocationContext()
{
$telemetryContext = new \ApplicationInsights\Telemetry_Context();
Expand All @@ -58,7 +60,7 @@ public function testLocationContext()
$context = $telemetryContext->getLocationContext();
$this->assertEquals($context, Utils::getSampleLocationContext());
}

public function testOperationContext()
{
$telemetryContext = new \ApplicationInsights\Telemetry_Context();
Expand All @@ -67,22 +69,22 @@ public function testOperationContext()
$context = $telemetryContext->getOperationContext();
$this->assertEquals($context, Utils::getSampleOperationContext());
}

public function testSessionContext()
{
$telemetryContext = new \ApplicationInsights\Telemetry_Context();
$context = $telemetryContext->getSessionContext();

$defaultSessionContext = new \ApplicationInsights\Channel\Contracts\Session();
$currentSession = new \ApplicationInsights\Current_Session();
$defaultSessionContext->setId($currentSession->id);
$this->assertEquals($context, $defaultSessionContext);

$telemetryContext->setSessionContext(Utils::getSampleSessionContext());
$context = $telemetryContext->getSessionContext();
$this->assertEquals($context, Utils::getSampleSessionContext());
}

public function testProperties()
{
$telemetryContext = new \ApplicationInsights\Telemetry_Context();
Expand All @@ -92,4 +94,4 @@ public function testProperties()
$properties = $telemetryContext->getProperties();
$this->assertEquals($properties, Utils::getSampleCustomProperties());
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"guzzlehttp/guzzle": ">=5.0 <=6.3"
},
"require-dev": {
"phpunit/phpunit": "~4.3",
"phpunit/phpunit": "~4.8.36",
"evert/phpdoc-md" : "~0.0.7"
},
"autoload": {
Expand Down

0 comments on commit 8383318

Please sign in to comment.