From 6912ec935f8a9cbf2911d586b560ab306bda7ade Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Sun, 13 Sep 2020 21:14:41 +0200 Subject: [PATCH 01/44] Allow PHP 8 --- CHANGELOG.md | 1 + composer.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83ac5bb8c0..a345717b60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # CHANGELOG ## Unreleased +- PHP 8 support ### 2.4.3 (2020-08-13) diff --git a/composer.json b/composer.json index 3cbd5cfb15..437de4a369 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": "^7.1", + "php": "^7.1|^8.0", "ext-json": "*", "ext-mbstring": "*", "guzzlehttp/promises": "^1.3", From bc566e7397978cd223bba970d246a376d9d4e1a7 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Sun, 13 Sep 2020 21:15:03 +0200 Subject: [PATCH 02/44] Test against 8 in CI --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index d98bd6a2ca..56949ca3d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ php: - 7.2 - 7.3 - 7.4 + - 8.0 env: - dependencies=highest From 5aa5ecdd7ec74565b4c729aec198c770c913cda8 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Sun, 13 Sep 2020 21:24:02 +0200 Subject: [PATCH 03/44] Remove false positive from PHPStan ignore list --- composer.json | 2 +- phpstan.neon | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 437de4a369..6770fd8632 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "monolog/monolog": "^1.3|^2.0", "php-http/mock-client": "^1.3", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^0.12", + "phpstan/phpstan": "^0.12.42", "phpstan/phpstan-phpunit": "^0.12", "phpunit/phpunit": "^7.5.18", "symfony/phpunit-bridge": "^4.3|^5.0", diff --git a/phpstan.neon b/phpstan.neon index bbdace8dcf..9e4f1703ca 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -27,9 +27,6 @@ parameters: - message: '/^Method Sentry\\Monolog\\Handler::write\(\) has parameter \$record with no value type specified in iterable type array\.$/' path: src/Monolog/Handler.php - - - message: '/^Cannot cast array\|bool\|float\|int\|string\|null to string\.$/' - path: src/Serializer/RepresentationSerializer.php - message: '/^Method Sentry\\Client::getIntegration\(\) should return T of Sentry\\Integration\\IntegrationInterface\|null but returns Sentry\\Integration\\IntegrationInterface\|null\.$/' path: src/Client.php From b5a13c7721517e2fedabcf5687884ffd92128eb8 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Sun, 13 Sep 2020 21:33:17 +0200 Subject: [PATCH 04/44] Use nightly definition in CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 56949ca3d4..813b38bd7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ php: - 7.2 - 7.3 - 7.4 - - 8.0 + - nightly env: - dependencies=highest From e61a803c5d6070b37f0b37b7cd6e17b191499cf1 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Wed, 23 Sep 2020 15:00:17 +0200 Subject: [PATCH 05/44] Update PHPUnit to version 8.5 and remove unnecessary code left behind after updating PHP minimum required version --- .gitignore | 1 + composer.json | 4 +- src/Breadcrumb.php | 6 +- src/Exception/InvalidArgumentException.php | 15 ---- src/Serializer/AbstractSerializer.php | 3 +- tests/BreadcrumbTest.php | 16 ++-- tests/ClientBuilderTest.php | 20 ----- tests/ClientTest.php | 28 ++----- tests/Serializer/AbstractSerializerTest.php | 14 ++-- .../RepresentationSerializerTest.php | 14 ++-- tests/Serializer/SerializerTest.php | 6 +- tests/SeverityTest.php | 7 +- tests/StacktraceTest.php | 2 +- tests/Util/JSONTest.php | 73 +++---------------- 14 files changed, 50 insertions(+), 159 deletions(-) delete mode 100644 src/Exception/InvalidArgumentException.php diff --git a/.gitignore b/.gitignore index 75ef0bad07..25a58fe9cb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ package.xml /vendor .idea .php_cs.cache +.phpunit.result.cache docs/_build tests/clover.xml diff --git a/composer.json b/composer.json index 772fdb2b3f..31db4e84f9 100644 --- a/composer.json +++ b/composer.json @@ -47,8 +47,8 @@ "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^0.12", "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^7.5.18", - "symfony/phpunit-bridge": "^4.3|^5.0", + "phpunit/phpunit": "^8.5", + "symfony/phpunit-bridge": "^5.1", "vimeo/psalm": "^3.4" }, "suggest": { diff --git a/src/Breadcrumb.php b/src/Breadcrumb.php index 3b65be03fe..e29e6be251 100644 --- a/src/Breadcrumb.php +++ b/src/Breadcrumb.php @@ -4,8 +4,6 @@ namespace Sentry; -use Sentry\Exception\InvalidArgumentException; - /** * This class stores all the information about a breadcrumb. * @@ -117,7 +115,7 @@ final class Breadcrumb public function __construct(string $level, string $type, string $category, ?string $message = null, array $metadata = []) { if (!\in_array($level, self::ALLOWED_LEVELS, true)) { - throw new InvalidArgumentException('The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants.'); + throw new \InvalidArgumentException('The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants.'); } $this->type = $type; @@ -173,7 +171,7 @@ public function getLevel(): string public function withLevel(string $level): self { if (!\in_array($level, self::ALLOWED_LEVELS, true)) { - throw new InvalidArgumentException('The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants.'); + throw new \InvalidArgumentException('The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants.'); } if ($level === $this->level) { diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php deleted file mode 100644 index 711a78d68a..0000000000 --- a/src/Exception/InvalidArgumentException.php +++ /dev/null @@ -1,15 +0,0 @@ - - */ -class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface -{ -} diff --git a/src/Serializer/AbstractSerializer.php b/src/Serializer/AbstractSerializer.php index 8562eec839..532c221b7e 100644 --- a/src/Serializer/AbstractSerializer.php +++ b/src/Serializer/AbstractSerializer.php @@ -20,7 +20,6 @@ namespace Sentry\Serializer; -use Sentry\Exception\InvalidArgumentException; use Sentry\Options; /** @@ -268,7 +267,7 @@ protected function serializeCallableWithoutTypeHint($callable): string } if (!\is_callable($callable)) { - throw new InvalidArgumentException(sprintf('Expecting callable, got %s', \is_object($callable) ? \get_class($callable) : \gettype($callable))); + throw new \InvalidArgumentException(sprintf('Expecting callable, got %s', \is_object($callable) ? \get_class($callable) : \gettype($callable))); } return $this->serializeCallable($callable); diff --git a/tests/BreadcrumbTest.php b/tests/BreadcrumbTest.php index ec0684d126..7499acb422 100644 --- a/tests/BreadcrumbTest.php +++ b/tests/BreadcrumbTest.php @@ -12,21 +12,19 @@ */ final class BreadcrumbTest extends TestCase { - /** - * @expectedException \Sentry\Exception\InvalidArgumentException - * @expectedExceptionMessage The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants. - */ public function testConstructorThrowsOnInvalidLevel(): void { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants.'); + new Breadcrumb('foo', 'bar', 'baz'); } - /** - * @expectedException \Sentry\Exception\InvalidArgumentException - * @expectedExceptionMessage The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants. - */ - public function testSetLevelThrowsOnInvalidLevel(): void + public function testWithLevelThrowsOnInvalidLevel(): void { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants.'); + $breadcrumb = new Breadcrumb(Breadcrumb::LEVEL_INFO, Breadcrumb::TYPE_USER, 'foo'); $breadcrumb->withLevel('bar'); } diff --git a/tests/ClientBuilderTest.php b/tests/ClientBuilderTest.php index 7e95f8caa0..18d91b532c 100644 --- a/tests/ClientBuilderTest.php +++ b/tests/ClientBuilderTest.php @@ -11,29 +11,9 @@ use Sentry\Event; use Sentry\Integration\IntegrationInterface; use Sentry\Options; -use Sentry\Transport\HttpTransport; -use Sentry\Transport\NullTransport; final class ClientBuilderTest extends TestCase { - public function testHttpTransportIsUsedWhenServerIsConfigured(): void - { - $clientBuilder = ClientBuilder::create(['dsn' => 'http://public:secret@example.com/sentry/1']); - - $transport = $this->getObjectAttribute($clientBuilder->getClient(), 'transport'); - - $this->assertInstanceOf(HttpTransport::class, $transport); - } - - public function testNullTransportIsUsedWhenNoServerIsConfigured(): void - { - $clientBuilder = new ClientBuilder(); - - $transport = $this->getObjectAttribute($clientBuilder->getClient(), 'transport'); - - $this->assertInstanceOf(NullTransport::class, $transport); - } - public function testClientBuilderFallbacksToDefaultSdkIdentifierAndVersion(): void { $callbackCalled = false; diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 5efac86967..b9fab4d55c 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -6,8 +6,8 @@ use GuzzleHttp\Promise\FulfilledPromise; use GuzzleHttp\Promise\PromiseInterface; -use PHPUnit\Framework\MockObject\Matcher\Invocation; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Rule\InvocationOrder; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use Sentry\Client; @@ -268,7 +268,7 @@ public function testCaptureLastError(): void $this->assertNotNull($client->captureLastError()); - $this->clearLastError(); + error_clear_last(); } public function testCaptureLastErrorDoesNothingWhenThereIsNoError(): void @@ -277,14 +277,13 @@ public function testCaptureLastErrorDoesNothingWhenThereIsNoError(): void $transport = $this->createMock(TransportInterface::class); $transport->expects($this->never()) ->method('send') - ->with($this->anything()) - ->willReturn(null); + ->with($this->anything()); $client = ClientBuilder::create(['dsn' => 'http://public:secret@example.com/1']) ->setTransportFactory($this->createTransportFactory($transport)) ->getClient(); - $this->clearLastError(); + error_clear_last(); $this->assertNull($client->captureLastError()); } @@ -317,14 +316,13 @@ public function testSendChecksBeforeSendOption(): void /** * @dataProvider processEventDiscardsEventWhenItIsSampledDueToSampleRateOptionDataProvider */ - public function testProcessEventDiscardsEventWhenItIsSampledDueToSampleRateOption(float $sampleRate, Invocation $transportCallInvocationMatcher, Invocation $loggerCallInvocationMatcher): void + public function testProcessEventDiscardsEventWhenItIsSampledDueToSampleRateOption(float $sampleRate, InvocationOrder $transportCallInvocationMatcher, InvocationOrder $loggerCallInvocationMatcher): void { /** @var TransportInterface&MockObject $transport */ $transport = $this->createMock(TransportInterface::class); $transport->expects($transportCallInvocationMatcher) ->method('send') - ->with($this->anything()) - ->willReturn(null); + ->with($this->anything()); /** @var LoggerInterface&MockObject $logger */ $logger = $this->createMock(LoggerInterface::class); @@ -445,20 +443,6 @@ public function testFlush(): void $this->assertTrue($promise->wait()); } - /** - * @see https://github.com/symfony/polyfill/blob/52332f49d18c413699d2dccf465234356f8e0b2c/src/Php70/Php70.php#L52-L61 - */ - private function clearLastError(): void - { - set_error_handler(static function (): bool { - return false; - }); - - @trigger_error(''); - - restore_error_handler(); - } - private function createTransportFactory(TransportInterface $transport): TransportFactoryInterface { return new class($transport) implements TransportFactoryInterface { diff --git a/tests/Serializer/AbstractSerializerTest.php b/tests/Serializer/AbstractSerializerTest.php index 0ec7c17c80..7d421f17e9 100644 --- a/tests/Serializer/AbstractSerializerTest.php +++ b/tests/Serializer/AbstractSerializerTest.php @@ -16,7 +16,7 @@ abstract protected function createSerializer(): AbstractSerializer; /** * This method is only existed because of testSerializeCallable. */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { } @@ -331,7 +331,7 @@ public function testBrokenEncoding(bool $serializeAllObjects): void $input = pack('H*', $key); $result = $this->invokeSerialization($serializer, $input); - $this->assertInternalType('string', $result); + $this->assertIsString($result); if (\function_exists('mb_detect_encoding')) { $this->assertContains(mb_detect_encoding($result), ['ASCII', 'UTF-8']); @@ -354,7 +354,7 @@ public function testLongString(bool $serializeAllObjects): void $input = str_repeat('x', $length); $result = $this->invokeSerialization($serializer, $input); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertLessThanOrEqual(1024, \strlen($result)); } } @@ -378,7 +378,7 @@ public function testSerializeValueResource(bool $serializeAllObjects): void $result = $this->invokeSerialization($serializer, $resource); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('Resource stream', $result); } @@ -449,15 +449,15 @@ public function serializableCallableProvider(): array ], [ 'callable' => [TestCase::class, 'setUpBeforeClass'], - 'expected' => 'Callable PHPUnit\\Framework\\TestCase::setUpBeforeClass []', + 'expected' => 'Callable void PHPUnit\\Framework\\TestCase::setUpBeforeClass []', ], [ 'callable' => [$this, 'setUpBeforeClass'], - 'expected' => 'Callable ' . __CLASS__ . '::setUpBeforeClass []', + 'expected' => 'Callable void ' . __CLASS__ . '::setUpBeforeClass []', ], [ 'callable' => [self::class, 'setUpBeforeClass'], - 'expected' => 'Callable ' . __CLASS__ . '::setUpBeforeClass []', + 'expected' => 'Callable void ' . __CLASS__ . '::setUpBeforeClass []', ], [ 'callable' => [SerializerTestObject::class, 'testy'], diff --git a/tests/Serializer/RepresentationSerializerTest.php b/tests/Serializer/RepresentationSerializerTest.php index e2510759cc..8d512caecf 100644 --- a/tests/Serializer/RepresentationSerializerTest.php +++ b/tests/Serializer/RepresentationSerializerTest.php @@ -39,7 +39,7 @@ public function testIntsBecomeStrings(bool $serializeAllObjects): void $result = $serializer->representationSerialize(1); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('1', $result); } @@ -56,7 +56,7 @@ public function testFloatsBecomeStrings(bool $serializeAllObjects): void $result = $serializer->representationSerialize(1.5); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('1.5', $result); } @@ -77,7 +77,7 @@ public function testBooleansBecomeStrings(bool $serializeAllObjects): void $result = $serializer->representationSerialize(false); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('false', $result); } @@ -94,7 +94,7 @@ public function testNullsBecomeString(bool $serializeAllObjects): void $result = $serializer->representationSerialize(null); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('null', $result); } @@ -111,17 +111,17 @@ public function testSerializeRoundedFloat(bool $serializeAllObjects): void $result = $serializer->representationSerialize((float) 1); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('1.0', $result); $result = $serializer->representationSerialize(floor(5 / 2)); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('2.0', $result); $result = $serializer->representationSerialize(floor(12345.678901234)); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('12345.0', $result); } diff --git a/tests/Serializer/SerializerTest.php b/tests/Serializer/SerializerTest.php index f04e55e001..d8d7e2fd0e 100644 --- a/tests/Serializer/SerializerTest.php +++ b/tests/Serializer/SerializerTest.php @@ -40,7 +40,7 @@ public function testIntsAreInts(bool $serializeAllObjects): void $result = $this->invokeSerialization($serializer, 1); - $this->assertInternalType('integer', $result); + $this->assertIsInt($result); $this->assertSame(1, $result); } @@ -57,7 +57,7 @@ public function testFloats(bool $serializeAllObjects): void $result = $this->invokeSerialization($serializer, 1.5); - $this->assertInternalType('double', $result); + $this->assertIsFloat($result); $this->assertSame(1.5, $result); } @@ -174,7 +174,7 @@ public function testLongStringWithOverwrittenMessageLength(): void $input = str_repeat('x', $length); $result = $this->invokeSerialization($serializer, $input); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertLessThanOrEqual(500, \strlen($result)); } } diff --git a/tests/SeverityTest.php b/tests/SeverityTest.php index c6c000a4dc..661088cabf 100644 --- a/tests/SeverityTest.php +++ b/tests/SeverityTest.php @@ -9,12 +9,11 @@ final class SeverityTest extends TestCase { - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The "foo" is not a valid enum value. - */ public function testConstructorThrowsOnInvalidValue(): void { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The "foo" is not a valid enum value.'); + new Severity('foo'); } diff --git a/tests/StacktraceTest.php b/tests/StacktraceTest.php index b050142763..e3de8fa7e7 100644 --- a/tests/StacktraceTest.php +++ b/tests/StacktraceTest.php @@ -27,7 +27,7 @@ public function testConstructorThrowsIfFramesListIsEmpty(): void public function testConstructorThrowsIfFramesListContainsUnexpectedValue(array $values, string $expectedExceptionMessage): void { $this->expectException(\UnexpectedValueException::class); - $this->expectExceptionMessageRegExp($expectedExceptionMessage); + $this->expectExceptionMessageMatches($expectedExceptionMessage); new Stacktrace($values); } diff --git a/tests/Util/JSONTest.php b/tests/Util/JSONTest.php index f8c60c2d87..78b4f6aa2f 100644 --- a/tests/Util/JSONTest.php +++ b/tests/Util/JSONTest.php @@ -5,6 +5,7 @@ namespace Sentry\Tests\Util; use PHPUnit\Framework\TestCase; +use Sentry\Exception\JsonException; use Sentry\Tests\Util\Fixtures\JsonSerializableClass; use Sentry\Tests\Util\Fixtures\SimpleClass; use Sentry\Util\JSON; @@ -62,16 +63,14 @@ public function encodeDataProvider(): \Generator } /** - * @requires PHP >= 7.2 - * - * @dataProvider encodeSubstitutesInvalidUtf8CharactersOnPhp72OrGreaterDataProvider + * @dataProvider encodeSubstitutesInvalidUtf8CharactersDataProvider */ - public function testEncodeSubstitutesInvalidUtf8CharactersOnPhp72OrGreater($value, string $expectedResult): void + public function testEncodeSubstitutesInvalidUtf8Characters($value, string $expectedResult): void { $this->assertSame($expectedResult, JSON::encode($value)); } - public function encodeSubstitutesInvalidUtf8CharactersOnPhp72OrGreaterDataProvider(): \Generator + public function encodeSubstitutesInvalidUtf8CharactersDataProvider(): \Generator { yield [ "\x61\xb0\x62", @@ -100,49 +99,6 @@ public function encodeSubstitutesInvalidUtf8CharactersOnPhp72OrGreaterDataProvid ]; } - /** - * @requires PHP < 7.2 - * - * @dataProvider encodeSubstitutesInvalidUtf8CharactersOnPhp71OrLowerDataProvider - */ - public function testEncodeSubstitutesInvalidUtf8CharactersOnPhp71OrLower($value, string $expectedResult): void - { - $this->assertSame($expectedResult, JSON::encode($value)); - } - - public function encodeSubstitutesInvalidUtf8CharactersOnPhp71OrLowerDataProvider(): \Generator - { - yield [ - "\x61\xb0\x62", - '"a�b"', - ]; - - yield [ - "\x61\xf0\x80\x80\x41", - '"a���A"', - ]; - - yield [ - [ - 123.45, - 'foo', - "\x61\xb0\x62", - [ - 'bar' => "\x61\xf0\x80\x80\x41", - "\x61\xf0\x80\x80\x41" => (object) [ - "\x61\xb0\x62", - "\x61\xf0\x80\x80\x41" => 'baz', - ], - ], - ], - '[123.45,"foo","a�b",{"bar":"a���A","a���A":{"0":"a�b","a���A":"baz"}}]', - ]; - } - - /** - * @expectedException \Sentry\Exception\JsonException - * @expectedExceptionMessage Could not encode value into JSON format. Error was: "Type is not supported". - */ public function testEncodeThrowsIfValueIsResource(): void { $resource = fopen('php://memory', 'r'); @@ -151,6 +107,9 @@ public function testEncodeThrowsIfValueIsResource(): void fclose($resource); + $this->expectException(JsonException::class); + $this->expectExceptionMessage('Could not encode value into JSON format. Error was: "Type is not supported".'); + JSON::encode($resource); } @@ -159,17 +118,6 @@ public function testEncodeRespectsOptionsArgument(): void $this->assertSame('{}', JSON::encode([], JSON_FORCE_OBJECT)); } - /** - * @requires PHP < 7.2 - * - * @expectedException \Sentry\Exception\JsonException - * @expectedExceptionMessage Reached the maximum depth limit while sanitizing the data. - */ - public function testEncodeThrowsOnPhp71OrLowerWhenSanitizationReachesMaxDepthLimit(): void - { - JSON::encode([[["\x61\xb0\x62"]]], 0, 2); - } - /** * @dataProvider decodeDataProvider */ @@ -203,12 +151,11 @@ public function decodeDataProvider(): \Generator ]; } - /** - * @expectedException \Sentry\Exception\JsonException - * @expectedExceptionMessage Could not decode value from JSON format. Error was: "Syntax error". - */ public function testDecodeThrowsIfValueIsNotValidJson(): void { + $this->expectException(JsonException::class); + $this->expectExceptionMessage('Could not decode value from JSON format. Error was: "Syntax error".'); + JSON::decode('foo'); } } From f61343e970ae6decf6727ffad7e4c3aa5b23f454 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Wed, 23 Sep 2020 18:55:53 +0200 Subject: [PATCH 06/44] Fix CR issues --- composer.json | 2 +- phpstan.neon | 3 -- src/Util/JSON.php | 87 ++--------------------------------------------- 3 files changed, 3 insertions(+), 89 deletions(-) diff --git a/composer.json b/composer.json index 31db4e84f9..bd2055cbe1 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^0.12", "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^8.5", + "phpunit/phpunit": "^8.5|^9.3", "symfony/phpunit-bridge": "^5.1", "vimeo/psalm": "^3.4" }, diff --git a/phpstan.neon b/phpstan.neon index 8e883fb310..5d724909aa 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,9 +6,6 @@ parameters: - src ignoreErrors: - '/Argument of an invalid type object supplied for foreach, only iterables are supported/' - - - message: '/^Argument of an invalid type array\|object supplied for foreach, only iterables are supported\.$/' - path: src/Util/JSON.php - message: '/^Access to constant (?:PROXY|TIMEOUT|CONNECT_TIMEOUT) on an unknown class GuzzleHttp\\RequestOptions\.$/' path: src/HttpClient/HttpClientFactory.php diff --git a/src/Util/JSON.php b/src/Util/JSON.php index 1cd4685ddc..5e0b7bb6a7 100644 --- a/src/Util/JSON.php +++ b/src/Util/JSON.php @@ -28,22 +28,9 @@ final class JSON */ public static function encode($data, int $options = 0, int $maxDepth = 512) { - $options |= JSON_UNESCAPED_UNICODE; + $options |= JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE; - if (\PHP_VERSION_ID >= 70200) { - /** @psalm-suppress UndefinedConstant */ - $options |= JSON_INVALID_UTF8_SUBSTITUTE; - } - - $encodedData = json_encode($data, $options); - - // This should never happen on PHP >= 7.2 as the substitution of invalid - // UTF-8 characters is done internally. On lower versions instead, we - // try to sanitize the data ourselves before retrying encoding. If it - // fails again we throw an exception as usual. - if (JSON_ERROR_UTF8 === json_last_error()) { - $encodedData = json_encode(self::sanitizeData($data, $maxDepth - 1), $options); - } + $encodedData = json_encode($data, $options, $maxDepth); if (JSON_ERROR_NONE !== json_last_error()) { throw new JsonException(sprintf('Could not encode value into JSON format. Error was: "%s".', json_last_error_msg())); @@ -71,74 +58,4 @@ public static function decode(string $data) return $decodedData; } - - /** - * Performs sanity checks on data that shall be encoded to JSON. - * - * @param mixed $data The data to sanitize - * @param int $maxDepth The maximum depth to walk through `$data` - * - * @return mixed - * - * @throws JsonException If the value of $maxDepth is less than 0 - */ - private static function sanitizeData($data, int $maxDepth) - { - if ($maxDepth < 0) { - throw new JsonException('Reached the maximum depth limit while sanitizing the data.'); - } - - if (\is_string($data)) { - return self::convertStringToUtf8($data); - } elseif (\is_array($data) || \is_object($data)) { - $output = []; - - foreach ($data as $key => $value) { - if (\is_string($key)) { - $key = self::convertStringToUtf8($key); - } - - if (\is_string($value)) { - $value = self::convertStringToUtf8($value); - } elseif (\is_array($value) || \is_object($value)) { - // This check is here because the `Event::toArray()` method - // is broken and doesn't return all child items as scalars - // or objects/arrays, so the sanitification would fail (e.g. - // on breadcrumb objects which do not expose public properties - // to iterate on) - if (\is_object($value) && method_exists($value, 'toArray')) { - $value = $value->toArray(); - } - - $value = self::sanitizeData($value, $maxDepth - 1); - } - - $output[$key] = $value; - } - - return \is_array($data) ? $output : (object) $output; - } else { - return $data; - } - } - - /** - * Converts a string to UTF-8 to avoid errors during its encoding to - * the JSON format. - * - * @param string $value The text to convert to UTF-8 - */ - private static function convertStringToUtf8(string $value): string - { - $previousSubstituteCharacter = mb_substitute_character(); - $encoding = mb_detect_encoding($value, mb_detect_order(), true); - - mb_substitute_character(0xfffd); - - $value = mb_convert_encoding($value, 'UTF-8', $encoding ?: 'UTF-8'); - - mb_substitute_character($previousSubstituteCharacter); - - return $value; - } } From 0e4159f0afeafa38e0dc05e90f848298fd25f18a Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 27 Oct 2020 16:06:27 +0100 Subject: [PATCH 07/44] Fix PHPStan error --- phpstan.neon | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 5d724909aa..0820667503 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -12,9 +12,6 @@ parameters: - message: '/^Call to static method create\(\) on an unknown class Symfony\\Component\\HttpClient\\HttpClient\.$/' path: src/HttpClient/HttpClientFactory.php - - - message: '/^Parameter #1 \$c of function ctype_digit expects int\|string, string\|null given\.$/' - path: src/Dsn.php - message: "/^Offset 'scheme' does not exist on array\\(\\?'scheme' => string, \\?'host' => string, \\?'port' => int, \\?'user' => string, \\?'pass' => string, \\?'path' => string, \\?'query' => string, \\?'fragment' => string\\)\\.$/" path: src/Dsn.php From b39abe007d6ff1519a65e883e16b39927f29e84c Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 28 Oct 2020 16:31:40 +0100 Subject: [PATCH 08/44] Try to remove PHPCSFixer under PHP 8 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3bd8f7beaf..d329cfb760 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,6 +35,7 @@ jobs: script: composer psalm install: + - if [ "$TRAVIS_PHP_VERSION" = "nightly" ]; then composer remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction --no-suggest - if [ "$dependencies" = "lowest" ]; then composer update --no-interaction --no-suggest --prefer-lowest --prefer-dist; fi; - if [ "$dependencies" = "highest" ]; then composer update --no-interaction --no-suggest --prefer-dist; fi; From 770523050b1bb1f67b8e0480b75a4ee45238fba8 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 29 Oct 2020 09:46:47 +0100 Subject: [PATCH 09/44] Fix if statement --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d329cfb760..6597c2ad24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ jobs: script: composer psalm install: - - if [ "$TRAVIS_PHP_VERSION" = "nightly" ]; then composer remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction --no-suggest + - if [ "$TRAVIS_PHP_VERSION" = "nightly" ]; then composer remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction --no-suggest; fi; - if [ "$dependencies" = "lowest" ]; then composer update --no-interaction --no-suggest --prefer-lowest --prefer-dist; fi; - if [ "$dependencies" = "highest" ]; then composer update --no-interaction --no-suggest --prefer-dist; fi; From 7faa5326f796ff916c1b90f8af8c32060ebcbd97 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 29 Oct 2020 11:20:57 +0100 Subject: [PATCH 10/44] Fix composer command --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6597c2ad24..db99a891f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ jobs: script: composer psalm install: - - if [ "$TRAVIS_PHP_VERSION" = "nightly" ]; then composer remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction --no-suggest; fi; + - if [ "$TRAVIS_PHP_VERSION" = "nightly" ]; then composer remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction; fi; - if [ "$dependencies" = "lowest" ]; then composer update --no-interaction --no-suggest --prefer-lowest --prefer-dist; fi; - if [ "$dependencies" = "highest" ]; then composer update --no-interaction --no-suggest --prefer-dist; fi; From de3e9acb8fc7d8fbc16e4446892b3de7c690c508 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 29 Oct 2020 12:27:42 +0100 Subject: [PATCH 11/44] Update PHPUnit --- composer.json | 4 ++-- tests/BreadcrumbTest.php | 15 +++++++-------- tests/ClientBuilderTest.php | 16 ++++++++++++++-- tests/ClientTest.php | 10 ++++------ tests/Serializer/AbstractSerializerTest.php | 14 +++++++------- .../Serializer/RepresentationSerializerTest.php | 14 +++++++------- tests/Serializer/SerializerTest.php | 6 +++--- tests/SeverityTest.php | 7 +++---- tests/StacktraceTest.php | 2 +- tests/Util/JSONTest.php | 15 +++++++-------- 10 files changed, 55 insertions(+), 48 deletions(-) diff --git a/composer.json b/composer.json index 75ce5ca23d..9f17d2f586 100644 --- a/composer.json +++ b/composer.json @@ -47,8 +47,8 @@ "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^0.12.42", "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^7.5.18", - "symfony/phpunit-bridge": "^4.3|^5.0", + "phpunit/phpunit": "^8.5.8|^9.4.2", + "symfony/phpunit-bridge": "^5.1", "vimeo/psalm": "^3.4" }, "suggest": { diff --git a/tests/BreadcrumbTest.php b/tests/BreadcrumbTest.php index ec0684d126..12a9d1fe0b 100644 --- a/tests/BreadcrumbTest.php +++ b/tests/BreadcrumbTest.php @@ -6,27 +6,26 @@ use PHPUnit\Framework\TestCase; use Sentry\Breadcrumb; +use Sentry\Exception\InvalidArgumentException; /** * @group time-sensitive */ final class BreadcrumbTest extends TestCase { - /** - * @expectedException \Sentry\Exception\InvalidArgumentException - * @expectedExceptionMessage The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants. - */ public function testConstructorThrowsOnInvalidLevel(): void { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants.'); + new Breadcrumb('foo', 'bar', 'baz'); } - /** - * @expectedException \Sentry\Exception\InvalidArgumentException - * @expectedExceptionMessage The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants. - */ public function testSetLevelThrowsOnInvalidLevel(): void { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants.'); + $breadcrumb = new Breadcrumb(Breadcrumb::LEVEL_INFO, Breadcrumb::TYPE_USER, 'foo'); $breadcrumb->withLevel('bar'); } diff --git a/tests/ClientBuilderTest.php b/tests/ClientBuilderTest.php index 7e95f8caa0..2f123c9b22 100644 --- a/tests/ClientBuilderTest.php +++ b/tests/ClientBuilderTest.php @@ -13,6 +13,7 @@ use Sentry\Options; use Sentry\Transport\HttpTransport; use Sentry\Transport\NullTransport; +use Sentry\Transport\TransportInterface; final class ClientBuilderTest extends TestCase { @@ -20,7 +21,7 @@ public function testHttpTransportIsUsedWhenServerIsConfigured(): void { $clientBuilder = ClientBuilder::create(['dsn' => 'http://public:secret@example.com/sentry/1']); - $transport = $this->getObjectAttribute($clientBuilder->getClient(), 'transport'); + $transport = $this->getTransport($clientBuilder->getClient()); $this->assertInstanceOf(HttpTransport::class, $transport); } @@ -29,7 +30,7 @@ public function testNullTransportIsUsedWhenNoServerIsConfigured(): void { $clientBuilder = new ClientBuilder(); - $transport = $this->getObjectAttribute($clientBuilder->getClient(), 'transport'); + $transport = $this->getTransport($clientBuilder->getClient()); $this->assertInstanceOf(NullTransport::class, $transport); } @@ -84,6 +85,17 @@ public function testCreateWithNoOptionsIsTheSameAsDefaultOptions(): void ClientBuilder::create([]) ); } + + private function getTransport(Client $client): TransportInterface + { + $property = new \ReflectionProperty(Client::class, 'transport'); + + $property->setAccessible(true); + $value = $property->getValue($client); + $property->setAccessible(false); + + return $value; + } } final class StubIntegration implements IntegrationInterface diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 137b01aeec..062d743853 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -6,8 +6,8 @@ use GuzzleHttp\Promise\FulfilledPromise; use GuzzleHttp\Promise\PromiseInterface; -use PHPUnit\Framework\MockObject\Matcher\Invocation; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Rule\InvokedCount; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use Sentry\Client; @@ -280,8 +280,7 @@ public function testCaptureLastErrorDoesNothingWhenThereIsNoError(): void $transport = $this->createMock(TransportInterface::class); $transport->expects($this->never()) ->method('send') - ->with($this->anything()) - ->willReturn(null); + ->with($this->anything()); $client = ClientBuilder::create(['dsn' => 'http://public:secret@example.com/1']) ->setTransportFactory($this->createTransportFactory($transport)) @@ -320,14 +319,13 @@ public function testSendChecksBeforeSendOption(): void /** * @dataProvider processEventDiscardsEventWhenItIsSampledDueToSampleRateOptionDataProvider */ - public function testProcessEventDiscardsEventWhenItIsSampledDueToSampleRateOption(float $sampleRate, Invocation $transportCallInvocationMatcher, Invocation $loggerCallInvocationMatcher): void + public function testProcessEventDiscardsEventWhenItIsSampledDueToSampleRateOption(float $sampleRate, InvokedCount $transportCallInvocationMatcher, InvokedCount $loggerCallInvocationMatcher): void { /** @var TransportInterface&MockObject $transport */ $transport = $this->createMock(TransportInterface::class); $transport->expects($transportCallInvocationMatcher) ->method('send') - ->with($this->anything()) - ->willReturn(null); + ->with($this->anything()); /** @var LoggerInterface&MockObject $logger */ $logger = $this->createMock(LoggerInterface::class); diff --git a/tests/Serializer/AbstractSerializerTest.php b/tests/Serializer/AbstractSerializerTest.php index 0ec7c17c80..7d421f17e9 100644 --- a/tests/Serializer/AbstractSerializerTest.php +++ b/tests/Serializer/AbstractSerializerTest.php @@ -16,7 +16,7 @@ abstract protected function createSerializer(): AbstractSerializer; /** * This method is only existed because of testSerializeCallable. */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { } @@ -331,7 +331,7 @@ public function testBrokenEncoding(bool $serializeAllObjects): void $input = pack('H*', $key); $result = $this->invokeSerialization($serializer, $input); - $this->assertInternalType('string', $result); + $this->assertIsString($result); if (\function_exists('mb_detect_encoding')) { $this->assertContains(mb_detect_encoding($result), ['ASCII', 'UTF-8']); @@ -354,7 +354,7 @@ public function testLongString(bool $serializeAllObjects): void $input = str_repeat('x', $length); $result = $this->invokeSerialization($serializer, $input); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertLessThanOrEqual(1024, \strlen($result)); } } @@ -378,7 +378,7 @@ public function testSerializeValueResource(bool $serializeAllObjects): void $result = $this->invokeSerialization($serializer, $resource); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('Resource stream', $result); } @@ -449,15 +449,15 @@ public function serializableCallableProvider(): array ], [ 'callable' => [TestCase::class, 'setUpBeforeClass'], - 'expected' => 'Callable PHPUnit\\Framework\\TestCase::setUpBeforeClass []', + 'expected' => 'Callable void PHPUnit\\Framework\\TestCase::setUpBeforeClass []', ], [ 'callable' => [$this, 'setUpBeforeClass'], - 'expected' => 'Callable ' . __CLASS__ . '::setUpBeforeClass []', + 'expected' => 'Callable void ' . __CLASS__ . '::setUpBeforeClass []', ], [ 'callable' => [self::class, 'setUpBeforeClass'], - 'expected' => 'Callable ' . __CLASS__ . '::setUpBeforeClass []', + 'expected' => 'Callable void ' . __CLASS__ . '::setUpBeforeClass []', ], [ 'callable' => [SerializerTestObject::class, 'testy'], diff --git a/tests/Serializer/RepresentationSerializerTest.php b/tests/Serializer/RepresentationSerializerTest.php index e2510759cc..8d512caecf 100644 --- a/tests/Serializer/RepresentationSerializerTest.php +++ b/tests/Serializer/RepresentationSerializerTest.php @@ -39,7 +39,7 @@ public function testIntsBecomeStrings(bool $serializeAllObjects): void $result = $serializer->representationSerialize(1); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('1', $result); } @@ -56,7 +56,7 @@ public function testFloatsBecomeStrings(bool $serializeAllObjects): void $result = $serializer->representationSerialize(1.5); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('1.5', $result); } @@ -77,7 +77,7 @@ public function testBooleansBecomeStrings(bool $serializeAllObjects): void $result = $serializer->representationSerialize(false); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('false', $result); } @@ -94,7 +94,7 @@ public function testNullsBecomeString(bool $serializeAllObjects): void $result = $serializer->representationSerialize(null); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('null', $result); } @@ -111,17 +111,17 @@ public function testSerializeRoundedFloat(bool $serializeAllObjects): void $result = $serializer->representationSerialize((float) 1); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('1.0', $result); $result = $serializer->representationSerialize(floor(5 / 2)); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('2.0', $result); $result = $serializer->representationSerialize(floor(12345.678901234)); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertSame('12345.0', $result); } diff --git a/tests/Serializer/SerializerTest.php b/tests/Serializer/SerializerTest.php index f04e55e001..d8d7e2fd0e 100644 --- a/tests/Serializer/SerializerTest.php +++ b/tests/Serializer/SerializerTest.php @@ -40,7 +40,7 @@ public function testIntsAreInts(bool $serializeAllObjects): void $result = $this->invokeSerialization($serializer, 1); - $this->assertInternalType('integer', $result); + $this->assertIsInt($result); $this->assertSame(1, $result); } @@ -57,7 +57,7 @@ public function testFloats(bool $serializeAllObjects): void $result = $this->invokeSerialization($serializer, 1.5); - $this->assertInternalType('double', $result); + $this->assertIsFloat($result); $this->assertSame(1.5, $result); } @@ -174,7 +174,7 @@ public function testLongStringWithOverwrittenMessageLength(): void $input = str_repeat('x', $length); $result = $this->invokeSerialization($serializer, $input); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertLessThanOrEqual(500, \strlen($result)); } } diff --git a/tests/SeverityTest.php b/tests/SeverityTest.php index c6c000a4dc..661088cabf 100644 --- a/tests/SeverityTest.php +++ b/tests/SeverityTest.php @@ -9,12 +9,11 @@ final class SeverityTest extends TestCase { - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The "foo" is not a valid enum value. - */ public function testConstructorThrowsOnInvalidValue(): void { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The "foo" is not a valid enum value.'); + new Severity('foo'); } diff --git a/tests/StacktraceTest.php b/tests/StacktraceTest.php index b050142763..e3de8fa7e7 100644 --- a/tests/StacktraceTest.php +++ b/tests/StacktraceTest.php @@ -27,7 +27,7 @@ public function testConstructorThrowsIfFramesListIsEmpty(): void public function testConstructorThrowsIfFramesListContainsUnexpectedValue(array $values, string $expectedExceptionMessage): void { $this->expectException(\UnexpectedValueException::class); - $this->expectExceptionMessageRegExp($expectedExceptionMessage); + $this->expectExceptionMessageMatches($expectedExceptionMessage); new Stacktrace($values); } diff --git a/tests/Util/JSONTest.php b/tests/Util/JSONTest.php index 3489182ddb..78b4f6aa2f 100644 --- a/tests/Util/JSONTest.php +++ b/tests/Util/JSONTest.php @@ -5,6 +5,7 @@ namespace Sentry\Tests\Util; use PHPUnit\Framework\TestCase; +use Sentry\Exception\JsonException; use Sentry\Tests\Util\Fixtures\JsonSerializableClass; use Sentry\Tests\Util\Fixtures\SimpleClass; use Sentry\Util\JSON; @@ -98,10 +99,6 @@ public function encodeSubstitutesInvalidUtf8CharactersDataProvider(): \Generator ]; } - /** - * @expectedException \Sentry\Exception\JsonException - * @expectedExceptionMessage Could not encode value into JSON format. Error was: "Type is not supported". - */ public function testEncodeThrowsIfValueIsResource(): void { $resource = fopen('php://memory', 'r'); @@ -110,6 +107,9 @@ public function testEncodeThrowsIfValueIsResource(): void fclose($resource); + $this->expectException(JsonException::class); + $this->expectExceptionMessage('Could not encode value into JSON format. Error was: "Type is not supported".'); + JSON::encode($resource); } @@ -151,12 +151,11 @@ public function decodeDataProvider(): \Generator ]; } - /** - * @expectedException \Sentry\Exception\JsonException - * @expectedExceptionMessage Could not decode value from JSON format. Error was: "Syntax error". - */ public function testDecodeThrowsIfValueIsNotValidJson(): void { + $this->expectException(JsonException::class); + $this->expectExceptionMessage('Could not decode value from JSON format. Error was: "Syntax error".'); + JSON::decode('foo'); } } From e9cc1a66cec57bd69368c8d0cf4b631da7f11dd8 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 29 Oct 2020 12:28:14 +0100 Subject: [PATCH 12/44] Ignore PHPUnit cache --- .gitignore | 1 + phpunit.xml.dist | 1 + 2 files changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 75ef0bad07..25a58fe9cb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ package.xml /vendor .idea .php_cs.cache +.phpunit.result.cache docs/_build tests/clover.xml diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8c633d455d..ee7bc098e1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,6 +5,7 @@ backupGlobals="true" colors="true" bootstrap="tests/bootstrap.php" + cacheResult="false" > From 020e2a425633c4530a156d127e86883bd61c16e8 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 29 Oct 2020 12:35:38 +0100 Subject: [PATCH 13/44] Update Psalm --- composer.json | 2 +- psalm.xml.dist | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 9f17d2f586..18b29cc26d 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ "phpstan/phpstan-phpunit": "^0.12", "phpunit/phpunit": "^8.5.8|^9.4.2", "symfony/phpunit-bridge": "^5.1", - "vimeo/psalm": "^3.4" + "vimeo/psalm": "^4.0" }, "suggest": { "monolog/monolog": "Allow sending log messages to Sentry by using the included Monolog handler." diff --git a/psalm.xml.dist b/psalm.xml.dist index 34d01006db..e1cbbfde23 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -34,7 +34,6 @@ - From ba682ab72ee82232e52776ab65ffaa17463aa77b Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 29 Oct 2020 12:51:36 +0100 Subject: [PATCH 14/44] Allow older Psalm too --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 18b29cc26d..23419e8adf 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ "phpstan/phpstan-phpunit": "^0.12", "phpunit/phpunit": "^8.5.8|^9.4.2", "symfony/phpunit-bridge": "^5.1", - "vimeo/psalm": "^4.0" + "vimeo/psalm": "^3.4|^4.0" }, "suggest": { "monolog/monolog": "Allow sending log messages to Sentry by using the included Monolog handler." From 50fe13510f29de225616a816faa25415fd363795 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 29 Oct 2020 14:52:15 +0100 Subject: [PATCH 15/44] Migrate PHPUnit config --- phpunit.xml.dist | 59 +++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ee7bc098e1..86c1f1dea5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,34 +1,31 @@ - - - - - - - - - tests - tests/phpt - - - - - - src - - - - - - - - - - + + + src + + + + + + + + tests + tests/phpt + + + + + + + + From a1c89287cf61887fb3392de83f3b2448af85828e Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 29 Oct 2020 17:40:52 +0100 Subject: [PATCH 16/44] Fix PHPT tests --- .../error_handler_can_be_registered_once.phpt | 28 +++++++++++++------ ...eption_rethrown_from_previous_handler.phpt | 3 +- ...handler_only_error_handler_registered.phpt | 17 +++++++---- ...ler_only_exception_handler_registered.phpt | 17 +++++++---- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/tests/phpt/error_handler_can_be_registered_once.phpt b/tests/phpt/error_handler_can_be_registered_once.phpt index 4a1c9ad277..6cc0da4bde 100644 --- a/tests/phpt/error_handler_can_be_registered_once.phpt +++ b/tests/phpt/error_handler_can_be_registered_once.phpt @@ -24,7 +24,7 @@ function getHandlerRegistrationCount(callable $setHandlerCallback, callable $res $previousErrorHandler = null; while (true) { - $errorHandler = call_user_func($setHandlerCallback, 'var_dump'); + $errorHandler = call_user_func($setHandlerCallback, 'print_r'); // Restore the error handler that has been popped out from the stack with // the line above @@ -52,14 +52,24 @@ function getHandlerRegistrationCount(callable $setHandlerCallback, callable $res return count($savedErrorHandlers); } -var_dump(ErrorHandler::registerOnceErrorHandler() === ErrorHandler::registerOnceErrorHandler()); -var_dump(1 === getHandlerRegistrationCount('set_error_handler', 'restore_error_handler')); +if (ErrorHandler::registerOnceErrorHandler() === ErrorHandler::registerOnceErrorHandler()) { + echo 'Error handler is a singleton' . PHP_EOL; +} + +if (1 === getHandlerRegistrationCount('set_error_handler', 'restore_error_handler')) { + echo 'Only one error handler is registered' . PHP_EOL; +} -var_dump(ErrorHandler::registerOnceExceptionHandler() === ErrorHandler::registerOnceExceptionHandler()); -var_dump(1 === getHandlerRegistrationCount('set_exception_handler', 'restore_exception_handler')); +if (ErrorHandler::registerOnceExceptionHandler() === ErrorHandler::registerOnceExceptionHandler()) { + echo 'Exception handler is a singleton' . PHP_EOL; +} + +if (1 === getHandlerRegistrationCount('set_exception_handler', 'restore_exception_handler')) { + echo 'Only one exception handler is registered' . PHP_EOL; +} ?> --EXPECT-- -bool(true) -bool(true) -bool(true) -bool(true) +Error handler is a singleton +Only one error handler is registered +Exception handler is a singleton +Only one exception handler is registered diff --git a/tests/phpt/error_handler_captures_exception_rethrown_from_previous_handler.phpt b/tests/phpt/error_handler_captures_exception_rethrown_from_previous_handler.phpt index dda9b6e9f7..15047a08d6 100644 --- a/tests/phpt/error_handler_captures_exception_rethrown_from_previous_handler.phpt +++ b/tests/phpt/error_handler_captures_exception_rethrown_from_previous_handler.phpt @@ -40,6 +40,5 @@ throw new \Exception('foo bar'); Exception listener called Custom exception handler called -Fatal error: Uncaught Exception: foo bar in %s:%d -Stack trace: +Fatal error: Uncaught Exception: foo bar in %s %a diff --git a/tests/phpt/error_handler_only_error_handler_registered.phpt b/tests/phpt/error_handler_only_error_handler_registered.phpt index 2975e228b1..57d447c4f8 100644 --- a/tests/phpt/error_handler_only_error_handler_registered.phpt +++ b/tests/phpt/error_handler_only_error_handler_registered.phpt @@ -19,15 +19,20 @@ require $vendor . '/vendor/autoload.php'; ErrorHandler::registerOnceErrorHandler(); -$previousErrorHandler = set_error_handler('var_dump'); -$previousExceptionHandler = set_exception_handler('var_dump'); +$previousErrorHandler = set_error_handler('print_r'); +$previousExceptionHandler = set_exception_handler('print_r'); restore_error_handler(); restore_exception_handler(); -var_dump(null !== $previousErrorHandler); -var_dump(null !== $previousExceptionHandler); +if (null !== $previousErrorHandler) { + echo 'Previous error handler is present' . PHP_EOL; +} + +if (null === $previousExceptionHandler) { + echo 'Previous exception handler is NOT present' . PHP_EOL; +} ?> --EXPECT-- -bool(true) -bool(false) +Previous error handler is present +Previous exception handler is NOT present diff --git a/tests/phpt/error_handler_only_exception_handler_registered.phpt b/tests/phpt/error_handler_only_exception_handler_registered.phpt index 5ed972abbf..422ea2e261 100644 --- a/tests/phpt/error_handler_only_exception_handler_registered.phpt +++ b/tests/phpt/error_handler_only_exception_handler_registered.phpt @@ -19,15 +19,20 @@ require $vendor . '/vendor/autoload.php'; ErrorHandler::registerOnceExceptionHandler(); -$previousErrorHandler = set_error_handler('var_dump'); -$previousExceptionHandler = set_exception_handler('var_dump'); +$previousErrorHandler = set_error_handler('print_r'); +$previousExceptionHandler = set_exception_handler('print_r'); restore_error_handler(); restore_exception_handler(); -var_dump(null !== $previousErrorHandler); -var_dump(null !== $previousExceptionHandler); +if (null === $previousErrorHandler) { + echo 'Previous error handler is NOT present' . PHP_EOL; +} + +if (null !== $previousExceptionHandler) { + echo 'Previous exception handler is present' . PHP_EOL; +} ?> --EXPECT-- -bool(false) -bool(true) +Previous error handler is NOT present +Previous exception handler is present From f0d1c3a17555a16c8b932123653e5c35d8d085e9 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 29 Oct 2020 18:07:44 +0100 Subject: [PATCH 17/44] Fix more PHPT tests --- ...andler_captures_exception_thrown_from_previous_handler.phpt | 3 +-- ...or_handler_captures_exception_with_no_previous_handler.phpt | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/phpt/error_handler_captures_exception_thrown_from_previous_handler.phpt b/tests/phpt/error_handler_captures_exception_thrown_from_previous_handler.phpt index ec11e2a10a..75d42a42c3 100644 --- a/tests/phpt/error_handler_captures_exception_thrown_from_previous_handler.phpt +++ b/tests/phpt/error_handler_captures_exception_thrown_from_previous_handler.phpt @@ -45,6 +45,5 @@ Exception listener called Custom exception handler called Exception listener called -Fatal error: Uncaught Exception: foo bar baz in %s:%d -Stack trace: +Fatal error: Uncaught Exception: foo bar baz in %s %a diff --git a/tests/phpt/error_handler_captures_exception_with_no_previous_handler.phpt b/tests/phpt/error_handler_captures_exception_with_no_previous_handler.phpt index 4d21c2076d..ea100553d7 100644 --- a/tests/phpt/error_handler_captures_exception_with_no_previous_handler.phpt +++ b/tests/phpt/error_handler_captures_exception_with_no_previous_handler.phpt @@ -38,6 +38,5 @@ throw new \Exception('foo bar'); --EXPECTF-- Exception listener called -Fatal error: Uncaught Exception: foo bar in %s:%d -Stack trace: +Fatal error: Uncaught Exception: foo bar in %s %a From cfabee904f641505cb19735baa0be99df0351fc9 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 3 Nov 2020 10:10:02 +0100 Subject: [PATCH 18/44] Bump Psalm 4 constaint --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 23419e8adf..6ffce160c4 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ "phpstan/phpstan-phpunit": "^0.12", "phpunit/phpunit": "^8.5.8|^9.4.2", "symfony/phpunit-bridge": "^5.1", - "vimeo/psalm": "^3.4|^4.0" + "vimeo/psalm": "^3.4|^4.1.1" }, "suggest": { "monolog/monolog": "Allow sending log messages to Sentry by using the included Monolog handler." From 63c3e72997f50a9cc7a14813e72542eca8d749a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20D=C3=B6hring?= Date: Fri, 27 Nov 2020 23:10:57 +0100 Subject: [PATCH 19/44] Migrate the error handling for the @ operator to php 8 state (#1141) --- CHANGELOG.md | 1 + src/ErrorHandler.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9e8364058..bc79432188 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased - PHP 8 support +- Change the error handling for silenced fatal errors using `@` to use a mask check in order to be php 8 compatible (#1141) ## 3.0.3 (2020-10-12) diff --git a/src/ErrorHandler.php b/src/ErrorHandler.php index 95493f447d..af00bf53d5 100644 --- a/src/ErrorHandler.php +++ b/src/ErrorHandler.php @@ -265,7 +265,7 @@ public function addExceptionHandlerListener(callable $listener): void */ private function handleError(int $level, string $message, string $file, int $line, ?array $errcontext = []): bool { - if (0 === error_reporting()) { + if (0 === (error_reporting() & $level)) { $errorAsException = new SilencedErrorException(self::ERROR_LEVELS_DESCRIPTION[$level] . ': ' . $message, 0, $level, $file, $line); } else { $errorAsException = new \ErrorException(self::ERROR_LEVELS_DESCRIPTION[$level] . ': ' . $message, 0, $level, $file, $line); From 9ebd3829ab57b0de188546387ddd0b4ff2a1900c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20D=C3=B6hring?= Date: Sat, 28 Nov 2020 12:11:42 +0100 Subject: [PATCH 20/44] Update guzzlehttp/promises and symfony/options-resolver to the minimum required version supported on PHP 8 (#1144) --- CHANGELOG.md | 2 ++ composer.json | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc79432188..5401be2770 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## Unreleased - PHP 8 support - Change the error handling for silenced fatal errors using `@` to use a mask check in order to be php 8 compatible (#1141) +- Update the `guzzlehttp/promises` package to the minimum required version compatible with PHP 8 (#1144) +- Update the `symfony/options-resolver` package to the minimum required version compatible with PHP 8 (#1144) ## 3.0.3 (2020-10-12) diff --git a/composer.json b/composer.json index 6ffce160c4..4499b53915 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "php": "^7.2|^8.0", "ext-json": "*", "ext-mbstring": "*", - "guzzlehttp/promises": "^1.3", + "guzzlehttp/promises": "^1.4", "guzzlehttp/psr7": "^1.6", "jean85/pretty-package-versions": "^1.5", "ocramius/package-versions": "^1.8", @@ -35,7 +35,7 @@ "psr/http-factory": "^1.0", "psr/http-message-implementation": "^1.0", "psr/log": "^1.0", - "symfony/options-resolver": "^3.4.4|^4.0|^5.0", + "symfony/options-resolver": "^3.4.43|^4.4.11|^5.0.11", "symfony/polyfill-php80": "^1.17", "symfony/polyfill-uuid": "^1.13.1" }, From 34b24c06c4c995a9020c1e86a676981a9c9612f4 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Mon, 30 Nov 2020 20:32:23 +0100 Subject: [PATCH 21/44] Remove unused phpstan ignore rule --- phpstan.neon | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 0820667503..24bf0cb766 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -27,9 +27,6 @@ parameters: - message: '/^Method Sentry\\Client::getIntegration\(\) should return T of Sentry\\Integration\\IntegrationInterface\|null but returns Sentry\\Integration\\IntegrationInterface\|null\.$/' path: src/Client.php - - - message: "/Call to function in_array\\(\\) with arguments callable\\(\\): mixed&string, array\\('{closure}', '__lambda_func'\\) and true will always evaluate to false\\.$/" - path: src/FrameBuilder.php excludes_analyse: - tests/resources - tests/Fixtures From e6fed3e1289d1d9464e20239732c5a95764474b9 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Tue, 1 Dec 2020 00:01:48 +0100 Subject: [PATCH 22/44] Test against PHP 8.0.0 stable --- .appveyor.yml | 20 +++++++++++++------- .gitattributes | 4 ++-- .travis.yml | 4 ++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index abb6aefe0f..06430ad9f9 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -8,22 +8,28 @@ image: Visual Studio 2019 environment: matrix: - PHP_VERSION: 7.2 - XDEBUG_VERSION: 2.9.2-7.2-vc15-nts + XDEBUG_VERSION: 3.0.0-7.2-vc15-nts DEPENDENCIES: lowest - PHP_VERSION: 7.2 - XDEBUG_VERSION: 2.9.2-7.2-vc15-nts + XDEBUG_VERSION: 3.0.0-7.2-vc15-nts DEPENDENCIES: highest - PHP_VERSION: 7.3 - XDEBUG_VERSION: 2.9.2-7.3-vc15-nts + XDEBUG_VERSION: 3.0.0-7.3-vc15-nts DEPENDENCIES: lowest - PHP_VERSION: 7.3 - XDEBUG_VERSION: 2.9.2-7.3-vc15-nts + XDEBUG_VERSION: 3.0.0-7.3-vc15-nts DEPENDENCIES: highest - PHP_VERSION: 7.4 - XDEBUG_VERSION: 2.9.2-7.4-vc15-nts + XDEBUG_VERSION: 3.0.0-7.4-vc15-nts DEPENDENCIES: lowest - PHP_VERSION: 7.4 - XDEBUG_VERSION: 2.9.2-7.4-vc15-nts + XDEBUG_VERSION: 3.0.0-7.4-vc15-nts + DEPENDENCIES: highest + - PHP_VERSION: 8.0 + XDEBUG_VERSION: 3.0.0-7.4-vc15-nts + DEPENDENCIES: lowest + - PHP_VERSION: 8.0 + XDEBUG_VERSION: 3.0.0-7.4-vc15-nts DEPENDENCIES: highest matrix: @@ -58,7 +64,7 @@ install: - IF %INSTALL_PHP%==1 echo xdebug.collect_vars=0 >> php.ini - IF %INSTALL_PHP%==1 echo xdebug.extended_info=0 >> php.ini - cd C:\projects\sentry-php - - IF NOT EXIST composer.phar appveyor-retry appveyor DownloadFile https://github.com/composer/composer/releases/download/1.9.3/composer.phar + - IF NOT EXIST composer.phar appveyor-retry appveyor DownloadFile https://github.com/composer/composer/releases/download/2.0.7/composer.phar - php composer.phar self-update - IF %DEPENDENCIES%==lowest php composer.phar update --no-progress --no-interaction --no-suggest --ansi --prefer-lowest --prefer-dist - IF %DEPENDENCIES%==highest php composer.phar update --no-progress --no-interaction --no-suggest --ansi --prefer-dist diff --git a/.gitattributes b/.gitattributes index ec85a1b1cc..c067dc5ae7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -16,9 +16,9 @@ /.editorconfig export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/.php_cs export-ignore -/.scrutinizer.yml export-ignore +/.php_cs.dist export-ignore /.travis.yml export-ignore /Makefile export-ignore /phpstan.neon export-ignore /phpunit.xml.dist export-ignore +/psalm.xml.dist export-ignore diff --git a/.travis.yml b/.travis.yml index db99a891f3..947edcf08c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ php: - 7.2 - 7.3 - 7.4 - - nightly + - 8.0 env: - dependencies=highest @@ -35,7 +35,7 @@ jobs: script: composer psalm install: - - if [ "$TRAVIS_PHP_VERSION" = "nightly" ]; then composer remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction; fi; + - if [ "$TRAVIS_PHP_VERSION" = "8.0" ]; then composer remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction; fi; - if [ "$dependencies" = "lowest" ]; then composer update --no-interaction --no-suggest --prefer-lowest --prefer-dist; fi; - if [ "$dependencies" = "highest" ]; then composer update --no-interaction --no-suggest --prefer-dist; fi; From cee4a6385a0854aad6ff7bf9ba1af55efa1287c0 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Tue, 1 Dec 2020 00:07:16 +0100 Subject: [PATCH 23/44] Revert unneeded changes to PHPT tests --- .../error_handler_can_be_registered_once.phpt | 28 ++++++------------- ...eption_rethrown_from_previous_handler.phpt | 3 +- ...xception_thrown_from_previous_handler.phpt | 3 +- ...es_exception_with_no_previous_handler.phpt | 3 +- ...handler_only_error_handler_registered.phpt | 17 ++++------- ...ler_only_exception_handler_registered.phpt | 17 ++++------- 6 files changed, 27 insertions(+), 44 deletions(-) diff --git a/tests/phpt/error_handler_can_be_registered_once.phpt b/tests/phpt/error_handler_can_be_registered_once.phpt index 6cc0da4bde..4a1c9ad277 100644 --- a/tests/phpt/error_handler_can_be_registered_once.phpt +++ b/tests/phpt/error_handler_can_be_registered_once.phpt @@ -24,7 +24,7 @@ function getHandlerRegistrationCount(callable $setHandlerCallback, callable $res $previousErrorHandler = null; while (true) { - $errorHandler = call_user_func($setHandlerCallback, 'print_r'); + $errorHandler = call_user_func($setHandlerCallback, 'var_dump'); // Restore the error handler that has been popped out from the stack with // the line above @@ -52,24 +52,14 @@ function getHandlerRegistrationCount(callable $setHandlerCallback, callable $res return count($savedErrorHandlers); } -if (ErrorHandler::registerOnceErrorHandler() === ErrorHandler::registerOnceErrorHandler()) { - echo 'Error handler is a singleton' . PHP_EOL; -} - -if (1 === getHandlerRegistrationCount('set_error_handler', 'restore_error_handler')) { - echo 'Only one error handler is registered' . PHP_EOL; -} +var_dump(ErrorHandler::registerOnceErrorHandler() === ErrorHandler::registerOnceErrorHandler()); +var_dump(1 === getHandlerRegistrationCount('set_error_handler', 'restore_error_handler')); -if (ErrorHandler::registerOnceExceptionHandler() === ErrorHandler::registerOnceExceptionHandler()) { - echo 'Exception handler is a singleton' . PHP_EOL; -} - -if (1 === getHandlerRegistrationCount('set_exception_handler', 'restore_exception_handler')) { - echo 'Only one exception handler is registered' . PHP_EOL; -} +var_dump(ErrorHandler::registerOnceExceptionHandler() === ErrorHandler::registerOnceExceptionHandler()); +var_dump(1 === getHandlerRegistrationCount('set_exception_handler', 'restore_exception_handler')); ?> --EXPECT-- -Error handler is a singleton -Only one error handler is registered -Exception handler is a singleton -Only one exception handler is registered +bool(true) +bool(true) +bool(true) +bool(true) diff --git a/tests/phpt/error_handler_captures_exception_rethrown_from_previous_handler.phpt b/tests/phpt/error_handler_captures_exception_rethrown_from_previous_handler.phpt index 15047a08d6..dda9b6e9f7 100644 --- a/tests/phpt/error_handler_captures_exception_rethrown_from_previous_handler.phpt +++ b/tests/phpt/error_handler_captures_exception_rethrown_from_previous_handler.phpt @@ -40,5 +40,6 @@ throw new \Exception('foo bar'); Exception listener called Custom exception handler called -Fatal error: Uncaught Exception: foo bar in %s +Fatal error: Uncaught Exception: foo bar in %s:%d +Stack trace: %a diff --git a/tests/phpt/error_handler_captures_exception_thrown_from_previous_handler.phpt b/tests/phpt/error_handler_captures_exception_thrown_from_previous_handler.phpt index 75d42a42c3..ec11e2a10a 100644 --- a/tests/phpt/error_handler_captures_exception_thrown_from_previous_handler.phpt +++ b/tests/phpt/error_handler_captures_exception_thrown_from_previous_handler.phpt @@ -45,5 +45,6 @@ Exception listener called Custom exception handler called Exception listener called -Fatal error: Uncaught Exception: foo bar baz in %s +Fatal error: Uncaught Exception: foo bar baz in %s:%d +Stack trace: %a diff --git a/tests/phpt/error_handler_captures_exception_with_no_previous_handler.phpt b/tests/phpt/error_handler_captures_exception_with_no_previous_handler.phpt index ea100553d7..4d21c2076d 100644 --- a/tests/phpt/error_handler_captures_exception_with_no_previous_handler.phpt +++ b/tests/phpt/error_handler_captures_exception_with_no_previous_handler.phpt @@ -38,5 +38,6 @@ throw new \Exception('foo bar'); --EXPECTF-- Exception listener called -Fatal error: Uncaught Exception: foo bar in %s +Fatal error: Uncaught Exception: foo bar in %s:%d +Stack trace: %a diff --git a/tests/phpt/error_handler_only_error_handler_registered.phpt b/tests/phpt/error_handler_only_error_handler_registered.phpt index 57d447c4f8..2975e228b1 100644 --- a/tests/phpt/error_handler_only_error_handler_registered.phpt +++ b/tests/phpt/error_handler_only_error_handler_registered.phpt @@ -19,20 +19,15 @@ require $vendor . '/vendor/autoload.php'; ErrorHandler::registerOnceErrorHandler(); -$previousErrorHandler = set_error_handler('print_r'); -$previousExceptionHandler = set_exception_handler('print_r'); +$previousErrorHandler = set_error_handler('var_dump'); +$previousExceptionHandler = set_exception_handler('var_dump'); restore_error_handler(); restore_exception_handler(); -if (null !== $previousErrorHandler) { - echo 'Previous error handler is present' . PHP_EOL; -} - -if (null === $previousExceptionHandler) { - echo 'Previous exception handler is NOT present' . PHP_EOL; -} +var_dump(null !== $previousErrorHandler); +var_dump(null !== $previousExceptionHandler); ?> --EXPECT-- -Previous error handler is present -Previous exception handler is NOT present +bool(true) +bool(false) diff --git a/tests/phpt/error_handler_only_exception_handler_registered.phpt b/tests/phpt/error_handler_only_exception_handler_registered.phpt index 422ea2e261..5ed972abbf 100644 --- a/tests/phpt/error_handler_only_exception_handler_registered.phpt +++ b/tests/phpt/error_handler_only_exception_handler_registered.phpt @@ -19,20 +19,15 @@ require $vendor . '/vendor/autoload.php'; ErrorHandler::registerOnceExceptionHandler(); -$previousErrorHandler = set_error_handler('print_r'); -$previousExceptionHandler = set_exception_handler('print_r'); +$previousErrorHandler = set_error_handler('var_dump'); +$previousExceptionHandler = set_exception_handler('var_dump'); restore_error_handler(); restore_exception_handler(); -if (null === $previousErrorHandler) { - echo 'Previous error handler is NOT present' . PHP_EOL; -} - -if (null !== $previousExceptionHandler) { - echo 'Previous exception handler is present' . PHP_EOL; -} +var_dump(null !== $previousErrorHandler); +var_dump(null !== $previousExceptionHandler); ?> --EXPECT-- -Previous error handler is NOT present -Previous exception handler is present +bool(false) +bool(true) From 8ec4f031a95dd6f7e23eccf29a6ff40d94cefdea Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Tue, 1 Dec 2020 00:16:31 +0100 Subject: [PATCH 24/44] Fix various issues (CS, revert breaking changes, etc) --- CHANGELOG.md | 3 +- composer.json | 8 +-- phpunit.xml.dist | 59 ++++++++++++---------- src/Exception/ExceptionInterface.php | 2 + src/Exception/InvalidArgumentException.php | 17 +++++++ 5 files changed, 56 insertions(+), 33 deletions(-) create mode 100644 src/Exception/InvalidArgumentException.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 5401be2770..935be1b8db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # CHANGELOG ## Unreleased -- PHP 8 support + +- Add support for PHP 8.0 (#1087) - Change the error handling for silenced fatal errors using `@` to use a mask check in order to be php 8 compatible (#1141) - Update the `guzzlehttp/promises` package to the minimum required version compatible with PHP 8 (#1144) - Update the `symfony/options-resolver` package to the minimum required version compatible with PHP 8 (#1144) diff --git a/composer.json b/composer.json index 4499b53915..4e118af4d2 100644 --- a/composer.json +++ b/composer.json @@ -45,11 +45,11 @@ "monolog/monolog": "^1.3|^2.0", "php-http/mock-client": "^1.3", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^0.12.42", + "phpstan/phpstan": "^0.12", "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^8.5.8|^9.4.2", - "symfony/phpunit-bridge": "^5.1", - "vimeo/psalm": "^3.4|^4.1.1" + "phpunit/phpunit": "^8.5|^9.4", + "symfony/phpunit-bridge": "^5.2", + "vimeo/psalm": "^3.4|^4.2" }, "suggest": { "monolog/monolog": "Allow sending log messages to Sentry by using the included Monolog handler." diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 86c1f1dea5..38586cb226 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,31 +1,34 @@ - - - - src - - - - - - - - tests - tests/phpt - - - - - - - - + + + + + + + tests + tests/phpt + + + + + + src + + + + + + + + + + diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index b957bd2e10..6ccb6c0c9b 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -8,6 +8,8 @@ * This interface must be implemented by all exception classes of this library. * * @author Stefano Arlandini + * + * @deprecated since version 3.0, to be removed in 4.0 */ interface ExceptionInterface { diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php new file mode 100644 index 0000000000..7cc4c342f7 --- /dev/null +++ b/src/Exception/InvalidArgumentException.php @@ -0,0 +1,17 @@ + + * + * @deprecated since version 3.0, to be removed in 4.0 + */ +class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface +{ +} From c5a03c0afcf5e4e71bb87e9583aa38b28a194efd Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Tue, 1 Dec 2020 00:23:47 +0100 Subject: [PATCH 25/44] Revert more unneeded changes to make the diff smaller --- phpunit.xml.dist | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 38586cb226..e82f4de790 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,7 @@ beStrictAboutOutputDuringTests="true" > - + @@ -25,10 +25,10 @@ - + - + From e89626a9889a29855768f5655531ae79156be6a9 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Tue, 1 Dec 2020 00:42:53 +0100 Subject: [PATCH 26/44] Adapt Xdebug config on AppVeyor for version 3 --- .appveyor.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 06430ad9f9..638ca6b1b6 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -58,11 +58,7 @@ install: - IF %INSTALL_PHP%==1 echo extension=php_mbstring.dll >> php.ini - IF %INSTALL_PHP%==1 echo extension=php_openssl.dll >> php.ini - IF %INSTALL_PHP%==1 echo zend_extension=C:\php\ext\php_xdebug.dll >> php.ini - - IF %INSTALL_PHP%==1 echo xdebug.overload_var_dump=0 >> php.ini - - IF %INSTALL_PHP%==1 echo xdebug.collect_includes=0 >> php.ini - - IF %INSTALL_PHP%==1 echo xdebug.dump_globals=0 >> php.ini - - IF %INSTALL_PHP%==1 echo xdebug.collect_vars=0 >> php.ini - - IF %INSTALL_PHP%==1 echo xdebug.extended_info=0 >> php.ini + - IF %INSTALL_PHP%==1 echo xdebug.mode=coverage >> php.ini - cd C:\projects\sentry-php - IF NOT EXIST composer.phar appveyor-retry appveyor DownloadFile https://github.com/composer/composer/releases/download/2.0.7/composer.phar - php composer.phar self-update From 68c8872673b5b247467e87852cb4b94279dc693f Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Tue, 1 Dec 2020 00:50:05 +0100 Subject: [PATCH 27/44] Bump minimum required version of PHPUnit 8 to avoid bugged version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 629ae20f71..0d2adf5312 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^0.12", "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^8.5|^9.4", + "phpunit/phpunit": "^8.5.12|^9.4", "symfony/phpunit-bridge": "^5.2", "vimeo/psalm": "^3.4|^4.2" }, From d450f80b96fcfb413c6b76e65d3963fc9a7ae45c Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Wed, 2 Dec 2020 18:57:10 +0100 Subject: [PATCH 28/44] Revert breaking changes --- src/Breadcrumb.php | 6 ++++-- src/Exception/ExceptionInterface.php | 2 +- src/Exception/InvalidArgumentException.php | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Breadcrumb.php b/src/Breadcrumb.php index e29e6be251..a709b0cdfb 100644 --- a/src/Breadcrumb.php +++ b/src/Breadcrumb.php @@ -4,6 +4,8 @@ namespace Sentry; +use InvalidArgumentException; + /** * This class stores all the information about a breadcrumb. * @@ -115,7 +117,7 @@ final class Breadcrumb public function __construct(string $level, string $type, string $category, ?string $message = null, array $metadata = []) { if (!\in_array($level, self::ALLOWED_LEVELS, true)) { - throw new \InvalidArgumentException('The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants.'); + throw new InvalidArgumentException('The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants.'); } $this->type = $type; @@ -171,7 +173,7 @@ public function getLevel(): string public function withLevel(string $level): self { if (!\in_array($level, self::ALLOWED_LEVELS, true)) { - throw new \InvalidArgumentException('The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants.'); + throw new InvalidArgumentException('The value of the $level argument must be one of the Breadcrumb::LEVEL_* constants.'); } if ($level === $this->level) { diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 6ccb6c0c9b..d4be5c56dc 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -9,7 +9,7 @@ * * @author Stefano Arlandini * - * @deprecated since version 3.0, to be removed in 4.0 + * @deprecated since version 3.1, to be removed in 4.0 */ interface ExceptionInterface { diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 7cc4c342f7..745f0e82bb 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -10,7 +10,7 @@ * * @author Stefano Arlandini * - * @deprecated since version 3.0, to be removed in 4.0 + * @deprecated since version 3.1, to be removed in 4.0 */ class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface { From 1749fe821f72d5f60f0d82ac872e3a524be97fb2 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 4 Dec 2020 22:27:26 +0100 Subject: [PATCH 29/44] Requier nikic/php-parser ^4.10.3 due to nikic/PHP-Parser#736 --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 478abeba23..d2a69d8918 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,7 @@ "friendsofphp/php-cs-fixer": "^2.16", "http-interop/http-factory-guzzle": "^1.0", "monolog/monolog": "^1.3|^2.0", + "nikic/php-parser": "^4.10.3", "php-http/mock-client": "^1.3", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^0.12", From eef1ab9e11961c1e515d1224d5cc95261d5b96b9 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sat, 5 Dec 2020 01:37:04 +0100 Subject: [PATCH 30/44] Stop using deprecated --no-suggest flag of Composer --- .appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 638ca6b1b6..680b0921ee 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -62,8 +62,8 @@ install: - cd C:\projects\sentry-php - IF NOT EXIST composer.phar appveyor-retry appveyor DownloadFile https://github.com/composer/composer/releases/download/2.0.7/composer.phar - php composer.phar self-update - - IF %DEPENDENCIES%==lowest php composer.phar update --no-progress --no-interaction --no-suggest --ansi --prefer-lowest --prefer-dist - - IF %DEPENDENCIES%==highest php composer.phar update --no-progress --no-interaction --no-suggest --ansi --prefer-dist + - IF %DEPENDENCIES%==lowest php composer.phar update --no-progress --no-interaction --ansi --prefer-lowest --prefer-dist + - IF %DEPENDENCIES%==highest php composer.phar update --no-progress --no-interaction --ansi --prefer-dist test_script: - cd C:\projects\sentry-php From 3a7239103bee44bd0a82190f0e8ff9a624c21f5e Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Fri, 4 Dec 2020 00:36:31 +0100 Subject: [PATCH 31/44] Revert one more breaking change --- src/Breadcrumb.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Breadcrumb.php b/src/Breadcrumb.php index a709b0cdfb..3b65be03fe 100644 --- a/src/Breadcrumb.php +++ b/src/Breadcrumb.php @@ -4,7 +4,7 @@ namespace Sentry; -use InvalidArgumentException; +use Sentry\Exception\InvalidArgumentException; /** * This class stores all the information about a breadcrumb. From f8ac3bd6b159634d0deda3da0f130a3d22bce403 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sat, 5 Dec 2020 12:55:21 +0100 Subject: [PATCH 32/44] Fix AppVeyor CI --- .appveyor.yml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 680b0921ee..3db494f846 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,6 +1,6 @@ version: 2.x-{build} build: false -clone_depth: 2 +clone_depth: 50 clone_folder: c:\projects\sentry-php skip_branch_with_pr: true image: Visual Studio 2019 @@ -8,35 +8,34 @@ image: Visual Studio 2019 environment: matrix: - PHP_VERSION: 7.2 - XDEBUG_VERSION: 3.0.0-7.2-vc15-nts + XDEBUG_VERSION: 3.0.1-7.2-vc15-nts DEPENDENCIES: lowest - PHP_VERSION: 7.2 - XDEBUG_VERSION: 3.0.0-7.2-vc15-nts + XDEBUG_VERSION: 3.0.1-7.2-vc15-nts DEPENDENCIES: highest - PHP_VERSION: 7.3 - XDEBUG_VERSION: 3.0.0-7.3-vc15-nts + XDEBUG_VERSION: 3.0.1-7.3-vc15-nts DEPENDENCIES: lowest - PHP_VERSION: 7.3 - XDEBUG_VERSION: 3.0.0-7.3-vc15-nts + XDEBUG_VERSION: 3.0.1-7.3-vc15-nts DEPENDENCIES: highest - PHP_VERSION: 7.4 - XDEBUG_VERSION: 3.0.0-7.4-vc15-nts + XDEBUG_VERSION: 3.0.1-7.4-vc15-nts DEPENDENCIES: lowest - PHP_VERSION: 7.4 - XDEBUG_VERSION: 3.0.0-7.4-vc15-nts + XDEBUG_VERSION: 3.0.1-7.4-vc15-nts DEPENDENCIES: highest - PHP_VERSION: 8.0 - XDEBUG_VERSION: 3.0.0-7.4-vc15-nts + XDEBUG_VERSION: 3.0.1-7.4-vc15-nts DEPENDENCIES: lowest - PHP_VERSION: 8.0 - XDEBUG_VERSION: 3.0.0-7.4-vc15-nts + XDEBUG_VERSION: 3.0.1-7.4-vc15-nts DEPENDENCIES: highest matrix: fast_finish: true cache: - - composer.phar - '%LOCALAPPDATA%\Composer\files' - C:\php -> .appveyor.yml @@ -50,6 +49,7 @@ install: - ps: choco upgrade chocolatey --confirm --no-progress --allow-downgrade --version 0.10.13 - ps: choco install codecov --confirm --no-progress - ps: choco install php --confirm --no-progress --package-parameters '""/InstallDir:C:\php""' --version (choco search php --exact --all-versions --limit-output | Select-String -Pattern $env:PHP_VERSION | ForEach-Object {$_ -Replace "php\|", ""} | Sort {[version] $_} -Descending | Select-Object -First 1) + - ps: choco install composer --confirm --no-progress --params '"/Php:C:\php"' - cd C:\php - ps: if ($env:INSTALL_PHP -imatch 1) { appveyor-retry appveyor DownloadFile "https://xdebug.org/files/php_xdebug-$env:XDEBUG_VERSION-x86_64.dll" -FileName C:\php\ext\php_xdebug.dll } - IF %INSTALL_PHP%==1 copy /Y php.ini-production php.ini @@ -60,10 +60,10 @@ install: - IF %INSTALL_PHP%==1 echo zend_extension=C:\php\ext\php_xdebug.dll >> php.ini - IF %INSTALL_PHP%==1 echo xdebug.mode=coverage >> php.ini - cd C:\projects\sentry-php - - IF NOT EXIST composer.phar appveyor-retry appveyor DownloadFile https://github.com/composer/composer/releases/download/2.0.7/composer.phar - - php composer.phar self-update - - IF %DEPENDENCIES%==lowest php composer.phar update --no-progress --no-interaction --ansi --prefer-lowest --prefer-dist - - IF %DEPENDENCIES%==highest php composer.phar update --no-progress --no-interaction --ansi --prefer-dist + - composer self-update + - IF %PHP_VERSION%==8.0 composer remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction + - IF %DEPENDENCIES%==lowest composer update --no-progress --no-interaction --ansi --prefer-lowest --prefer-dist + - IF %DEPENDENCIES%==highest composer update --no-progress --no-interaction --ansi --prefer-dist test_script: - cd C:\projects\sentry-php From 79c4d4656e310640317a94e8fef25757eb0d783d Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sat, 5 Dec 2020 12:59:55 +0100 Subject: [PATCH 33/44] Use refreshenv command to reload changed env vars in AppVeyor --- .appveyor.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 3db494f846..e4361c0eba 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -49,7 +49,8 @@ install: - ps: choco upgrade chocolatey --confirm --no-progress --allow-downgrade --version 0.10.13 - ps: choco install codecov --confirm --no-progress - ps: choco install php --confirm --no-progress --package-parameters '""/InstallDir:C:\php""' --version (choco search php --exact --all-versions --limit-output | Select-String -Pattern $env:PHP_VERSION | ForEach-Object {$_ -Replace "php\|", ""} | Sort {[version] $_} -Descending | Select-Object -First 1) - - ps: choco install composer --confirm --no-progress --params '"/Php:C:\php"' + - ps: choco install composer --confirm --no-progress --params '"/Dev:C:\tools\composer /Php:C:\php"' + - ps: refreshenv - cd C:\php - ps: if ($env:INSTALL_PHP -imatch 1) { appveyor-retry appveyor DownloadFile "https://xdebug.org/files/php_xdebug-$env:XDEBUG_VERSION-x86_64.dll" -FileName C:\php\ext\php_xdebug.dll } - IF %INSTALL_PHP%==1 copy /Y php.ini-production php.ini From 56360ec55d16dd0df4d199445d4cd16e504ec908 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sat, 5 Dec 2020 13:06:46 +0100 Subject: [PATCH 34/44] Revert how Composer is installed to AppVeyor --- .appveyor.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index e4361c0eba..677889b366 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -36,6 +36,7 @@ matrix: fast_finish: true cache: + - composer.phar - '%LOCALAPPDATA%\Composer\files' - C:\php -> .appveyor.yml @@ -49,8 +50,6 @@ install: - ps: choco upgrade chocolatey --confirm --no-progress --allow-downgrade --version 0.10.13 - ps: choco install codecov --confirm --no-progress - ps: choco install php --confirm --no-progress --package-parameters '""/InstallDir:C:\php""' --version (choco search php --exact --all-versions --limit-output | Select-String -Pattern $env:PHP_VERSION | ForEach-Object {$_ -Replace "php\|", ""} | Sort {[version] $_} -Descending | Select-Object -First 1) - - ps: choco install composer --confirm --no-progress --params '"/Dev:C:\tools\composer /Php:C:\php"' - - ps: refreshenv - cd C:\php - ps: if ($env:INSTALL_PHP -imatch 1) { appveyor-retry appveyor DownloadFile "https://xdebug.org/files/php_xdebug-$env:XDEBUG_VERSION-x86_64.dll" -FileName C:\php\ext\php_xdebug.dll } - IF %INSTALL_PHP%==1 copy /Y php.ini-production php.ini @@ -61,10 +60,11 @@ install: - IF %INSTALL_PHP%==1 echo zend_extension=C:\php\ext\php_xdebug.dll >> php.ini - IF %INSTALL_PHP%==1 echo xdebug.mode=coverage >> php.ini - cd C:\projects\sentry-php - - composer self-update + - IF NOT EXIST composer.phar appveyor-retry appveyor DownloadFile https://github.com/composer/composer/releases/download/2.0.8/composer.phar + - php composer.phar self-update - IF %PHP_VERSION%==8.0 composer remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction - - IF %DEPENDENCIES%==lowest composer update --no-progress --no-interaction --ansi --prefer-lowest --prefer-dist - - IF %DEPENDENCIES%==highest composer update --no-progress --no-interaction --ansi --prefer-dist + - IF %DEPENDENCIES%==lowest php composer.phar update --no-progress --no-interaction --ansi --prefer-lowest --prefer-dist + - IF %DEPENDENCIES%==highest php composer.phar update --no-progress --no-interaction --ansi --prefer-dist test_script: - cd C:\projects\sentry-php From 13eaa9c75482d21c3ba30b690a3f163b2d242919 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sat, 5 Dec 2020 13:23:58 +0100 Subject: [PATCH 35/44] Update Xdebug to version 3.0.1 on Travis CI --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 947edcf08c..9760f5d7e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,6 +34,9 @@ jobs: name: Psalm script: composer psalm +before_install: + - pecl install xdebug-3.0.1 + install: - if [ "$TRAVIS_PHP_VERSION" = "8.0" ]; then composer remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction; fi; - if [ "$dependencies" = "lowest" ]; then composer update --no-interaction --no-suggest --prefer-lowest --prefer-dist; fi; From 73ef998dfe635af0e4f33513d6e321cea2e82f8b Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sat, 5 Dec 2020 13:28:12 +0100 Subject: [PATCH 36/44] Use more recent version of Ubuntu as base image --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 9760f5d7e9..a8ca55edf0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: php +dist: focal php: - 7.2 From ba4f3b43b5f033fdbdc3b9be85af79cac07b701d Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sat, 5 Dec 2020 13:34:21 +0100 Subject: [PATCH 37/44] Uninstall old Xdebug before installing the new version --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a8ca55edf0..82cd15dc1e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,8 @@ jobs: script: composer psalm before_install: - - pecl install xdebug-3.0.1 + - pecl uninstall xdebug + - pecl install xdebug install: - if [ "$TRAVIS_PHP_VERSION" = "8.0" ]; then composer remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction; fi; From aebc0e855f9be66fc4a38d2b5eb0fac48d56eebc Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sat, 5 Dec 2020 13:56:31 +0100 Subject: [PATCH 38/44] Add missing XDEBUG_MODE env var --- .travis.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 82cd15dc1e..98aadecf0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ language: php -dist: focal php: - 7.2 @@ -35,17 +34,13 @@ jobs: name: Psalm script: composer psalm -before_install: - - pecl uninstall xdebug - - pecl install xdebug - install: - if [ "$TRAVIS_PHP_VERSION" = "8.0" ]; then composer remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction; fi; - if [ "$dependencies" = "lowest" ]; then composer update --no-interaction --no-suggest --prefer-lowest --prefer-dist; fi; - if [ "$dependencies" = "highest" ]; then composer update --no-interaction --no-suggest --prefer-dist; fi; script: >- - vendor/bin/phpunit --coverage-clover=build/coverage-report.xml && + XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover=build/coverage-report.xml && bash <(curl -s https://codecov.io/bash) -f build/coverage-report.xml notifications: From 45c67631bce93f96cc7bb958b258850b148aed89 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sat, 5 Dec 2020 18:55:50 +0100 Subject: [PATCH 39/44] Adjust memory limit in PHPT test to avoid PHPUnit OOM fatal error --- .../error_handler_captures_out_of_memory_fatal_error.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpt/error_handler_captures_out_of_memory_fatal_error.phpt b/tests/phpt/error_handler_captures_out_of_memory_fatal_error.phpt index 68e2078797..20cf5ff13b 100644 --- a/tests/phpt/error_handler_captures_out_of_memory_fatal_error.phpt +++ b/tests/phpt/error_handler_captures_out_of_memory_fatal_error.phpt @@ -1,7 +1,7 @@ --TEST-- Test catching out of memory fatal error --INI-- -memory_limit=20M +memory_limit=64M --FILE-- addExceptionHandlerListener(static function (): void { echo 'Exception listener called (it should not have been)' . PHP_EOL; }); -$foo = str_repeat('x', 1024 * 1024 * 30); +$foo = str_repeat('x', 1024 * 1024 * 70); ?> --EXPECTF-- Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s on line %d From 461fd71f6771ddcbc55ae2e7c05eb27a1c64a3c3 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sat, 5 Dec 2020 18:57:55 +0100 Subject: [PATCH 40/44] Fix code coverage config not being compatible with PHPUnit 8.5 --- phpunit.xml.dist | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e82f4de790..0f5d147423 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,6 @@ + + + src + + + From 98fb75fa59016891fa4cc59b696cd1e4f9246206 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sat, 5 Dec 2020 20:11:16 +0100 Subject: [PATCH 41/44] Fix wrong path to Composer executable in AppVeyor --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 677889b366..18c82c1e65 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -62,7 +62,7 @@ install: - cd C:\projects\sentry-php - IF NOT EXIST composer.phar appveyor-retry appveyor DownloadFile https://github.com/composer/composer/releases/download/2.0.8/composer.phar - php composer.phar self-update - - IF %PHP_VERSION%==8.0 composer remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction + - IF %PHP_VERSION%==8.0 php composer.phar remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction - IF %DEPENDENCIES%==lowest php composer.phar update --no-progress --no-interaction --ansi --prefer-lowest --prefer-dist - IF %DEPENDENCIES%==highest php composer.phar update --no-progress --no-interaction --ansi --prefer-dist From 25f5f5f679ff3f7f9665169a5a249729eebb9c68 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sat, 5 Dec 2020 21:36:55 +0100 Subject: [PATCH 42/44] Fix Xdebug version for PHP8 on AppVeyor --- .appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 18c82c1e65..c84dc3372c 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -26,10 +26,10 @@ environment: XDEBUG_VERSION: 3.0.1-7.4-vc15-nts DEPENDENCIES: highest - PHP_VERSION: 8.0 - XDEBUG_VERSION: 3.0.1-7.4-vc15-nts + XDEBUG_VERSION: 3.0.1-8.0-vs16-nts DEPENDENCIES: lowest - PHP_VERSION: 8.0 - XDEBUG_VERSION: 3.0.1-7.4-vc15-nts + XDEBUG_VERSION: 3.0.1-8.0-vs16-nts DEPENDENCIES: highest matrix: From 7a8134c257d659626cfb41d2f8621d2d67766cfe Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sat, 5 Dec 2020 22:25:02 +0100 Subject: [PATCH 43/44] Fix AppVeyor build (finally!) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d2a69d8918..751f71577b 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,7 @@ "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^0.12", "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^8.5.12|^9.4", + "phpunit/phpunit": "^8.5.13|^9.4", "symfony/phpunit-bridge": "^5.2", "vimeo/psalm": "^3.4|^4.2" }, From e98d1b50f3dc60d4eb0e29cdb7d348ab8c64944e Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Sat, 5 Dec 2020 22:37:00 +0100 Subject: [PATCH 44/44] Revert breaking change --- src/Serializer/AbstractSerializer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Serializer/AbstractSerializer.php b/src/Serializer/AbstractSerializer.php index 08116a87cf..d744bdb641 100644 --- a/src/Serializer/AbstractSerializer.php +++ b/src/Serializer/AbstractSerializer.php @@ -20,6 +20,7 @@ namespace Sentry\Serializer; +use Sentry\Exception\InvalidArgumentException; use Sentry\Options; /** @@ -264,7 +265,7 @@ protected function serializeCallable($callable): string } if (!\is_callable($callable)) { - throw new \InvalidArgumentException(sprintf('Expecting callable, got %s', \is_object($callable) ? \get_class($callable) : \gettype($callable))); + throw new InvalidArgumentException(sprintf('Expecting callable, got %s', \is_object($callable) ? \get_class($callable) : \gettype($callable))); } try {