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

Update to PHP 8 and PHPUnit 10 #122

Closed
wants to merge 5 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
phpunit.xml
.phpunit.cache
vendor
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
dist: trusty
dist: bionic
sudo: false

language: php
php:
- '7.1'
- '8.1.0'

install:
- composer install
Expand Down
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@
"homepage": "https://airbrake.io",
"license": "MIT",
"require": {
"php": ">=5.4",
"php": ">=8.1",
"guzzlehttp/guzzle": ">=6.3",
"cash/lrucache": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^2.9",
"phpunit/phpunit": "^10.0",
"squizlabs/php_codesniffer": "^3.7",
"monolog/monolog": "^1.22|^2.0",
"mikey179/vfsstream": "^1.6"
},
"suggest": {
"guzzlehttp/guzzle": "Guzzle HTTP client"
},
"autoload": {
"files": [
"src/constants.php"
],
"psr-4": {
"Airbrake\\": "src/"
}
Expand Down
49 changes: 25 additions & 24 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="Airbrake Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"
bootstrap="vendor/autoload.php"
executionOrder="depends,defects"
backupGlobals="false"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
colors="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">
<coverage/>
<testsuites>
<testsuite name="Airbrake Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
11 changes: 7 additions & 4 deletions src/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
define('ERR_IP_RATE_LIMITED', 'phpbrake: IP is rate limited');
define('ERR_NOTIFICATIONS_DISABLED', 'phpbrake: error notifications are disabled');

const AIRBRAKE_NOTIFIER_VERSION = '0.8.0';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this constant removed?

When I run the unit tests, I see errors mentioning the removed constant. Example:

15) Warning
The data provider specified for Airbrake\Tests\NotifierTest::testPostsToURL is invalid.
Undefined constant "Airbrake\AIRBRAKE_NOTIFIER_VERSION"


/**
* Airbrake exception notifier.
*/
Expand All @@ -26,6 +24,11 @@ class Notifier
*/
protected $opt;

/**
* @var array
*/
private $errorConfig;

/**
* @var callable[]
*/
Expand Down Expand Up @@ -76,7 +79,7 @@ public function __construct($opt)
$opt['keysBlocklist'] = $opt['keysBlacklist'];
}

if (empty($opt['remoteConfig'])) {
if (!isset($opt['remoteConfig'])) {
$opt['remoteConfig'] = true;
}

Expand Down Expand Up @@ -564,7 +567,7 @@ protected function remoteErrorConfig()
return RemoteConfig::DEFAULT_CONFIG;
}

if (isset($this->errorConfig)) {
if ($this->errorConfig !== null) {
return $this->errorConfig;
}

Expand Down
5 changes: 5 additions & 0 deletions src/constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace Airbrake;

const AIRBRAKE_NOTIFIER_VERSION = '0.8.0';
6 changes: 3 additions & 3 deletions tests/ChecksForError.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public function testPostsError($notifier)
{
$notice = $notifier->notice;
$error = $notice['errors'][0];
$this->assertEquals('E_NOTICE', $error['type']);
$this->assertEquals('Undefined variable: undefinedVar', $error['message']);
$this->assertEquals('E_WARNING', $error['type']);
$this->assertEquals('Undefined variable $undefinedVar', $error['message']);
}

/** @dataProvider undefinedVarErrorProvider */
Expand Down Expand Up @@ -47,5 +47,5 @@ public function testPostsErrorBacktrace($notifier)
}
}

abstract public function undefinedVarErrorProvider();
abstract public static function undefinedVarErrorProvider();
}
2 changes: 1 addition & 1 deletion tests/ChecksForException.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ public function testPostsToURL($notifier)
);
}

abstract public function exceptionProvider();
abstract public static function exceptionProvider();
}
22 changes: 11 additions & 11 deletions tests/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Airbrake\Tests;

use PHPUnit_Framework_TestCase;
use PHPUnit\Framework\TestCase;

