From 7166b2ca94e7116523b0b425dbc689c3f3d10f2a Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sun, 16 Apr 2023 22:19:52 +0700 Subject: [PATCH 1/6] chore: allow phpunit 10 --- .gitignore | 1 + composer.json | 12 ++++----- phpunit.xml | 33 ++++++++++++------------ tests/BaseRollbarTest.php | 1 - tests/ConfigTest.php | 6 ++--- tests/DataBuilderTest.php | 20 +++++++------- tests/Handlers/ErrorHandlerTest.php | 4 +-- tests/Handlers/ExceptionHandlerTest.php | 4 +-- tests/JsHelperTest.php | 16 ++++++------ tests/LevelFactoryTest.php | 8 +++--- tests/NotifierTest.php | 4 +-- tests/RollbarLoggerTest.php | 10 +++---- tests/ScrubberTest.php | 32 +++++++++++------------ tests/Truncation/FramesStrategyTest.php | 2 +- tests/Truncation/MinBodyStrategyTest.php | 12 ++++----- tests/Truncation/StringsStrategyTest.php | 23 ++++++++--------- tests/Truncation/TruncationTest.php | 14 +++++----- 17 files changed, 100 insertions(+), 102 deletions(-) diff --git a/.gitignore b/.gitignore index d4e82c78..a698468f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ vendor composer.lock build .phpunit.result.cache +.phpunit.cache # Files editors may leave around that aren't related to any kind of # build artifacts diff --git a/composer.json b/composer.json index 90af9354..ba648fec 100644 --- a/composer.json +++ b/composer.json @@ -33,16 +33,16 @@ "require": { "php": ">=8.0.0 <9.0", "ext-curl": "*", - "psr/log": "^1 || ^2 || ^3", + "psr/log": "^2 || ^3", "monolog/monolog": "^2 || ^3" }, "require-dev": { - "phpunit/phpunit": "^9", - "mockery/mockery": "^1", - "squizlabs/php_codesniffer": "^3.6 || 3.x-dev", - "phpmd/phpmd" : "^2", - "vimeo/psalm": "^5" + "phpunit/phpunit": "^9.6 || ^10.1", + "mockery/mockery": "^1.5", + "squizlabs/php_codesniffer": "^3.7", + "phpmd/phpmd" : "^2.13", + "vimeo/psalm": "^5.9" }, "suggest": { diff --git a/phpunit.xml b/phpunit.xml index 51e56e66..bd0a8ece 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,30 +1,31 @@ - + ./tests/ ./tests/Performance/ + ./tests/Performance/ - + + + + + + + + ./src - - - - + + diff --git a/tests/BaseRollbarTest.php b/tests/BaseRollbarTest.php index 62f0f0f3..2bbafbe2 100644 --- a/tests/BaseRollbarTest.php +++ b/tests/BaseRollbarTest.php @@ -4,7 +4,6 @@ abstract class BaseRollbarTest extends TestCase { - const DEFAULT_ACCESS_TOKEN = 'ad865e76e7fb496fab096ac07b1dbabb'; public function tearDown(): void diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index be99c342..e090f336 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -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'); @@ -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( @@ -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( diff --git a/tests/DataBuilderTest.php b/tests/DataBuilderTest.php index 75a6a60e..ea2b7a12 100644 --- a/tests/DataBuilderTest.php +++ b/tests/DataBuilderTest.php @@ -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(); @@ -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 @@ -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 @@ -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 @@ -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 @@ -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), @@ -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), diff --git a/tests/Handlers/ErrorHandlerTest.php b/tests/Handlers/ErrorHandlerTest.php index a6b23e42..4e20a022 100644 --- a/tests/Handlers/ErrorHandlerTest.php +++ b/tests/Handlers/ErrorHandlerTest.php @@ -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()) @@ -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()) diff --git a/tests/Handlers/ExceptionHandlerTest.php b/tests/Handlers/ExceptionHandlerTest.php index 90f40724..2e9379e0 100644 --- a/tests/Handlers/ExceptionHandlerTest.php +++ b/tests/Handlers/ExceptionHandlerTest.php @@ -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()) @@ -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()) diff --git a/tests/JsHelperTest.php b/tests/JsHelperTest.php index 11a768af..875c688f 100644 --- a/tests/JsHelperTest.php +++ b/tests/JsHelperTest.php @@ -40,7 +40,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( @@ -89,7 +89,7 @@ public function testIsHtml($headers, $expected): void ); } - public function isHtmlProvider(): array + public static function isHtmlProvider(): array { return array( array( @@ -118,7 +118,7 @@ public function testHasAttachment($headers, $expected): void ); } - public function hasAttachmentProvider(): array + public static function hasAttachmentProvider(): array { return array( array( @@ -153,7 +153,7 @@ public function testShouldAppendNonce($headers, $expected): void ); } - public function shouldAppendNonceProvider(): array + public static function shouldAppendNonceProvider(): array { return array( array( @@ -198,7 +198,7 @@ public function testScriptTag($content, $headers, $nonce, $expected): void } } - public function scriptTagProvider(): array + public static function scriptTagProvider(): array { return array( 'nonce script' => array( @@ -239,7 +239,7 @@ public function testConfigJsTag($config, $expectedJson): void $this->assertEquals($expected, $result); } - public function configJsTagProvider() + public static function configJsTagProvider(): array { return array( array(array(), '{}'), @@ -254,7 +254,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, @@ -263,7 +263,7 @@ public function testBuildJs($config, $headers, $nonce, $expected): void "var customJs = true;" ); - $this->assertEquals($expected, $result); + self::assertEquals($expected, $result); } /** diff --git a/tests/LevelFactoryTest.php b/tests/LevelFactoryTest.php index 19d27e41..c242f14b 100644 --- a/tests/LevelFactoryTest.php +++ b/tests/LevelFactoryTest.php @@ -15,9 +15,9 @@ public function testIsValidLevelProvider(string $level, bool $expected): void ); } - public function isValidLevelProvider(): array + public static function isValidLevelProvider(): array { - $data = $this->fromNameProvider(); + $data = self::fromNameProvider(); foreach ($data as &$testParams) { $testParams[] = true; } @@ -41,7 +41,7 @@ public function testFromName(string $level): void ); } - public function fromNameProvider(): array + public static function fromNameProvider(): array { return [ [Level::EMERGENCY], @@ -66,7 +66,7 @@ public function testFromNameOrInstance(Level|string $level): void ); } - public function fromNameOrInstanceProvider(): array + public static function fromNameOrInstanceProvider(): array { return [ [Level::EMERGENCY], diff --git a/tests/NotifierTest.php b/tests/NotifierTest.php index fd3ed455..fd14f087 100644 --- a/tests/NotifierTest.php +++ b/tests/NotifierTest.php @@ -30,8 +30,8 @@ public function testDefaultNotifierIsRepresentableAsJson(): void $notifier = Notifier::defaultNotifier()->serialize(); $encoding = json_encode($notifier, flags: JSON_THROW_ON_ERROR|JSON_FORCE_OBJECT); $decoding = json_decode($encoding, flags: JSON_THROW_ON_ERROR); - $this->assertObjectHasAttribute('name', $decoding); - $this->assertObjectHasAttribute('version', $decoding); + $this->assertObjectHasProperty('name', $decoding); + $this->assertObjectHasProperty('version', $decoding); } public function testDefaultNotifierVersionIsSemVerCompliant(): void diff --git a/tests/RollbarLoggerTest.php b/tests/RollbarLoggerTest.php index 6440642f..04d26032 100644 --- a/tests/RollbarLoggerTest.php +++ b/tests/RollbarLoggerTest.php @@ -222,7 +222,7 @@ public function testVerbose(): void $originalHandler = $originalHandler[0]; $handlerMock = $this->getMockBuilder(ErrorLogHandler::class) - ->setMethods(array('handle')) + ->onlyMethods(array('handle')) ->getMock(); $handlerMock->setLevel($originalHandler->getLevel()); @@ -493,7 +493,7 @@ private function scrubTestAssert( } } - public function scrubDataProvider(): array + public static function scrubDataProvider(): array { return array( array( // test 1 @@ -652,9 +652,9 @@ public function testGetRequestScrubBodyContext($testData): void ); } - public function scrubQueryStringDataProvider(): array + public static function scrubQueryStringDataProvider(): array { - $data = $this->scrubDataProvider(); + $data = self::scrubDataProvider(); foreach ($data as &$test) { $test[0] = http_build_query($test[0]); @@ -757,7 +757,7 @@ public function testMaxItems($maxItemsConfig): void ); } - public function maxItemsProvider(): array + public static function maxItemsProvider(): array { return array( 'use default max_items' => array(null), diff --git a/tests/ScrubberTest.php b/tests/ScrubberTest.php index 5d19e617..af8b9c4a 100644 --- a/tests/ScrubberTest.php +++ b/tests/ScrubberTest.php @@ -7,7 +7,7 @@ class ScrubberTest extends BaseRollbarTest { - public function scrubUrlDataProvider(): array + public static function scrubUrlDataProvider(): array { return array( 'nothing to scrub' => array( @@ -40,7 +40,7 @@ public function testScrubSafelist($testData, $scrubFields, $safelist, $expected) ); } - public function scrubSafelistProvider(): array + public static function scrubSafelistProvider(): array { return array( array( @@ -96,23 +96,23 @@ public function testScrub(array $testData, array $scrubFields, array $expected): $this->assertEquals($expected, $result, "Looks like some fields did not get scrubbed correctly."); } - public function scrubDataProvider(): array + public static function scrubDataProvider(): array { return array_merge(array( 'flat data array' => - $this->scrubFlatDataProvider(), + self::scrubFlatDataProvider(), 'recursive data array' => - $this->scrubRecursiveDataProvider(), + self::scrubRecursiveDataProvider(), 'string encoded values' => - $this->scrubFlatStringDataProvider(), + self::scrubFlatStringDataProvider(), 'string encoded recursive values' => - $this->scrubRecursiveStringDataProvider(), + self::scrubRecursiveStringDataProvider(), 'string encoded recursive values in recursive array' => - $this->scrubRecursiveStringRecursiveDataProvider() - ), $this->scrubUrlDataProvider(), $this->scrubJSONNumbersProvider()); + self::scrubRecursiveStringRecursiveDataProvider() + ), self::scrubUrlDataProvider(), self::scrubJSONNumbersProvider()); } - private function scrubJSONNumbersProvider(): array + private static function scrubJSONNumbersProvider(): array { return array( 'plain array' => array( @@ -132,7 +132,7 @@ private function scrubJSONNumbersProvider(): array ); } - private function scrubFlatDataProvider(): array + private static function scrubFlatDataProvider(): array { return array( array( // $testData @@ -149,7 +149,7 @@ private function scrubFlatDataProvider(): array ); } - private function scrubRecursiveDataProvider(): array + private static function scrubRecursiveDataProvider(): array { return array( array( // $testData @@ -196,7 +196,7 @@ private function scrubRecursiveDataProvider(): array ); } - private function scrubFlatStringDataProvider(): array + private static function scrubFlatStringDataProvider(): array { return array( // $testData @@ -225,7 +225,7 @@ private function scrubFlatStringDataProvider(): array ); } - private function scrubRecursiveStringDataProvider(): array + private static function scrubRecursiveStringDataProvider(): array { return array( // $testData @@ -260,7 +260,7 @@ private function scrubRecursiveStringDataProvider(): array ); } - private function scrubRecursiveStringRecursiveDataProvider(): array + private static function scrubRecursiveStringRecursiveDataProvider(): array { return array( array( // $testData @@ -332,7 +332,7 @@ public function testScrubArray($testData, $scrubFields, $expected): void $this->assertEquals($expected, $result, "Looks like some fields did not get scrubbed correctly."); } - public function scrubArrayDataProvider(): array + public static function scrubArrayDataProvider(): array { return array( 'flat data array' => array( diff --git a/tests/Truncation/FramesStrategyTest.php b/tests/Truncation/FramesStrategyTest.php index 96ad41b5..a99f819b 100644 --- a/tests/Truncation/FramesStrategyTest.php +++ b/tests/Truncation/FramesStrategyTest.php @@ -32,7 +32,7 @@ public function testExecute(array $data, array $expected): void * * @return array */ - public function executeProvider(): array + public static function executeProvider(): array { $data = array( 'nothing to truncate using trace key' => array( diff --git a/tests/Truncation/MinBodyStrategyTest.php b/tests/Truncation/MinBodyStrategyTest.php index 6b881154..30041e7d 100644 --- a/tests/Truncation/MinBodyStrategyTest.php +++ b/tests/Truncation/MinBodyStrategyTest.php @@ -27,7 +27,7 @@ public function testExecute($data, $expected): void $this->assertEquals($expected, $result->data()); } - public function executeProvider(): array + public static function executeProvider(): array { $data = array(); @@ -52,18 +52,18 @@ public function executeProvider(): array $data['trace data set'] = array( - $this->payloadStructureProvider(array('trace' => $traceData)), - $this->payloadStructureProvider(array('trace' => $expected)) + self::payloadStructureProvider(array('trace' => $traceData)), + self::payloadStructureProvider(array('trace' => $expected)) ); $data['trace_chain data set'] = array( - $this->payloadStructureProvider(array('trace_chain' => $traceData)), - $this->payloadStructureProvider(array('trace_chain' => $expected)) + self::payloadStructureProvider(array('trace_chain' => $traceData)), + self::payloadStructureProvider(array('trace_chain' => $expected)) ); return $data; } - protected function payloadStructureProvider($body): array + protected static function payloadStructureProvider($body): array { return array( "data" => array( diff --git a/tests/Truncation/StringsStrategyTest.php b/tests/Truncation/StringsStrategyTest.php index 79ceb92a..004fb14b 100644 --- a/tests/Truncation/StringsStrategyTest.php +++ b/tests/Truncation/StringsStrategyTest.php @@ -8,7 +8,6 @@ class StringsStrategyTest extends BaseRollbarTest { - protected function execute($data): array { $config = new Config(array('access_token' => $this->getTestAccessToken())); @@ -36,13 +35,13 @@ public function testExecuteTruncateNothing($data, $expected): void * * @return array */ - public function executeTruncateNothingProvider(): array + public static function executeTruncateNothingProvider(): array { $data = array(); $data["truncate nothing"] = array( - $this->payloadStructureProvider(str_repeat("A", 10)), - $this->payloadStructureProvider(str_repeat("A", 10)) + self::payloadStructureProvider(str_repeat("A", 10)), + self::payloadStructureProvider(str_repeat("A", 10)) ); return $data; @@ -69,23 +68,23 @@ public function testExecuteArray($data, $expectedThreshold): void * * @return array */ - public function executeArrayProvider(): array + public static function executeArrayProvider(): array { $data = array(); $thresholds = StringsStrategy::getThresholds(); foreach ($thresholds as $threshold) { - $data['truncate strings to ' . $threshold] = $this->thresholdTestProvider($threshold); + $data['truncate strings to ' . $threshold] = self::thresholdTestProvider($threshold); } return $data; } - public function thresholdTestProvider($threshold): array + public static function thresholdTestProvider($threshold): array { $stringLengthToTrim = $threshold*2; - $payload = $this->payloadStructureProvider(array()); + $payload = self::payloadStructureProvider(array()); $payload['data']['body']['message']['body']['value2'] = array(); while (strlen(json_encode($payload)) <= Truncation::MAX_PAYLOAD_SIZE) { @@ -103,19 +102,19 @@ public function executeProvider(): array $data = array(); $data["truncate nothing"] = array( - $this->payloadStructureProvider(str_repeat("A", 10)), - $this->payloadStructureProvider(str_repeat("A", 10)) + self::payloadStructureProvider(str_repeat("A", 10)), + self::payloadStructureProvider(str_repeat("A", 10)) ); $thresholds = StringsStrategy::getThresholds(); foreach ($thresholds as $threshold) { - $data['truncate strings to ' . $threshold] = $this->thresholdTestProvider($threshold); + $data['truncate strings to ' . $threshold] = self::thresholdTestProvider($threshold); } return $data; } - public function payloadStructureProvider($message): array + public static function payloadStructureProvider($message): array { return array( "data" => array( diff --git a/tests/Truncation/TruncationTest.php b/tests/Truncation/TruncationTest.php index 987bb8aa..602a9fe6 100644 --- a/tests/Truncation/TruncationTest.php +++ b/tests/Truncation/TruncationTest.php @@ -48,7 +48,6 @@ public function testCustomTruncation(): void */ public function testTruncateNoPerformance($data): void { - $data = new EncodedPayload($data); $data->encode(); @@ -62,13 +61,12 @@ public function testTruncateNoPerformance($data): void ); } - public function truncateProvider(): array + public static function truncateProvider(): array { - - $stringsTest = new StringsStrategyTest(); - $framesTest = new FramesStrategyTest(); + $stringsTest = new StringsStrategyTest("StringsStrategyTest"); + $framesTest = new FramesStrategyTest("FramesStrategyTest"); - $framesTestData = $framesTest->executeProvider(); + $framesTestData = $framesTest::executeProvider(); // Fill up frames with data to go over the allowed payload size limit $frames = &$framesTestData['truncate middle using trace key'][0]['data']['body']['trace']['frames']; @@ -84,8 +82,8 @@ public function truncateProvider(): array } $data = array_merge( - $stringsTest->executeTruncateNothingProvider(), - $stringsTest->executeArrayProvider(), + $stringsTest::executeTruncateNothingProvider(), + $stringsTest::executeArrayProvider(), $framesTestData ); From 2325348417b5225adf49bead4a15022f63dcf14b Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sun, 16 Apr 2023 22:46:13 +0700 Subject: [PATCH 2/6] chore: allow phpunit 10 --- tests/JsHelperTest.php | 45 +++++++++++++++++++++++++----------------- tests/NotifierTest.php | 15 ++++++++++++-- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/tests/JsHelperTest.php b/tests/JsHelperTest.php index 875c688f..69aa4459 100644 --- a/tests/JsHelperTest.php +++ b/tests/JsHelperTest.php @@ -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() ); } @@ -85,7 +92,7 @@ public function testIsHtml($headers, $expected): void { $this->assertEquals( $expected, - $this->jsHelper->isHtml($headers) + self::$jsHelper->isHtml($headers) ); } @@ -114,7 +121,7 @@ public function testHasAttachment($headers, $expected): void { $this->assertEquals( $expected, - $this->jsHelper->hasAttachment($headers) + self::$jsHelper->hasAttachment($headers) ); } @@ -137,9 +144,9 @@ public static 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()); } /** @@ -149,7 +156,7 @@ public function testShouldAppendNonce($headers, $expected): void { $this->assertEquals( $expected, - $this->jsHelper->shouldAppendNonce($headers) + self::$jsHelper->shouldAppendNonce($headers) ); } @@ -184,7 +191,7 @@ 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) { @@ -192,7 +199,7 @@ public function testScriptTag($content, $headers, $nonce, $expected): void return; } } else { - $result = $this->jsHelper->scriptTag($content, $headers, $nonce); + $result = self::$jsHelper->scriptTag($content, $headers, $nonce); $this->assertEquals($expected, $result); } @@ -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' diff --git a/tests/NotifierTest.php b/tests/NotifierTest.php index fd14f087..a05fafc1 100644 --- a/tests/NotifierTest.php +++ b/tests/NotifierTest.php @@ -30,8 +30,19 @@ public function testDefaultNotifierIsRepresentableAsJson(): void $notifier = Notifier::defaultNotifier()->serialize(); $encoding = json_encode($notifier, flags: JSON_THROW_ON_ERROR|JSON_FORCE_OBJECT); $decoding = json_decode($encoding, flags: JSON_THROW_ON_ERROR); - $this->assertObjectHasProperty('name', $decoding); - $this->assertObjectHasProperty('version', $decoding); + + if(method_exists($this, 'assertObjectHasProperty')) + { + # phpUnit 10 + $this->assertObjectHasProperty('name', $decoding); + $this->assertObjectHasProperty('version', $decoding); + } + else + { + # phpUnit 9 + $this->assertObjectHasAttribute('name', $decoding); + $this->assertObjectHasAttribute('version', $decoding); + } } public function testDefaultNotifierVersionIsSemVerCompliant(): void From 475e5012fd29e3c1705d15abf380bd6e28dd79cc Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sun, 16 Apr 2023 22:48:32 +0700 Subject: [PATCH 3/6] chore: allow phpunit 10 --- tests/NotifierTest.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/NotifierTest.php b/tests/NotifierTest.php index a05fafc1..da5a880a 100644 --- a/tests/NotifierTest.php +++ b/tests/NotifierTest.php @@ -31,14 +31,11 @@ public function testDefaultNotifierIsRepresentableAsJson(): void $encoding = json_encode($notifier, flags: JSON_THROW_ON_ERROR|JSON_FORCE_OBJECT); $decoding = json_decode($encoding, flags: JSON_THROW_ON_ERROR); - if(method_exists($this, 'assertObjectHasProperty')) - { + if (method_exists($this, 'assertObjectHasProperty')) { # phpUnit 10 $this->assertObjectHasProperty('name', $decoding); $this->assertObjectHasProperty('version', $decoding); - } - else - { + } else { # phpUnit 9 $this->assertObjectHasAttribute('name', $decoding); $this->assertObjectHasAttribute('version', $decoding); From b1a781fd36753f1530425809101addefa864c507 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sun, 16 Apr 2023 23:26:58 +0700 Subject: [PATCH 4/6] chore: allow phpunit 10 --- composer.json | 2 +- phpunit.xml | 5 +++++ tests/FakeLog.php | 11 ----------- tests/RollbarTest.php | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) delete mode 100644 tests/FakeLog.php diff --git a/composer.json b/composer.json index ba648fec..73f53908 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,7 @@ "test": [ "phpcs --standard=PSR2 src tests", "psalm --long-progress --use-baseline=psalm.baseline", - "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", diff --git a/phpunit.xml b/phpunit.xml index bd0a8ece..254b6617 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -4,11 +4,16 @@ bootstrap="./tests/bootstrap.php" colors="true" cacheDirectory=".phpunit.cache" + defaultTestSuite="Rollbar Test Suite" > ./tests/ ./tests/Performance/ + ./tests/TestHelpers/ + ./tests/FakeDataBuilder.php + ./tests/bootstrap.php + ./tests/BaseRollbarTest.php diff --git a/tests/FakeLog.php b/tests/FakeLog.php deleted file mode 100644 index d90e49cf..00000000 --- a/tests/FakeLog.php +++ /dev/null @@ -1,11 +0,0 @@ -logUncaught('level', new \Exception); + $result = $sut::logUncaught('level', new \Exception); $expected = new Response(0, "Rollbar Not Initialized"); $this->assertEquals($expected, $result); } From 7a86663dbb85a77435a41670a9eb6c821c5c5126 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sun, 16 Apr 2023 23:35:03 +0700 Subject: [PATCH 5/6] chore: allow phpunit 10 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1781d1c9..1a19a2d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: # Our code has paths for with- and without- XDebug, and we want to test # both of them. # @see https://xdebug.org/docs/all_settings#mode - xdebug3-mode: ["xdebug.mode=develop,coverage", "xdebug.mode=coverage"] + xdebug3-mode: ['develop,coverage', 'coverage'] name: PHP ${{ matrix.php }} on ${{ matrix.os }}, ${{ matrix.dependency }} dependencies preferred runs-on: ${{ matrix.os }}-latest @@ -53,7 +53,7 @@ jobs: with: php-version: ${{ matrix.php }} extensions: curl - ini-values: zend.exception_ignore_args=Off, ${{ matrix.xdebug3-mode }} + ini-values: zend.exception_ignore_args=Off, xdebug3-mode="${{ matrix.xdebug3-mode }}" coverage: xdebug - name: Get composer cache directory From 6725840d6a8d2e9589ab9b5a02c40c48e754296b Mon Sep 17 00:00:00 2001 From: Daniel Morell Date: Sat, 29 Apr 2023 11:11:38 -0500 Subject: [PATCH 6/6] Reverted drop of psr/log v1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a5eed2fd..e72035b1 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "require": { "php": ">=8.0.0 <9.0", "ext-curl": "*", - "psr/log": "^2 || ^3", + "psr/log": "^1 || ^2 || ^3", "monolog/monolog": "^2 || ^3" },