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/.gitignore b/.gitignore
index 75ef0bad07..f0ae426e8d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,6 @@
*.lock
-package.xml
-/vendor
+vendor
.idea
.php_cs.cache
-docs/_build
+.phpunit.result.cache
tests/clover.xml
diff --git a/composer.json b/composer.json
index 9cb47f9114..d407678dfb 100644
--- a/composer.json
+++ b/composer.json
@@ -40,13 +40,13 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"monolog/monolog": "^1.3|^2.0",
- "php-http/mock-client": "^1.3",
+ "php-http/mock-client": "^1.4",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpunit/phpunit": "^7.5.20",
"symfony/phpunit-bridge": "^5.2",
- "vimeo/psalm": "^3.4"
+ "vimeo/psalm": "^4.2"
},
"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 @@
-
diff --git a/src/Context/TagsContext.php b/src/Context/TagsContext.php
index 2a892d3349..068b43ffc0 100644
--- a/src/Context/TagsContext.php
+++ b/src/Context/TagsContext.php
@@ -63,7 +63,7 @@ public function offsetSet($offset, $value): void
/**
* Sanitizes the given data by converting numeric values to strings.
*
- * @param array $data The data to sanitize
+ * @param mixed[] $data The data to sanitize
*
* @return array
*
diff --git a/src/Stacktrace.php b/src/Stacktrace.php
index fc49496fcb..744c054de2 100644
--- a/src/Stacktrace.php
+++ b/src/Stacktrace.php
@@ -177,9 +177,9 @@ public function addFrame(string $file, int $line, array $backtraceFrame): void
$argumentValue = $this->representationSerializer->representationSerialize($argumentValue);
if (\is_string($argumentValue)) {
- $frameArguments[(string) $argumentName] = mb_substr($argumentValue, 0, $this->options->getMaxValueLength());
+ $frameArguments[$argumentName] = mb_substr($argumentValue, 0, $this->options->getMaxValueLength());
} else {
- $frameArguments[(string) $argumentName] = $argumentValue;
+ $frameArguments[$argumentName] = $argumentValue;
}
}
@@ -343,14 +343,14 @@ protected function getFrameArgumentsValues(array $frame): array
}
$result = [];
+ $paramIndex = 0;
- if (\is_string(array_keys($frame['args'])[0])) {
- $result = array_map([$this, 'serializeArgument'], $frame['args']);
- } else {
- $index = 0;
- foreach (array_values($frame['args']) as $argument) {
- $result['param' . (++$index)] = $this->serializeArgument($argument);
+ foreach ($frame['args'] as $argumentName => $argumentValue) {
+ if (!\is_string($argumentName)) {
+ $argumentName = 'param' . (++$paramIndex);
}
+
+ $result[$argumentName] = $this->serializeArgument($argumentValue);
}
return $result;
diff --git a/tests/BreadcrumbTest.php b/tests/BreadcrumbTest.php
index df69a53c2f..17e2370fc7 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 b9183e970b..d303131b4d 100644
--- a/tests/ClientBuilderTest.php
+++ b/tests/ClientBuilderTest.php
@@ -29,39 +29,37 @@
use Sentry\Transport\HttpTransport;
use Sentry\Transport\NullTransport;
use Sentry\Transport\TransportInterface;
+use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
final class ClientBuilderTest extends TestCase
{
- /**
- * @group legacy
- *
- * @expectedDeprecationMessage Delaying the sending of the events using the "Sentry\Transport\HttpTransport" class is deprecated since version 2.2 and will not work in 3.0.
- */
+ use ExpectDeprecationTrait;
+
public function testHttpTransportIsUsedWhenServerIsConfigured(): void
{
- $clientBuilder = ClientBuilder::create(['dsn' => 'http://public:secret@example.com/sentry/1']);
-
- $transport = $this->getObjectAttribute($clientBuilder->getClient(), 'transport');
+ /** @var Client $client */
+ $client = ClientBuilder::create(['dsn' => 'http://public:secret@example.com/sentry/1'])->getClient();
+ $transport = $this->getTransport($client);
$this->assertInstanceOf(HttpTransport::class, $transport);
}
public function testNullTransportIsUsedWhenNoServerIsConfigured(): void
{
- $clientBuilder = new ClientBuilder();
-
- $transport = $this->getObjectAttribute($clientBuilder->getClient(), 'transport');
+ /** @var Client $client */
+ $client = ClientBuilder::create()->getClient();
+ $transport = $this->getTransport($client);
$this->assertInstanceOf(NullTransport::class, $transport);
}
/**
* @group legacy
- *
- * @expectedDeprecationMessage Delaying the sending of the events using the "Sentry\Transport\HttpTransport" class is deprecated since version 2.2 and will not work in 3.0.
*/
public function testSetMessageFactory(): void
{
+ $this->expectDeprecation('Method Sentry\ClientBuilder::setMessageFactory() is deprecated since version 2.3 and will be removed in 3.0.');
+
/** @var MessageFactoryInterface&MockObject $messageFactory */
$messageFactory = $this->createMock(MessageFactoryInterface::class);
$messageFactory->expects($this->once())
@@ -77,11 +75,11 @@ public function testSetMessageFactory(): void
/**
* @group legacy
- *
- * @expectedDeprecation Method Sentry\ClientBuilder::setTransport() is deprecated since version 2.3 and will be removed in 3.0. Use the setTransportFactory() method instead.
*/
public function testSetTransport(): void
{
+ $this->expectDeprecation('Method Sentry\ClientBuilder::setTransport() is deprecated since version 2.3 and will be removed in 3.0. Use the setTransportFactory() method instead.');
+
/** @var TransportInterface&MockObject $transport */
$transport = $this->createMock(TransportInterface::class);
$transport->expects($this->once())
@@ -97,11 +95,11 @@ public function testSetTransport(): void
/**
* @group legacy
- *
- * @expectedDeprecationMessage Delaying the sending of the events using the "Sentry\Transport\HttpTransport" class is deprecated since version 2.2 and will not work in 3.0.
*/
public function testSetHttpClient(): void
{
+ $this->expectDeprecation('Method Sentry\ClientBuilder::setHttpClient() is deprecated since version 2.3 and will be removed in 3.0.');
+
/** @var HttpAsyncClientInterface&MockObject $httpClient */
$httpClient = $this->createMock(HttpAsyncClientInterface::class);
$httpClient->expects($this->once())
@@ -119,11 +117,11 @@ public function testSetHttpClient(): void
/**
* @group legacy
- *
- * @expectedDeprecationMessage Method Sentry\ClientBuilder::addHttpClientPlugin() is deprecated since version 2.3 and will be removed in 3.0.
*/
public function testAddHttpClientPlugin(): void
{
+ $this->expectDeprecation('Method Sentry\ClientBuilder::addHttpClientPlugin() is deprecated since version 2.3 and will be removed in 3.0.');
+
/** @var PluginInterface&MockObject $plugin */
$plugin = $this->createMock(PluginInterface::class);
$plugin->expects($this->once())
@@ -141,12 +139,12 @@ public function testAddHttpClientPlugin(): void
/**
* @group legacy
- *
- * @expectedDeprecation Method Sentry\ClientBuilder::addHttpClientPlugin() is deprecated since version 2.3 and will be removed in 3.0.
- * @expectedDeprecation Method Sentry\ClientBuilder::removeHttpClientPlugin() is deprecated since version 2.3 and will be removed in 3.0.
*/
public function testRemoveHttpClientPlugin(): void
{
+ $this->expectDeprecation('Method Sentry\ClientBuilder::addHttpClientPlugin() is deprecated since version 2.3 and will be removed in 3.0.');
+ $this->expectDeprecation('Method Sentry\ClientBuilder::removeHttpClientPlugin() is deprecated since version 2.3 and will be removed in 3.0.');
+
$plugin = new class() implements PluginInterface {
public function handleRequest(RequestInterface $request, callable $next, callable $first): PromiseInterface
{
@@ -280,6 +278,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 430e151c7f..ff3c8e7d0f 100644
--- a/tests/ClientTest.php
+++ b/tests/ClientTest.php
@@ -240,7 +240,7 @@ public function testCaptureLastError(): void
$client->captureLastError();
- $this->clearLastError();
+ error_clear_last();
}
public function testCaptureLastErrorDoesNothingWhenThereIsNoError(): void
@@ -254,7 +254,7 @@ public function testCaptureLastErrorDoesNothingWhenThereIsNoError(): void
->setTransportFactory($this->createTransportFactory($transport))
->getClient();
- $this->clearLastError();
+ error_clear_last();
$client->captureLastError();
}
@@ -501,20 +501,6 @@ public function testAttachStacktrace(): void
$client->captureMessage('test');
}
- /**
- * @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/Exception/MissingProjectIdCredentialExceptionTest.php b/tests/Exception/MissingProjectIdCredentialExceptionTest.php
index 5a79607a10..6d19cdab5a 100644
--- a/tests/Exception/MissingProjectIdCredentialExceptionTest.php
+++ b/tests/Exception/MissingProjectIdCredentialExceptionTest.php
@@ -6,15 +6,19 @@
use PHPUnit\Framework\TestCase;
use Sentry\Exception\MissingProjectIdCredentialException;
+use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
final class MissingProjectIdCredentialExceptionTest extends TestCase
{
+ use ExpectDeprecationTrait;
+
/**
* @group legacy
- * @expectedDeprecationMessage The Sentry\Exception\MissingProjectIdCredentialException class is deprecated since version 2.4 and will be removed in 3.0.
*/
public function testGetMessage(): void
{
+ $this->expectDeprecation('The Sentry\\Exception\\MissingProjectIdCredentialException class is deprecated since version 2.4 and will be removed in 3.0.');
+
$exception = new MissingProjectIdCredentialException();
$this->assertSame('The project ID of the DSN is required to authenticate with the Sentry server.', $exception->getMessage());
diff --git a/tests/Exception/MissingPublicKeyCredentialExceptionTest.php b/tests/Exception/MissingPublicKeyCredentialExceptionTest.php
index 01b9a0e167..78c6c51be4 100644
--- a/tests/Exception/MissingPublicKeyCredentialExceptionTest.php
+++ b/tests/Exception/MissingPublicKeyCredentialExceptionTest.php
@@ -6,15 +6,19 @@
use PHPUnit\Framework\TestCase;
use Sentry\Exception\MissingPublicKeyCredentialException;
+use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
final class MissingPublicKeyCredentialExceptionTest extends TestCase
{
+ use ExpectDeprecationTrait;
+
/**
* @group legacy
- * @expectedDeprecationMessage The Sentry\Exception\MissingPublicKeyCredentialExceptionTest class is deprecated since version 2.4 and will be removed in 3.0.
*/
public function testGetMessage(): void
{
+ $this->expectDeprecation('The Sentry\\Exception\\MissingPublicKeyCredentialException class is deprecated since version 2.4 and will be removed in 3.0.');
+
$exception = new MissingPublicKeyCredentialException();
$this->assertSame('The public key of the DSN is required to authenticate with the Sentry server.', $exception->getMessage());
diff --git a/tests/Integration/ModulesIntegrationTest.php b/tests/Integration/ModulesIntegrationTest.php
index 6f359b9f37..da25c7bb00 100644
--- a/tests/Integration/ModulesIntegrationTest.php
+++ b/tests/Integration/ModulesIntegrationTest.php
@@ -11,10 +11,13 @@
use Sentry\Integration\ModulesIntegration;
use Sentry\SentrySdk;
use Sentry\State\Scope;
+use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use function Sentry\withScope;
final class ModulesIntegrationTest extends TestCase
{
+ use ExpectDeprecationTrait;
+
/**
* @dataProvider invokeDataProvider
*/
@@ -59,11 +62,11 @@ public function invokeDataProvider(): \Generator
/**
* @group legacy
- *
- * @expectedDeprecationMessage The "Sentry\Integration\ModulesIntegration::applyToEvent" method is deprecated since version 2.4 and will be removed in 3.0.
*/
public function testApplyToEvent(): void
{
+ $this->expectDeprecation('The "Sentry\Integration\ModulesIntegration::applyToEvent" method is deprecated since version 2.4 and will be removed in 3.0.');
+
$event = new Event();
$integration = new ModulesIntegration();
$integration->applyToEvent($integration, $event);
diff --git a/tests/OptionsTest.php b/tests/OptionsTest.php
index 1e3679b69e..e6cd5fedac 100644
--- a/tests/OptionsTest.php
+++ b/tests/OptionsTest.php
@@ -14,10 +14,13 @@
use Sentry\Integration\RequestIntegration;
use Sentry\Integration\TransactionIntegration;
use Sentry\Options;
+use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
final class OptionsTest extends TestCase
{
+ use ExpectDeprecationTrait;
+
/**
* @group legacy
*
@@ -81,11 +84,17 @@ public function optionsDataProvider(): array
* @group legacy
*
* @dataProvider dsnOptionDataProvider
- *
- * @expectedDeprecationMessage Calling the method getDsn() and expecting it to return a string is deprecated since version 2.4 and will stop working in 3.0.
*/
public function testDsnOption($value, ?string $expectedProjectId, ?string $expectedPublicKey, ?string $expectedSecretKey, ?string $expectedDsnAsString, ?Dsn $expectedDsnAsObject): void
{
+ $this->expectDeprecation('Method Sentry\\Options::getProjectId() is deprecated since version 2.4 and will be removed in 3.0. Use the getDsn() method instead.');
+ $this->expectDeprecation('Method Sentry\\Options::getPublicKey() is deprecated since version 2.4 and will be removed in 3.0. Use the getDsn() method instead.');
+ $this->expectDeprecation('Method Sentry\\Options::getSecretKey() is deprecated since version 2.4 and will be removed in 3.0. Use the getDsn() method instead.');
+
+ if (null !== $expectedDsnAsString) {
+ $this->expectDeprecation('Calling the method Sentry\\Options::getDsn() and expecting it to return a string is deprecated since version 2.4 and will stop working in 3.0.');
+ }
+
$options = new Options(['dsn' => $value]);
$this->assertSame($expectedProjectId, $options->getProjectId());
@@ -362,11 +371,13 @@ public function contextLinesOptionValidatesInputValueDataProvider(): \Generator
/**
* @group legacy
* @backupGlobals enabled
- *
- * @expectedDeprecationMessage Calling the method getDsn() and expecting it to return a string is deprecated since version 2.4 and will stop working in 3.0.
*/
public function testDsnOptionDefaultValueIsGotFromEnvironmentVariable(): void
{
+ $this->expectDeprecation('Calling the method Sentry\\Options::getDsn() and expecting it to return a string is deprecated since version 2.4 and will stop working in 3.0.');
+ $this->expectDeprecation('Method Sentry\\Options::getPublicKey() is deprecated since version 2.4 and will be removed in 3.0. Use the getDsn() method instead.');
+ $this->expectDeprecation('Method Sentry\\Options::getProjectId() is deprecated since version 2.4 and will be removed in 3.0. Use the getDsn() method instead.');
+
$_SERVER['SENTRY_DSN'] = 'http://public@example.com/1';
$options = new Options();
diff --git a/tests/Serializer/AbstractSerializerTest.php b/tests/Serializer/AbstractSerializerTest.php
index 0ec7c17c80..ea61deb189 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);
}
@@ -453,11 +453,11 @@ public function serializableCallableProvider(): array
],
[
'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 9d96b097f9..f52e501ed8 100644
--- a/tests/StacktraceTest.php
+++ b/tests/StacktraceTest.php
@@ -531,12 +531,12 @@ public function testGetFrameArgumentsDoesNotModifyCapturedArgs(): void
$result = $stacktrace->getFrameArguments($frame);
// Check we haven't modified our vars.
- $this->assertEquals($originalFoo, 'bloopblarp');
- $this->assertEquals($nestedArray['key'], 'xxxxxxxxxx');
+ $this->assertSame('bloopblarp', $originalFoo);
+ $this->assertSame('xxxxxxxxxx', $nestedArray['key']);
// Check that we did truncate the variable in our output
- $this->assertEquals($result['param1'], 'bloop');
- $this->assertEquals($result['param2']['key'], 'xxxxx');
+ $this->assertSame('bloop', $result['param1']);
+ $this->assertSame('xxxxx', $result['param2']['key']);
}
public function testPreserveXdebugFrameArgumentNames(): void
diff --git a/tests/Transport/HttpTransportTest.php b/tests/Transport/HttpTransportTest.php
index bdbb16de28..44197c37f4 100644
--- a/tests/Transport/HttpTransportTest.php
+++ b/tests/Transport/HttpTransportTest.php
@@ -14,9 +14,12 @@
use Sentry\Event;
use Sentry\Options;
use Sentry\Transport\HttpTransport;
+use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
final class HttpTransportTest extends TestCase
{
+ use ExpectDeprecationTrait;
+
public function testSendThrowsIfDsnOptionIsNotSet(): void
{
$transport = new HttpTransport(
@@ -34,11 +37,11 @@ public function testSendThrowsIfDsnOptionIsNotSet(): void
/**
* @group legacy
- *
- * @expectedDeprecationMessage Delaying the sending of the events using the "Sentry\Transport\HttpTransport" class is deprecated since version 2.2 and will not work in 3.0.
*/
public function testSendDelaysExecutionUntilShutdown(): void
{
+ $this->expectDeprecation('Delaying the sending of the events using the "Sentry\Transport\HttpTransport" class is deprecated since version 2.2 and will not work in 3.0.');
+
$promise = new FulfilledPromise('foo');
/** @var HttpAsyncClientInterface&MockObject $httpClient */
@@ -116,11 +119,11 @@ public function testSendLogsErrorMessageIfSendingFailed(): void
/**
* @group legacy
- *
- * @expectedDeprecationMessage Delaying the sending of the events using the "Sentry\Transport\HttpTransport" class is deprecated since version 2.2 and will not work in 3.0.
*/
public function testCloseLogsErrorMessageIfSendingFailed(): void
{
+ $this->expectDeprecation('Delaying the sending of the events using the "Sentry\Transport\HttpTransport" class is deprecated since version 2.2 and will not work in 3.0.');
+
$exception = new \Exception('foo');
$event1 = new Event();
$event2 = new Event();
@@ -165,11 +168,11 @@ public function testCloseLogsErrorMessageIfSendingFailed(): void
/**
* @group legacy
- *
- * @expectedDeprecationMessage Delaying the sending of the events using the "Sentry\Transport\HttpTransport" class is deprecated since version 2.2 and will not work in 3.0.
*/
public function testCloseLogsErrorMessageIfExceptionIsThrownWhileProcessingTheHttpRequest(): void
{
+ $this->expectDeprecation('Delaying the sending of the events using the "Sentry\Transport\HttpTransport" class is deprecated since version 2.2 and will not work in 3.0.');
+
$exception = new \Exception('foo');
/** @var LoggerInterface&MockObject $logger */
diff --git a/tests/Util/JSONTest.php b/tests/Util/JSONTest.php
index f8c60c2d87..6e0a04b155 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;
@@ -139,12 +140,11 @@ public function encodeSubstitutesInvalidUtf8CharactersOnPhp71OrLowerDataProvider
];
}
- /**
- * @expectedException \Sentry\Exception\JsonException
- * @expectedExceptionMessage Could not encode value into JSON format. Error was: "Type is not supported".
- */
public function testEncodeThrowsIfValueIsResource(): void
{
+ $this->expectException(JsonException::class);
+ $this->expectExceptionMessage('Could not encode value into JSON format. Error was: "Type is not supported".');
+
$resource = fopen('php://memory', 'r');
$this->assertNotFalse($resource);
@@ -161,12 +161,12 @@ public function testEncodeRespectsOptionsArgument(): void
/**
* @requires PHP < 7.2
- *
- * @expectedException \Sentry\Exception\JsonException
- * @expectedExceptionMessage Reached the maximum depth limit while sanitizing the data.
*/
public function testEncodeThrowsOnPhp71OrLowerWhenSanitizationReachesMaxDepthLimit(): void
{
+ $this->expectException(JsonException::class);
+ $this->expectExceptionMessage('Reached the maximum depth limit while sanitizing the data.');
+
JSON::encode([[["\x61\xb0\x62"]]], 0, 2);
}
@@ -203,12 +203,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');
}
}
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 82f2fc2b5a..8b7f588b8d 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' . 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