class ErrorHandlerTest extends PHPUnit_Framework_TestCase
class ErrorHandlerTest extends TestCase
{
use ChecksForError;
use ChecksForException;

public function exceptionProvider()
public static function exceptionProvider()
{
$notifier = new NotifierMock([
'projectId' => 1,
Expand All @@ -25,15 +25,15 @@ public function exceptionProvider()
return [[$notifier]];
}

public function undefinedVarErrorProvider()
public static function undefinedVarErrorProvider()
{
return [
[$this->arrangeOnErrorNotifier(), 'OnError'],
[$this->arrangeOnShutdownNotifier(), 'OnShutdown'],
[self::arrangeOnErrorNotifier(), 'OnError'],
[self::arrangeOnShutdownNotifier(), 'OnShutdown'],
];
}

private function makeHandlerBoundNotifier()
private static function makeHandlerBoundNotifier()
{
$notifier = new NotifierMock([
'projectId' => 1,
Expand All @@ -45,19 +45,19 @@ private function makeHandlerBoundNotifier()
return [$notifier, $handler];
}

private function arrangeOnErrorNotifier()
private static function arrangeOnErrorNotifier()
{
$saved = error_reporting(E_ALL | E_STRICT);
list($notifier, $handler) = $this->makeHandlerBoundNotifier();
list($notifier) = self::makeHandlerBoundNotifier();
Troublemaker::echoUndefinedVar();
error_reporting($saved);

return $notifier;
}

private function arrangeOnShutdownNotifier()
private static function arrangeOnShutdownNotifier()
{
list($notifier, $handler) = $this->makeHandlerBoundNotifier();
list($notifier, $handler) = self::makeHandlerBoundNotifier();
@Troublemaker::echoUndefinedVar();
$handler->onShutdown();

Expand Down
14 changes: 7 additions & 7 deletions tests/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Airbrake\Tests;

use PHPUnit_Framework_TestCase;
use PHPUnit\Framework\TestCase;

class FilterTest extends PHPUnit_Framework_TestCase
class FilterTest extends TestCase
{
private function makeNotifierWithFilter(callable $filter)
private static function makeNotifierWithFilter(callable $filter)
{
$notifier = new NotifierMock([
'projectId' => 1,
Expand All @@ -22,11 +22,11 @@ private function makeNotifierWithFilter(callable $filter)
*/
public function testNoticeIsIgnored($filter, $comment)
{
$notifier = $this->makeNotifierWithFilter($filter);
$notifier = self::makeNotifierWithFilter($filter);
$this->assertNull($notifier->notice, $comment);
}

public function negativeFilterProvider()
public static function negativeFilterProvider()
{
return [
[
Expand Down Expand Up @@ -60,9 +60,9 @@ public function testEnvironmentIsUnset($notifier)
$this->assertFalse(isset($notifier->notice['environment']));
}

public function filterFullNotifierProvider()
public static function filterFullNotifierProvider()
{
return [[$this->makeNotifierWithFilter(function () {
return [[self::makeNotifierWithFilter(function () {
$notice['context']['environment'] = 'production';
unset($notice['environment']);

Expand Down
8 changes: 5 additions & 3 deletions tests/MonologBacktraceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace Airbrake\Tests;

use PHPUnit_Framework_TestCase;
use PHPUnit\Framework\TestCase;

class MonologBacktraceTest extends PHPUnit_Framework_TestCase
class MonologBacktraceTest extends TestCase
{
public function setUp()
private NotifierMock $notifier;

public function setUp(): void
{
$this->notifier = new NotifierMock([
'projectId' => 1,
Expand Down
8 changes: 5 additions & 3 deletions tests/MonologHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace Airbrake\Tests;

use PHPUnit_Framework_TestCase;
use PHPUnit\Framework\TestCase;

class MonologHandlerTest extends PHPUnit_Framework_TestCase
class MonologHandlerTest extends TestCase
{
public function setUp()
private NotifierMock $notifier;

public function setUp(): void
{
$this->notifier = new NotifierMock([
'projectId' => 1,
Expand Down
Loading