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

Commit 8383318

Browse files
authored
Merge pull request #36 from carusogabriel/phpunit
Use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase
2 parents 5434b28 + 32963c3 commit 8383318

File tree

8 files changed

+49
-37
lines changed

8 files changed

+49
-37
lines changed

Tests/Bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
require_once 'vendor/autoload.php';
3+
require_once 'vendor/autoload.php';

Tests/Channel/Contracts/Utils_Test.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
<?php
22
namespace ApplicationInsights\Channel\Contracts;
33

4+
use PHPUnit\Framework\TestCase;
5+
46
/**
57
* Contains tests for Utils class
68
*/
7-
class Utils_Test extends \PHPUnit_Framework_TestCase
9+
class Utils_Test extends TestCase
810
{
911
public function testConvertMillisecondsToTimeSpan()
1012
{
11-
$this->assertEquals(Utils::convertMillisecondsToTimeSpan(0), "00:00:00.000");
13+
$this->assertEquals(Utils::convertMillisecondsToTimeSpan(0), "00:00:00.000");
1214
$this->assertEquals(Utils::convertMillisecondsToTimeSpan(1), "00:00:00.001", "milliseconds digit 1");
1315
$this->assertEquals(Utils::convertMillisecondsToTimeSpan(10), "00:00:00.010", "milliseconds digit 2");
1416
$this->assertEquals(Utils::convertMillisecondsToTimeSpan(100), "00:00:00.100", "milliseconds digit 3");
@@ -28,4 +30,4 @@ public function testConvertMillisecondsToTimeSpan()
2830
$this->assertEquals(Utils::convertMillisecondsToTimeSpan(-1), "00:00:00.000", "invalid input");
2931

3032
}
31-
}
33+
}

Tests/Channel/Telemetry_Channel_Test.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
<?php
22
namespace ApplicationInsights\Channel\Tests;
33

