Skip to content

Commit b04e9f7

Browse files
javerramunasd
authored andcommitted
Add PHP 8.1 support
1 parent e1ca4d5 commit b04e9f7

File tree

6 files changed

+47
-4
lines changed

6 files changed

+47
-4
lines changed

.github/workflows/phpunit.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ jobs:
3737
phpseclib: '^3.0'
3838
composer: 'composer:v2'
3939
coverage: none
40+
- php: '8.1'
41+
phpseclib: '^3.0'
42+
composer: 'composer:v2'
43+
coverage: none
4044
services:
4145
rabbitmq:
42-
image: rabbitmq:3-management
46+
image: rabbitmq:3.8-management
4347
ports:
4448
- 5671:5671
4549
- 5672:5672
@@ -53,7 +57,7 @@ jobs:
5357
RABBITMQ_SSL_KEYFILE: /src/tests/certs/server_key.pem
5458
RABBITMQ_SSL_VERIFY: verify_peer
5559
RABBITMQ_SSL_FAIL_IF_NO_PEER_CERT: 0
56-
name: PHP ${{ matrix.php }} Test on ${{ matrix.operating-system }}
60+
name: PHP ${{ matrix.php }} + phpseclib ${{ matrix.phpseclib }}
5761
steps:
5862
- name: Checkout
5963
uses: actions/checkout@v2
@@ -70,7 +74,7 @@ jobs:
7074
run: php tests/phpinfo.php
7175

7276
- name: Start broker service
73-
run: docker start ${{ job.services.rabbitmq.id }}
77+
run: docker restart ${{ job.services.rabbitmq.id }}
7478

7579
- name: Composer install
7680
run: composer require --prefer-dist --no-progress --no-suggest phpseclib/phpseclib ${{ matrix.phpseclib }}

PhpAmqpLib/Wire/AMQPAbstractCollection.php

+9
Original file line numberDiff line numberDiff line change
@@ -196,23 +196,27 @@ final protected function decodeCollection(array $val)
196196
return $val;
197197
}
198198

199+
#[\ReturnTypeWillChange]
199200
public function offsetExists($offset)
200201
{
201202
return isset($this->data[$offset]);
202203
}
203204

205+
#[\ReturnTypeWillChange]
204206
public function offsetGet($offset)
205207
{
206208
$value = isset($this->data[$offset]) ? $this->data[$offset] : null;
207209

208210
return is_array($value) ? $value[1] : $value;
209211
}
210212

213+
#[\ReturnTypeWillChange]
211214
public function offsetSet($offset, $value)
212215
{
213216
$this->setValue($value, null, $offset);
214217
}
215218

219+
#[\ReturnTypeWillChange]
216220
public function offsetUnset($offset)
217221
{
218222
unset($this->data[$offset]);
@@ -467,26 +471,31 @@ final public static function getDataTypeForSymbol($symbol)
467471
return $symbols[$symbol];
468472
}
469473

474+
#[\ReturnTypeWillChange]
470475
public function current()
471476
{
472477
return current($this->data);
473478
}
474479

480+
#[\ReturnTypeWillChange]
475481
public function key()
476482
{
477483
return key($this->data);
478484
}
479485

486+
#[\ReturnTypeWillChange]
480487
public function next()
481488
{
482489
next($this->data);
483490
}
484491

492+
#[\ReturnTypeWillChange]
485493
public function rewind()
486494
{
487495
reset($this->data);
488496
}
489497

498+
#[\ReturnTypeWillChange]
490499
public function valid()
491500
{
492501
return key($this->data) !== null;

PhpAmqpLib/Wire/AMQPWriter.php

+12
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ public function write_signed_longlong($n)
283283
*/
284284
public function write_shortstr($s)
285285
{
286+
if ($s === null) {
287+
$this->write_octet(0);
288+
289+
return $this;
290+
}
291+
286292
$len = mb_strlen($s, 'ASCII');
287293
if ($len > 255) {
288294
throw new AMQPInvalidArgumentException('String too long');
@@ -302,6 +308,12 @@ public function write_shortstr($s)
302308
*/
303309
public function write_longstr($s)
304310
{
311+
if ($s === null) {
312+
$this->write_long(0);
313+
314+
return $this;
315+
}
316+
305317
$this->write_long(mb_strlen($s, 'ASCII'));
306318
$this->out .= $s;
307319

PhpAmqpLib/Wire/IO/StreamIO.php

+4
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ protected function do_select($sec, $usec)
344344
$write = null;
345345
$except = null;
346346

347+
if ($sec === null && PHP_VERSION_ID >= 80100) {
348+
$usec = null;
349+
}
350+
347351
return stream_select($read, $write, $except, $sec, $usec);
348352
}
349353

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
}
3030
],
3131
"require": {
32-
"php": "^7.0||~8.0.0",
32+
"php": "^7.0||^8.0",
3333
"ext-sockets": "*",
3434
"ext-mbstring": "*",
3535
"phpseclib/phpseclib": "^2.0|^3.0"

tests/Unit/Wire/AMQPWriterTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ public function write_table_with_invalid_type()
123123
]);
124124
}
125125

126+
/**
127+
* @test
128+
*/
129+
public function write_table_with_null_strings()
130+
{
131+
$this->writer->write_table([
132+
'x-long-str' => ['S', null],
133+
'x-short-str' => ['s', null],
134+
]);
135+
136+
$expected = "\x00\x00\x00\x1e\x0ax-long-strS\x00\x00\x00\x00\x0bx-short-strs\x00";
137+
$this->assertEquals($expected, $this->writer->getvalue());
138+
}
139+
126140
protected function setProtoVersion($proto)
127141
{
128142
$r = new \ReflectionProperty('\\PhpAmqpLib\\Wire\\AMQPAbstractCollection', 'protocol');

0 commit comments

Comments
 (0)