Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
*.lock
package.xml
/vendor
vendor
.idea
.php_cs.cache
docs/_build
.phpunit.result.cache
tests/clover.xml
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
1 change: 0 additions & 1 deletion psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
<MissingReturnType errorLevel="info" />
<MissingPropertyType errorLevel="info" />
<InvalidDocblock errorLevel="info" />
<MisplacedRequiredParam errorLevel="info" />

<PropertyNotSetInConstructor errorLevel="info">
<errorLevel type="suppress">
Expand Down
2 changes: 1 addition & 1 deletion src/Context/TagsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function offsetSet($offset, $value): void
/**
* Sanitizes the given data by converting numeric values to strings.
*
* @param array<string, string> $data The data to sanitize
* @param mixed[] $data The data to sanitize
*
* @return array<string, string>
*
Expand Down
16 changes: 8 additions & 8 deletions src/Stacktrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
Expand Down
15 changes: 7 additions & 8 deletions tests/BreadcrumbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
53 changes: 31 additions & 22 deletions tests/ClientBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
18 changes: 2 additions & 16 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public function testCaptureLastError(): void

$client->captureLastError();

$this->clearLastError();
error_clear_last();
}

public function testCaptureLastErrorDoesNothingWhenThereIsNoError(): void
Expand All @@ -254,7 +254,7 @@ public function testCaptureLastErrorDoesNothingWhenThereIsNoError(): void
->setTransportFactory($this->createTransportFactory($transport))
->getClient();

$this->clearLastError();
error_clear_last();

$client->captureLastError();
}
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion tests/Exception/MissingProjectIdCredentialExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 5 additions & 1 deletion tests/Exception/MissingPublicKeyCredentialExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
7 changes: 5 additions & 2 deletions tests/Integration/ModulesIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down
Loading