Skip to content

Commit 0504957

Browse files
committed
Fix PHP 8.4 deprecation warnings and upgrade PHPUnit
1 parent 4a6489e commit 0504957

14 files changed

Lines changed: 1639 additions & 726 deletions

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
"psr/log": "^1.0"
1010
},
1111
"require-dev": {
12+
"ergebnis/phpunit-slow-test-detector": "^2.17",
1213
"phpdocumentor/phpdocumentor": "^2.8.5",
13-
"phpunit/phpunit": "~4.8.20"
14+
"phpunit/phpunit": "~9"
1415
},
1516
"autoload": {
1617
"psr-4": {

composer.lock

Lines changed: 1575 additions & 696 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Client/ClientTracer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ protected function joinFromArray(Span $span, $carrier) {
322322
}
323323

324324
protected function _startsWith($haystack, $needle) {
325-
return (substr($haystack, 0, strlen($needle)) === $needle);
325+
return (str_starts_with($haystack, $needle));
326326
}
327327

328328
// PHP does not have an event loop or timer threads. Instead manually check as

lib/Client/Transports/TransportHTTPJSON.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TransportHTTPJSON {
1919
*/
2020
protected $logger;
2121

22-
public function __construct(LoggerInterface $logger = null) {
22+
public function __construct(?LoggerInterface $logger = null) {
2323

2424
$this->logger = $logger ?: new SystemLogger;
2525
$this->_timeout = ini_get("default_socket_timeout");

lib/Client/Transports/TransportHTTPPROTO.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TransportHTTPPROTO {
1919
*/
2020
protected $logger;
2121

22-
public function __construct(LoggerInterface $logger = null) {
22+
public function __construct(?LoggerInterface $logger = null) {
2323

2424
$this->logger = $logger ?: new SystemLogger;
2525
$this->_timeout = ini_get("default_socket_timeout");

lib/Client/Transports/TransportUDP.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ class TransportUDP {
1010

1111
protected $_sock = NULL;
1212
protected $_host = NULL;
13-
protected $_post = NULL;
13+
protected $_port = NULL;
1414
/**
1515
* @var LoggerInterface
1616
*/
1717
protected $logger;
1818

19-
public function __construct(LoggerInterface $logger = null) {
19+
public function __construct(?LoggerInterface $logger = null) {
2020

2121
$this->logger = $logger ?: new SystemLogger;
2222
}

lib/vendor/Thrift/ClassLoader/ThriftClassLoader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* under the License.
1919
*
2020
* ClassLoader to load Thrift library and definitions
21-
* Inspired from UniversalClassLoader from Symfony 2
21+
* Inspired from UniversalClassLoader from Symfony 2
2222
*
2323
* @package thrift.classloader
2424
*/
@@ -146,7 +146,7 @@ public function findFile($class)
146146
foreach ($this->namespaces as $ns => $dirs)
147147
{
148148
//Don't interfere with other autoloaders
149-
if (0 !== strpos($namespace, $ns))
149+
if (!str_starts_with($namespace, $ns))
150150
{
151151
continue;
152152
}
@@ -184,7 +184,7 @@ public function findFile($class)
184184
foreach ($this->definitions as $ns => $dirs)
185185
{
186186
//Don't interfere with other autoloaders
187-
if (0 !== strpos($namespace, $ns))
187+
if (!str_starts_with($namespace, $ns))
188188
{
189189
continue;
190190
}

phpunit.xml.dist

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
35
colors="true"
6+
failOnWarning="true"
47
processIsolation="false"
58
stopOnFailure="false"
6-
syntaxCheck="false"
9+
failOnRisky="true"
10+
backupGlobals="false"
711
>
812
<php>
913
<ini name="memory_limit" value="-1"/>
@@ -17,31 +21,31 @@
1721
</testsuite>
1822
</testsuites>
1923

20-
<!-- Setup a listener for fixtures -->
21-
<listeners>
22-
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener">
24+
<extensions>
25+
<extension class="Ergebnis\PHPUnit\SlowTestDetector\Extension">
2326
<arguments>
2427
<array>
25-
<element key="slowThreshold">
26-
<integer>250</integer>
28+
<element key="maximum-count">
29+
<integer>40</integer>
2730
</element>
28-
<element key="reportLength">
29-
<integer>50</integer>
31+
<element key="maximum-duration">
32+
<integer>500</integer>
3033
</element>
3134
</array>
3235
</arguments>
33-
</listener>
34-
</listeners>
36+
</extension>
37+
</extensions>
3538

36-
<!-- Prevent coverage reports from looking in tests and vendors -->
37-
<filter>
38-
<blacklist>
39+
<coverage>
40+
<include>
41+
<directory suffix=".php">./lib/</directory>
42+
</include>
43+
<exclude>
3944
<directory suffix=".php">./vendor/</directory>
4045
<directory suffix=".ctp">./vendor/</directory>
41-
4246
<directory suffix=".php">./test/</directory>
4347
<directory suffix=".ctp">./test/</directory>
44-
</blacklist>
45-
</filter>
48+
</exclude>
49+
</coverage>
4650

4751
</phpunit>

test/BaseLightStepTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
22

3+
use PHPUnit\Framework\TestCase;
4+
35
/**
46
* Class BaseLightStepTest
57
* @author Josh Wickham
68
* @copyright &copy; 2016 Life360, Inc.
79
* @since 6/10/16
810
*/
9-
abstract class BaseLightStepTest extends PHPUnit_Framework_TestCase
11+
abstract class BaseLightStepTest extends TestCase
1012
{
1113
protected function createTestTracer($component_name, $access_token) {
1214
$opts = [
@@ -24,7 +26,10 @@ protected function createTestTracer($component_name, $access_token) {
2426
* @return mixed
2527
*/
2628
protected function peek($obj, $field) {
27-
return PHPUnit_Framework_Assert::readAttribute($obj, $field);
29+
$reflection = new ReflectionClass($obj);
30+
$property = $reflection->getProperty($field);
31+
$property->setAccessible(true);
32+
return $property->getValue($obj);
2833
}
2934

3035
}

test/ClientTracerTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ class ClientTracerTest extends BaseLightStepTest
1313
*/
1414
public function testCorrectTransportSelected($key, $class)
1515
{
16-
1716
$tracer = new ClientTracer(['transport' => $key]);
1817

19-
$this->assertInstanceOf($class, $this->readAttribute($tracer, '_transport'));
18+
$reflection = new ReflectionClass($tracer);
19+
$property = $reflection->getProperty('_transport');
20+
$property->setAccessible(true);
21+
$tracerTransport = $property->getValue($tracer);
22+
$this->assertInstanceOf($class, $tracerTransport);
2023
}
2124

2225
public function transports()
@@ -61,7 +64,7 @@ public function testSettingCustomTracerAttributes() {
6164
$attributes = $this->peek($tracer, '_options')['attributes'];
6265

6366
$this->assertArrayHasKey('foo', $attributes);
64-
$this->assertSame($attributes['foo'], 'bar');
67+
$this->assertSame('bar', $attributes['foo']);
6568
}
6669

6770
public function testAddingCustomAttributeDoesNotRemoveDefaultAttributes() {

0 commit comments

Comments
 (0)