Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: allow phpunit 10 #621

Merged
merged 7 commits into from
Apr 29, 2023
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
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
},

"require-dev": {
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^9.6 || ^10.1",
"mockery/mockery": "^1.5.1",
"squizlabs/php_codesniffer": "^3.6 || 3.x-dev",
"phpmd/phpmd" : "^2",
"vimeo/psalm": "^5"
"squizlabs/php_codesniffer": "^3.7",
"phpmd/phpmd" : "^2.13",
"vimeo/psalm": "^5.9"
},

"suggest": {
Expand All @@ -55,7 +55,7 @@
"test": [
"phpcs --standard=PSR2 src tests",
"psalm --long-progress",
"phpunit --coverage-clover build/logs/clover.xml --testsuite 'Rollbar Test Suite'"
"phpunit --coverage-clover build/logs/clover.xml"
],
"fix": "phpcbf --standard=PSR2 src tests",
"get-js-snippet": "ROLLBAR_JS_TAG=$(curl -s https://api.github.com/repos/rollbar/rollbar.js/releases/latest | sed -n 's/\"tag_name\":.*\"\\(.*\\)\",/\\1/p' | sed 's/ *//'); curl -X GET https://raw.githubusercontent.com/rollbar/rollbar.js/$ROLLBAR_JS_TAG/dist/rollbar.snippet.js > data/rollbar.snippet.js",
Expand Down
38 changes: 22 additions & 16 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./tests/bootstrap.php"
colors="true"
cacheDirectory=".phpunit.cache"
defaultTestSuite="Rollbar Test Suite"
>
<testsuites>
<testsuite name="Rollbar Test Suite">
<directory suffix=".php">./tests/</directory>
<exclude>./tests/Performance/</exclude>
<exclude>./tests/TestHelpers/</exclude>
<exclude>./tests/FakeDataBuilder.php</exclude>
<exclude>./tests/bootstrap.php</exclude>
<exclude>./tests/BaseRollbarTest.php</exclude>
</testsuite>

<testsuite name="Rollbar Performance Test Suite">
<directory suffix=".php">./tests/Performance/</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">

<coverage/>

<php>
<env name="ROLLBAR_TEST_TOKEN" value="ad865e76e7fb496fab096ac07b1dbabb"/>
</php>

<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<php>
<env name="ROLLBAR_TEST_TOKEN" value="ad865e76e7fb496fab096ac07b1dbabb" />
</php>
</source>

</phpunit>
1 change: 0 additions & 1 deletion tests/BaseRollbarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

abstract class BaseRollbarTest extends TestCase
{

const DEFAULT_ACCESS_TOKEN = 'ad865e76e7fb496fab096ac07b1dbabb';

public function tearDown(): void
Expand Down
6 changes: 3 additions & 3 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function testVerboseInfo(): void
));

$handlerMock = $this->getMockBuilder(ErrorLogHandler::class)
->setMethods(array('handle'))
->onlyMethods(array('handle'))
->getMock();

$handlerMock->expects($this->once())->method('handle');
Expand Down Expand Up @@ -721,7 +721,7 @@ public function testUseErrorReporting($use_error_reporting, $error_reporting, $e
}
}

