Skip to content

Commit 7859f81

Browse files
Merge pull request #682 from bugsnag/php85support
Updated tests for PHP 8.5
2 parents f66649a + 7d3d525 commit 7859f81

12 files changed

+210
-5
lines changed

.github/workflows/test-package.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ jobs:
2525
guzzle-version: '^7.0'
2626
- php-version: '8.3'
2727
guzzle-version: '^7.0'
28-
# PHP 8.4 skipped pending PLAT-14402
29-
#- php-version: '8.4'
30-
# guzzle-version: '^7.9'
28+
- php-version: '8.4'
29+
guzzle-version: '^7.9'
30+
- php-version: '8.5'
31+
guzzle-version: '^7.10'
3132

3233
steps:
3334
- uses: actions/checkout@v2

tests/RequestTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ public function testGetCurrentUrl()
200200

201201
$method = (new ReflectionClass($request))->getMethod('getCurrentUrl');
202202

203-
$method->setAccessible(true);
203+
if (PHP_VERSION_ID < 80100) { // No effect since 8.1, deprecated in 8.5
204+
$method->setAccessible(true);
205+
}
204206

205207
$this->assertSame('http://example.com/blah/blah.php?some=param', $method->invoke($request));
206208
}
@@ -211,7 +213,9 @@ public function testRequestIp()
211213

212214
$method = (new ReflectionClass($request))->getMethod('getRequestIp');
213215

214-
$method->setAccessible(true);
216+
if (PHP_VERSION_ID < 80100) { // No effect since 8.1, deprecated in 8.5
217+
$method->setAccessible(true);
218+
}
215219

216220
$this->assertSame('123.45.67.8', $method->invoke($request));
217221
}

tests/phpt/handler_should_increase_memory_limit_by_configured_amount_on_oom.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ $a = str_repeat('a', 2147483647);
1818

1919
echo "No OOM!\n";
2020
?>
21+
--SKIPIF--
22+
<?php
23+
if (PHP_VERSION_ID >= 80500) {
24+
echo 'SKIP — this test has a different output in PHP 8.5+';
25+
}
26+
?>
2127
--EXPECTF--
2228
string(7) "5242880"
2329

tests/phpt/handler_should_not_increase_memory_limit_when_memory_limit_increase_is_disabled.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ $a = str_repeat('a', 2147483647);
2020

2121
echo "No OOM!\n";
2222
?>
23+
--SKIPIF--
24+
<?php
25+
if (PHP_VERSION_ID >= 80500) {
26+
echo 'SKIP — this test has a different output in PHP 8.5+';
27+
}
28+
?>
2329
--EXPECTF--
2430
string(2) "5M"
2531

tests/phpt/handler_should_report_compile_errors.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ var_dump('I should not be reached');
1717
if (PHP_MAJOR_VERSION < 7) {
1818
echo 'SKIP — this is a different error in PHP 5';
1919
}
20+
if (PHP_VERSION_ID >= 80500) {
21+
echo 'SKIP — this test has a different output in PHP 8.5+';
22+
}
2023
?>
2124
--EXPECTF--
2225
Fatal error: A class constant must not be called 'class'; it is reserved for class name fetching in %s/compile_error.php on line 9

tests/phpt/handler_should_report_oom_from_large_allocation.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ $a = str_repeat('a', 2147483647);
1212

1313
echo "No OOM!\n";
1414
?>
15+
--SKIPIF--
16+
<?php
17+
if (PHP_VERSION_ID >= 80500) {
18+
echo 'SKIP — this test has a different output in PHP 8.5+';
19+
}
20+
?>
1521
--EXPECTF--
1622
Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s on line 8
1723
Guzzle request made (1 event)!