4+
use PHPUnit\Framework\TestCase;
5+
46
/**
57
* Contains tests for TelemetrySender class
68
*/
7-
class Telemetry_Channel_Test extends \PHPUnit_Framework_TestCase
9+
class Telemetry_Channel_Test extends TestCase
810
{
911
public function testConstructor()
1012
{
1113
$telemetryChannel = new \ApplicationInsights\Channel\Telemetry_Channel();
1214
$this->assertEquals($telemetryChannel->getEndpointUrl(), 'https://dc.services.visualstudio.com/v2/track', 'Default Endpoint URL is incorrect.');
1315
$this->assertEquals($telemetryChannel->getQueue(), [], 'Queue should be empty by default.');
1416
}
15-
17+
1618
public function testEndpointUrl()
1719
{
1820
$telemetryChannel = new \ApplicationInsights\Channel\Telemetry_Channel();
1921
$telemetryChannel->setEndpointUrl('http://foo.com');
2022
$this->assertEquals($telemetryChannel->getEndpointUrl(), 'http://foo.com');
2123
}
22-
24+
2325
public function testQueue()
2426
{
2527
$telemetryChannel = new \ApplicationInsights\Channel\Telemetry_Channel();

Tests/Current_Session_Test.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,50 @@
11
<?php
22
namespace ApplicationInsights\Tests;
33

4+
use PHPUnit\Framework\TestCase;
5+
46
/**
57
* Contains tests for Current_Session class
68
*/
7-
class Current_Session_Test extends \PHPUnit_Framework_TestCase
9+
class Current_Session_Test extends TestCase
810
{
911
private $sessionId;
1012
private $sessionCreatedTime;
1113
private $sessionLastRenewedTime;
12-
14+
1315
protected function setUp()
1416
{
1517
$this->sessionId = \ApplicationInsights\Channel\Contracts\Utils::returnGuid();
1618
$this->sessionCreatedTime = time();
1719
$this->sessionLastRenewedTime = time() - 10000;
1820
Utils::setSessionCookie($this->sessionId, $this->sessionCreatedTime, $this->sessionLastRenewedTime);
1921
}
20-
22+
2123
protected function tearDown()
2224
{
2325
Utils::clearSessionCookie();
2426
}
25-
27+
2628
/**
2729
* Verifies the object is constructed properly.
2830
*/
2931
public function testConstructor()
3032
{
3133
$currentSession = new \ApplicationInsights\Current_Session();
32-
34+
3335
$this->assertEquals($currentSession->id, $this->sessionId);
3436
$this->assertEquals($currentSession->sessionCreated, $this->sessionCreatedTime);
3537
$this->assertEquals($currentSession->sessionLastRenewed, $this->sessionLastRenewedTime);
3638
}
37-
39+
3840
/**
3941
* Verifies the object is constructed properly.
4042
*/
4143
public function testConstructorWithNoCookie()
4244
{
4345
Utils::clearSessionCookie();
4446
$currentSession = new \ApplicationInsights\Current_Session();
45-
47+
4648
$this->assertEquals($currentSession->id, NULL);
4749
$this->assertEquals($currentSession->sessionCreated, NULL);
4850
$this->assertEquals($currentSession->sessionLastRenewed, NULL);

Tests/Current_User_Test.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,45 @@
11
<?php
22
namespace ApplicationInsights\Tests;
33

4+
use PHPUnit\Framework\TestCase;
5+
46
/**
57
* Contains tests for Current_User class
68
*/
7-
class Current_User_Test extends \PHPUnit_Framework_TestCase
9+
class Current_User_Test extends TestCase
810
{
911
private $userId;
10-
12+
1113
protected function setUp()
1214
{
1315
$this->userId = \ApplicationInsights\Channel\Contracts\Utils::returnGuid();
1416
Utils::setUserCookie($this->userId);
1517
}
16-
18+
1719
protected function tearDown()
1820
{
1921
Utils::clearUserCookie();
2022
}
21-
23+
2224
/**
2325
* Verifies the object is constructed properly.
2426
*/
2527
public function testConstructor()
2628
{
2729
$currentUser = new \ApplicationInsights\Current_User();
28-
30+
2931
$this->assertEquals($currentUser->id, $this->userId);
3032
}
31-
33+
3234
/**
3335
* Verifies the object is constructed properly.
3436
*/
3537
public function testConstructorWithNoCookie()
3638
{
3739
Utils::clearUserCookie();
3840
$currentUser = new \ApplicationInsights\Current_User();
39-
41+
4042
$this->assertTrue($currentUser->id != NULL && $currentUser->id != $this->userId);
4143
}
42-
44+
4345
}

Tests/Telemetry_Client_Test.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22
namespace ApplicationInsights\Tests;
33

4+
use PHPUnit\Framework\TestCase;
5+
46
/**
57
* Contains tests for Telemetry_Client class
68
*/
7-
class Telemetry_Client_Test extends \PHPUnit_Framework_TestCase
9+
class Telemetry_Client_Test extends TestCase
810
{
911
private $_telemetryClient;
1012

@@ -47,7 +49,7 @@ public function testCompleteException()
4749
$searchStrings = array("\\");
4850
$replaceStrings = array("\\\\");
4951

50-
$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"}}]');
52+
$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"}}]');
5153
$expectedValue = json_decode($expectedString, true);
5254

5355
$this->assertEquals($this->removeMachineSpecificExceptionData($queue), $this->removeMachineSpecificExceptionData($expectedValue));

Tests/Telemetry_Context_Test.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22
namespace ApplicationInsights\Tests;
33

4+
use PHPUnit\Framework\TestCase;
5+
46
/**
57
* Contains tests for Telemetry_Context class
68
*/
7-
class Telemetry_Context_Test extends \PHPUnit_Framework_TestCase
9+
class Telemetry_Context_Test extends TestCase
810
{
911
public function testInstrumentationKey()
1012
{
@@ -13,7 +15,7 @@ public function testInstrumentationKey()
1315
$telemetryContext->setInstrumentationKey($instrumentationKey);
1416
$this->assertEquals($instrumentationKey, $telemetryContext->getInstrumentationKey());
1517
}
16-
18+
1719
public function testDeviceContext()
1820
{
1921
$telemetryContext = new \ApplicationInsights\Telemetry_Context();
@@ -23,7 +25,7 @@ public function testDeviceContext()
2325
$context = $telemetryContext->getDeviceContext();
2426
$this->assertEquals($context, Utils::getSampleDeviceContext());
2527
}
26-
28+
2729
public function testApplicationContext()
2830
{
2931
$telemetryContext = new \ApplicationInsights\Telemetry_Context();
@@ -33,12 +35,12 @@ public function testApplicationContext()
3335
$context = $telemetryContext->getApplicationContext();
3436
$this->assertEquals($context, Utils::getSampleApplicationContext());
3537
}
36-
38+
3739
public function testUserContext()
3840
{
3941
$telemetryContext = new \ApplicationInsights\Telemetry_Context();
4042
$context = $telemetryContext->getUserContext();
41-
43+
4244
$defaultUserContext = new \ApplicationInsights\Channel\Contracts\User();
4345
$currentUser = new \ApplicationInsights\Current_User();
4446
$defaultUserContext->setId($currentUser->id);
@@ -48,7 +50,7 @@ public function testUserContext()
4850
$context = $telemetryContext->getUserContext();
4951
$this->assertEquals($context, Utils::getSampleUserContext());
5052
}
51-
53+
5254
public function testLocationContext()
5355
{
5456
$telemetryContext = new \ApplicationInsights\Telemetry_Context();
@@ -58,7 +60,7 @@ public function testLocationContext()
5860
$context = $telemetryContext->getLocationContext();
5961
$this->assertEquals($context, Utils::getSampleLocationContext());
6062
}
61-
63+
6264
public function testOperationContext()
6365
{
6466
$telemetryContext = new \ApplicationInsights\Telemetry_Context();
@@ -67,22 +69,22 @@ public function testOperationContext()
6769
$context = $telemetryContext->getOperationContext();
6870
$this->assertEquals($context, Utils::getSampleOperationContext());
6971
}
70-
72+
7173
public function testSessionContext()
7274
{
7375
$telemetryContext = new \ApplicationInsights\Telemetry_Context();
7476
$context = $telemetryContext->getSessionContext();
75-
77+
7678
$defaultSessionContext = new \ApplicationInsights\Channel\Contracts\Session();
7779
$currentSession = new \ApplicationInsights\Current_Session();
7880
$defaultSessionContext->setId($currentSession->id);
7981
$this->assertEquals($context, $defaultSessionContext);
80-
82+
8183
$telemetryContext->setSessionContext(Utils::getSampleSessionContext());
8284
$context = $telemetryContext->getSessionContext();
8385
$this->assertEquals($context, Utils::getSampleSessionContext());
8486
}
85-
87+
8688
public function testProperties()
8789
{
8890
$telemetryContext = new \ApplicationInsights\Telemetry_Context();
@@ -92,4 +94,4 @@ public function testProperties()
9294
$properties = $telemetryContext->getProperties();
9395
$this->assertEquals($properties, Utils::getSampleCustomProperties());
9496
}
95-
}
97+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"guzzlehttp/guzzle": ">=5.0 <=6.3"
1111
},
1212
"require-dev": {
13-
"phpunit/phpunit": "~4.3",
13+
"phpunit/phpunit": "~4.8.36",
1414
"evert/phpdoc-md" : "~0.0.7"
1515
},
1616
"autoload": {

0 commit comments

Comments
 (0)