Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

PHP 8 Support #1087

Merged
merged 48 commits into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
6912ec9
Allow PHP 8
Jean85 Sep 13, 2020
bc566e7
Test against 8 in CI
Jean85 Sep 13, 2020
5aa5ecd
Remove false positive from PHPStan ignore list
Jean85 Sep 13, 2020
b5a13c7
Use nightly definition in CI
Jean85 Sep 13, 2020
e61a803
Update PHPUnit to version 8.5 and remove unnecessary code left behind…
ste93cry Sep 23, 2020
f61343e
Fix CR issues
ste93cry Sep 23, 2020
f477a31
Merge branch 'master' into php8-support
Jean85 Oct 27, 2020
0e4159f
Fix PHPStan error
Jean85 Oct 27, 2020
b39abe0
Try to remove PHPCSFixer under PHP 8
Jean85 Oct 28, 2020
7705230
Fix if statement
Jean85 Oct 29, 2020
7faa532
Fix composer command
Jean85 Oct 29, 2020
de3e9ac
Update PHPUnit
Jean85 Oct 29, 2020
e9cc1a6
Ignore PHPUnit cache
Jean85 Oct 29, 2020
020e2a4
Update Psalm
Jean85 Oct 29, 2020
ba682ab
Allow older Psalm too
Jean85 Oct 29, 2020
50fe135
Migrate PHPUnit config
Jean85 Oct 29, 2020
a1c8928
Fix PHPT tests
Jean85 Oct 29, 2020
f0d1c3a
Fix more PHPT tests
Jean85 Oct 29, 2020
eb82bb2
Merge #1093 into php8-support
Jean85 Oct 30, 2020
cfabee9
Bump Psalm 4 constaint
Jean85 Nov 3, 2020
63c3e72
Migrate the error handling for the @ operator to php 8 state (#1141)
chris-doehring Nov 27, 2020
9ebd382
Update guzzlehttp/promises and symfony/options-resolver to the minimu…
chris-doehring Nov 28, 2020
34b24c0
Remove unused phpstan ignore rule
stayallive Nov 30, 2020
e6fed3e
Test against PHP 8.0.0 stable
ste93cry Nov 30, 2020
cee4a63
Revert unneeded changes to PHPT tests
ste93cry Nov 30, 2020
8ec4f03
Fix various issues (CS, revert breaking changes, etc)
ste93cry Nov 30, 2020
c5a03c0
Revert more unneeded changes to make the diff smaller
ste93cry Nov 30, 2020
3cb4eb7
Merge branch 'master' into php8-support
ste93cry Nov 30, 2020
e89626a
Adapt Xdebug config on AppVeyor for version 3
ste93cry Nov 30, 2020
68c8872
Bump minimum required version of PHPUnit 8 to avoid bugged version
ste93cry Nov 30, 2020
d450f80
Revert breaking changes
ste93cry Dec 2, 2020
ee8bacd
Merge branch 'master' into php8-support
ste93cry Dec 2, 2020
1749fe8
Requier nikic/php-parser ^4.10.3 due to nikic/PHP-Parser#736
Jean85 Dec 4, 2020
eef1ab9
Stop using deprecated --no-suggest flag of Composer
ste93cry Dec 5, 2020
3a72391
Revert one more breaking change
ste93cry Dec 3, 2020
f8ac3bd
Fix AppVeyor CI
ste93cry Dec 5, 2020
79c4d46
Use refreshenv command to reload changed env vars in AppVeyor
ste93cry Dec 5, 2020
56360ec
Revert how Composer is installed to AppVeyor
ste93cry Dec 5, 2020
13eaa9c
Update Xdebug to version 3.0.1 on Travis CI
ste93cry Dec 5, 2020
73ef998
Use more recent version of Ubuntu as base image
ste93cry Dec 5, 2020
ba4f3b4
Uninstall old Xdebug before installing the new version
ste93cry Dec 5, 2020
aebc0e8
Add missing XDEBUG_MODE env var
ste93cry Dec 5, 2020
45c6763
Adjust memory limit in PHPT test to avoid PHPUnit OOM fatal error
ste93cry Dec 5, 2020
461fd71
Fix code coverage config not being compatible with PHPUnit 8.5
ste93cry Dec 5, 2020
98fb75f
Fix wrong path to Composer executable in AppVeyor
ste93cry Dec 5, 2020
25f5f5f
Fix Xdebug version for PHP8 on AppVeyor
ste93cry Dec 5, 2020
7a8134c
Fix AppVeyor build (finally!)
ste93cry Dec 5, 2020
e98d1b5
Revert breaking change
ste93cry Dec 5, 2020
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
33 changes: 18 additions & 15 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
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

environment:
matrix:
- PHP_VERSION: 7.2
XDEBUG_VERSION: 2.9.2-7.2-vc15-nts
XDEBUG_VERSION: 3.0.1-7.2-vc15-nts
DEPENDENCIES: lowest
- PHP_VERSION: 7.2
XDEBUG_VERSION: 2.9.2-7.2-vc15-nts
XDEBUG_VERSION: 3.0.1-7.2-vc15-nts
DEPENDENCIES: highest
- PHP_VERSION: 7.3
XDEBUG_VERSION: 2.9.2-7.3-vc15-nts
XDEBUG_VERSION: 3.0.1-7.3-vc15-nts
DEPENDENCIES: lowest
- PHP_VERSION: 7.3
XDEBUG_VERSION: 2.9.2-7.3-vc15-nts
XDEBUG_VERSION: 3.0.1-7.3-vc15-nts
DEPENDENCIES: highest
- PHP_VERSION: 7.4
XDEBUG_VERSION: 2.9.2-7.4-vc15-nts
XDEBUG_VERSION: 3.0.1-7.4-vc15-nts
DEPENDENCIES: lowest
- PHP_VERSION: 7.4
XDEBUG_VERSION: 2.9.2-7.4-vc15-nts
XDEBUG_VERSION: 3.0.1-7.4-vc15-nts
DEPENDENCIES: highest
- PHP_VERSION: 8.0
XDEBUG_VERSION: 3.0.1-8.0-vs16-nts
DEPENDENCIES: lowest
- PHP_VERSION: 8.0
XDEBUG_VERSION: 3.0.1-8.0-vs16-nts
DEPENDENCIES: highest

matrix:
Expand Down Expand Up @@ -52,16 +58,13 @@ 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/1.9.3/composer.phar
- 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 %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 %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

test_script:
- cd C:\projects\sentry-php
Expand Down
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package.xml
/vendor
.idea
.php_cs.cache
.phpunit.result.cache
docs/_build
tests/clover.xml
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ php:
- 7.2
- 7.3
- 7.4
- 8.0

env:
- dependencies=highest
Expand Down Expand Up @@ -34,11 +35,12 @@ jobs:
script: composer psalm

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:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 3.1.0 (2020-12-01)

- 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)
- Fix capturing of the request body in the `RequestIntegration` integration (#1139)
- Deprecate `SpanContext::fromTraceparent()` in favor of `TransactionContext::fromSentryTrace()` (#1134)
- Allow setting custom data on the sampling context by passing it as 2nd argument of the `startTransaction()` function (#1134)
Expand Down
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2|^8.0",
"ext-json": "*",
"ext-mbstring": "*",
"guzzlehttp/promises": "^1.3",
"guzzlehttp/promises": "^1.4",
"guzzlehttp/psr7": "^1.7",
"jean85/pretty-package-versions": "^1.5",
"ocramius/package-versions": "^1.8",
Expand All @@ -35,21 +35,22 @@
"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"
},
"require-dev": {
"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",
"phpstan/phpstan-phpunit": "^0.12",
"phpunit/phpunit": "^7.5.18",
"symfony/phpunit-bridge": "^5.1",
"vimeo/psalm": "^3.4"
"phpunit/phpunit": "^8.5.13|^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."
Expand Down
9 changes: 8 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="true"
colors="true"
bootstrap="tests/bootstrap.php"
cacheResult="false"
beStrictAboutOutputDuringTests="true"
>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0" />
Expand All @@ -17,6 +18,12 @@
</testsuite>
</testsuites>

<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>

<filter>
<whitelist>
<directory suffix=".php">src</directory>
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/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* This interface must be implemented by all exception classes of this library.
*
* @author Stefano Arlandini <sarlandini@alice.it>
*
* @deprecated since version 3.1, to be removed in 4.0
*/
interface ExceptionInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* the expected value.
*
* @author Stefano Arlandini <sarlandini@alice.it>
*
* @deprecated since version 3.1, to be removed in 4.0
*/
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
Expand Down
16 changes: 7 additions & 9 deletions tests/BreadcrumbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
16 changes: 14 additions & 2 deletions tests/ClientBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
use Sentry\Options;
use Sentry\Transport\HttpTransport;
use Sentry\Transport\NullTransport;
use Sentry\Transport\TransportInterface;

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');
$transport = $this->getTransport($clientBuilder->getClient());

$this->assertInstanceOf(HttpTransport::class, $transport);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
28 changes: 6 additions & 22 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -271,7 +271,7 @@ public function testCaptureLastError(): void

$this->assertNotNull($client->captureLastError());

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

public function testCaptureLastErrorDoesNothingWhenThereIsNoError(): void
Expand All @@ -280,14 +280,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());
}
Expand Down Expand Up @@ -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, 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);
Expand Down Expand Up @@ -448,20 +446,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 {
Expand Down
Loading