tests/phpt/handler_should_report_oom_from_small_allocations.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ echo "No OOM!\n";
2525
if (PHP_MAJOR_VERSION < 7) {
2626
echo "SKIP - PHP 5 does not run OOM in this test";
2727
}
28+
if (PHP_VERSION_ID >= 80500) {
29+
echo 'SKIP — this test has a different output in PHP 8.5+';
30+
}
2831
?>
2932
--EXPECTF--
3033
Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s on line %d
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
Bugsnag\Handler should increase the memory limit by the configured amount when an OOM happens
3+
--FILE--
4+
<?php
5+
$client = require __DIR__ . '/../_prelude.php';
6+
$client->setMemoryLimitIncrease(1024 * 1024 * 10);
7+
8+
Bugsnag\Handler::register($client);
9+
10+
ini_set('memory_limit', 1024 * 1024 * 5);
11+
var_dump(ini_get('memory_limit'));
12+
13+
$client->registerCallback(function () {
14+
var_dump(ini_get('memory_limit'));
15+
});
16+
17+
$a = str_repeat('a', 2147483647);
18+
19+
echo "No OOM!\n";
20+
?>
21+
--SKIPIF--
22+
<?php
23+
if (PHP_VERSION_ID < 80500) {
24+
echo 'SKIP — this case is already tested in PHP <8.5';
25+
}
26+
?>
27+
--EXPECTF--
28+
string(7) "5242880"
29+
30+
Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s on line 14
31+
Stack trace:
32+
#0 Standard input code(14): str_repeat('a', 2147483647)
33+
#1 {main}
34+
string(8) "15728640"
35+
Guzzle request made (1 event)!
36+
* Method: 'POST'
37+
* URI: 'http://localhost/notify'
38+
* Events:
39+
- Allowed memory size of %d bytes exhausted (tried to allocate %d bytes)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Bugsnag\Handler should not increase the memory limit when memoryLimitIncrease is disabled
3+
--FILE--
4+
<?php
5+
$client = require __DIR__ . '/../_prelude.php';
6+
$client->setMemoryLimitIncrease(null);
7+
8+
ini_set('memory_limit', '5M');
9+
var_dump(ini_get('memory_limit'));
10+
11+
$client->registerCallback(function () {
12+
// This should be the same as the first var_dump, because we should not have
13+
// increase the memory limit
14+
var_dump(ini_get('memory_limit'));
15+
});
16+
17+
Bugsnag\Handler::register($client);
18+
19+
$a = str_repeat('a', 2147483647);
20+
21+
echo "No OOM!\n";
22+
?>
23+
--SKIPIF--
24+
<?php
25+
if (PHP_VERSION_ID < 80500) {
26+
echo 'SKIP — this case is already tested in PHP <8.5';
27+
}
28+
?>
29+
--EXPECTF--
30+
string(2) "5M"
31+
32+
Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s on line 16
33+
Stack trace:
34+
#0 Standard input code(16): str_repeat('a', 2147483647)
35+
#1 {main}
36+
string(2) "5M"
37+
Guzzle request made (1 event)!
38+
* Method: 'POST'
39+
* URI: 'http://localhost/notify'
40+
* Events:
41+
- Allowed memory size of %d bytes exhausted (tried to allocate %d bytes)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Bugsnag\Handler should report compile errors
3+
4+
https://github.com/php/php-src/blob/2772751b58ee579a8f1288a0949e5e1fcb554877/Zend/zend_API.c#L3965-L3968
5+
--FILE--
6+
<?php
7+
$client = require __DIR__ . '/../_prelude.php';
8+
9+
Bugsnag\Handler::register($client);
10+
11+
include __DIR__ . '/../fixtures/compile_error.php';
12+
13+
var_dump('I should not be reached');
14+
?>
15+
--SKIPIF--
16+
<?php
17+
if (PHP_VERSION_ID < 80500) {
18+
echo 'SKIP — this case is already tested in PHP <8.5';
19+
}
20+
?>
21+
--EXPECTF--
22+
Fatal error: A class constant must not be called 'class'; it is reserved for class name fetching in %s/compile_error.php on line 9
23+
Stack trace:
24+
#0 {main}
25+
Guzzle request made (1 event)!
26+
* Method: 'POST'
27+
* URI: 'http://localhost/notify'
28+
* Events:
29+
- A class constant must not be called 'class'; it is reserved for class name fetching

0 commit comments

Comments
 (0)