public function useErrorReportingProvider(): array
public static function useErrorReportingProvider(): array
{
return array(
"use_error_reporting off" => array(
Expand Down Expand Up @@ -760,7 +760,7 @@ public function testExceptionSampleRate($exception, $expected): void
$this->assertEquals($expected, $sampleRate);
}

public function providerExceptionSampleRate(): array
public static function providerExceptionSampleRate(): array
{
return array(
array(
Expand Down
20 changes: 10 additions & 10 deletions tests/DataBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ public function testGetUrl($protoData, $hostData, $portData): void
$this->assertEquals($expected, $result);
}

public function getUrlProvider(): array
public static function getUrlProvider(): array
{
$protoData = $this->getUrlProtoProvider();
$hostData = $this->getUrlHostProvider();
$portData = $this->getUrlPortProvider();
$protoData = self::getUrlProtoProvider();
$hostData = self::getUrlHostProvider();
$portData = self::getUrlPortProvider();

$testData = array();

Expand Down Expand Up @@ -118,7 +118,7 @@ public function testParseForwardedString($forwaded, $expected): void
$this->assertEquals($expected, $output);
}

public function parseForwardedStringProvider(): array
public static function parseForwardedStringProvider(): array
{
return array(
array( // test 1
Expand Down Expand Up @@ -182,7 +182,7 @@ public function testGetUrlProto($data, $expected): void
$_SERVER = $pre_SERVER;
}

public function getUrlProtoProvider(): array
public static function getUrlProtoProvider(): array
{
return array(
array( // test 1: HTTP_FORWARDED
Expand Down Expand Up @@ -237,7 +237,7 @@ public function testGetUrlHost($data, $expected): void
$this->assertEquals($expected, $output);
}

public function getUrlHostProvider(): array
public static function getUrlHostProvider(): array
{
return array(
array( // test 1: HTTP_FORWARDED
Expand Down Expand Up @@ -311,7 +311,7 @@ public function testGetUrlPort($data, $expected): void
$this->assertEquals($expected, $output);
}

public function getUrlPortProvider(): array
public static function getUrlPortProvider(): array
{
return array(
array( // test 1: HTTP_X_FORWARDED
Expand Down Expand Up @@ -952,7 +952,7 @@ public function testCaptureErrorStacktracesError(
$this->assertEquals($expected, count($frames) == 0);
}

public function captureErrorStacktracesProvider(): array
public static function captureErrorStacktracesProvider(): array
{
return array(
array(false,true),
Expand Down Expand Up @@ -1002,7 +1002,7 @@ public function testGetUserIp($ipAddress, $expected, $captureIP): void
unset($_SERVER['HTTP_X_REAL_IP']);
}

public function getUserIpProvider(): array
public static function getUserIpProvider(): array
{
return array(
array('127.0.0.1', '127.0.0.1', null),
Expand Down
11 changes: 0 additions & 11 deletions tests/FakeLog.php

This file was deleted.

4 changes: 2 additions & 2 deletions tests/Handlers/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testRegister(): void
{
$handler = $this->getMockBuilder(ErrorHandler::class)
->setConstructorArgs(array(new RollbarLogger(self::$simpleConfig)))
->setMethods(array('handle'))
->onlyMethods(array('handle'))
->getMock();

$handler->expects($this->once())
Expand All @@ -57,7 +57,7 @@ public function testHandle(): void
{
$logger = $this->getMockBuilder(RollbarLogger::class)
->setConstructorArgs(array(self::$simpleConfig))
->setMethods(array('report'))
->onlyMethods(array('report'))
->getMock();

$logger->expects($this->once())
Expand Down
4 changes: 2 additions & 2 deletions tests/Handlers/ExceptionHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testSetup(): void
{
$handler = $this->getMockBuilder(ExceptionHandler::class)
->setConstructorArgs(array(new RollbarLogger(self::$simpleConfig)))
->setMethods(array('handle'))
->onlyMethods(array('handle'))
->getMock();

$handler->expects($this->once())
Expand All @@ -73,7 +73,7 @@ public function testHandle(): void

$logger = $this->getMockBuilder(RollbarLogger::class)
->setConstructorArgs(array(self::$simpleConfig))
->setMethods(array('report'))
->onlyMethods(array('report'))
->getMock();

$logger->expects($this->once())
Expand Down
61 changes: 35 additions & 26 deletions tests/JsHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@

class JsHelperTest extends BaseRollbarTest
{
protected RollbarJsHelper $jsHelper;
protected string|false $testSnippetPath;
protected static RollbarJsHelper $jsHelper;
protected static string|false $testSnippetPath = "";

public function setUp(): void
{
$this->jsHelper = new RollbarJsHelper(array());
$this->testSnippetPath = realpath(__DIR__ . "/../data/rollbar.snippet.js");
self::$jsHelper = new RollbarJsHelper(array());
self::$testSnippetPath = realpath(__DIR__ . "/../data/rollbar.snippet.js");
}


# TODO this is needed for phpUnit 10 as all Generators needs to be static
public static function init(): void
{
self::$jsHelper = new RollbarJsHelper(array());
self::$testSnippetPath = realpath(__DIR__ . "/../data/rollbar.snippet.js");
}

public function testSnippetPath(): void
{
$this->assertEquals(
$this->testSnippetPath,
$this->jsHelper->snippetPath()
self::$testSnippetPath,
self::$jsHelper->snippetPath()
);
}

Expand All @@ -40,7 +47,7 @@ public function testShouldAddJs($setup, $expected): void
$this->assertEquals($expected, $mock->shouldAddJs($status, array()));
}

public function shouldAddJsProvider(): array
public static function shouldAddJsProvider(): array
{
return array(
array(
Expand Down Expand Up @@ -85,11 +92,11 @@ public function testIsHtml($headers, $expected): void
{
$this->assertEquals(
$expected,
$this->jsHelper->isHtml($headers)
self::$jsHelper->isHtml($headers)
);
}

public function isHtmlProvider(): array
public static function isHtmlProvider(): array
{
return array(
array(
Expand All @@ -114,11 +121,11 @@ public function testHasAttachment($headers, $expected): void
{
$this->assertEquals(
$expected,
$this->jsHelper->hasAttachment($headers)
self::$jsHelper->hasAttachment($headers)
);
}

public function hasAttachmentProvider(): array
public static function hasAttachmentProvider(): array
{
return array(
array(
Expand All @@ -137,9 +144,9 @@ public function hasAttachmentProvider(): array

public function testJsSnippet(): void
{
$expected = file_get_contents($this->testSnippetPath);
$expected = file_get_contents(self::$testSnippetPath);

$this->assertEquals($expected, $this->jsHelper->jsSnippet());
$this->assertEquals($expected, self::$jsHelper->jsSnippet());
}

/**
Expand All @@ -149,11 +156,11 @@ public function testShouldAppendNonce($headers, $expected): void
{
$this->assertEquals(
$expected,
$this->jsHelper->shouldAppendNonce($headers)
self::$jsHelper->shouldAppendNonce($headers)
);
}

public function shouldAppendNonceProvider(): array
public static function shouldAppendNonceProvider(): array
{
return array(
array(
Expand Down Expand Up @@ -184,21 +191,21 @@ public function testScriptTag($content, $headers, $nonce, $expected): void
{
if ($expected === 'Exception') {
try {
$result = $this->jsHelper->scriptTag($content, $headers, $nonce);
$result = self::$jsHelper->scriptTag($content, $headers, $nonce);

$this->fail();
} catch (\Exception $e) {
$this->assertTrue(true);
return;
}
} else {
$result = $this->jsHelper->scriptTag($content, $headers, $nonce);
$result = self::$jsHelper->scriptTag($content, $headers, $nonce);

$this->assertEquals($expected, $result);
}
}

public function scriptTagProvider(): array
public static function scriptTagProvider(): array
{
return array(
'nonce script' => array(
Expand Down Expand Up @@ -239,7 +246,7 @@ public function testConfigJsTag($config, $expectedJson): void
$this->assertEquals($expected, $result);
}

public function configJsTagProvider()
public static function configJsTagProvider(): array
{
return array(
array(array(), '{}'),
Expand All @@ -254,7 +261,7 @@ public function configJsTagProvider()
/**
* @dataProvider addJsProvider
*/
public function testBuildJs($config, $headers, $nonce, $expected): void
public static function testBuildJs($config, $headers, $nonce, $expected): void
{
$result = RollbarJsHelper::buildJs(
$config,
Expand All @@ -263,7 +270,7 @@ public function testBuildJs($config, $headers, $nonce, $expected): void
"var customJs = true;"
);

$this->assertEquals($expected, $result);
self::assertEquals($expected, $result);
}

/**
Expand All @@ -281,11 +288,13 @@ public function testAddJs($config, $headers, $nonce, $expected): void

$this->assertEquals($expected, $result);
}

public function addJsProvider(): array

# TODO this is needed for phpUnit 10 as all Generators needs to be static
public static function addJsProvider(): array
{
$this->setUp();
$expectedJs = file_get_contents($this->testSnippetPath);
self::init();
$expectedJs = file_get_contents(self::$testSnippetPath);

return array(
array(
array(), // 'config'
Expand Down
Loading