Skip to content

Commit 393546c

Browse files
authored
add support PHP8.0
* follow php8.0 standard: no required fields allowed after default ones: https://www.php.net/manual/en/migration80.deprecated.php * add php8.0 to travis and github flows * make tests compatible with both php <7.1 and php >=7.1; phpunit 9.5 (for php >=8.0) * fix for php 8: socket_ extension now returns instance of \Socket instead of resource
1 parent 85da8ec commit 393546c

36 files changed

+284
-156
lines changed

.github/workflows/phpunit.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ jobs:
2929
phpseclib: '^3.0'
3030
composer: 'composer:v2'
3131
coverage: 'xdebug'
32+
- php: '8.0'
33+
phpseclib: '^3.0'
34+
composer: 'composer:v2'
35+
coverage: 'xdebug'
3236
services:
3337
rabbitmq:
3438
image: rabbitmq:3-management

PhpAmqpLib/Connection/AbstractConnection.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,15 @@ public function __construct(
181181
$login_method = 'AMQPLAIN',
182182
$login_response = null,
183183
$locale = 'en_US',
184-
AbstractIO $io,
184+
AbstractIO $io = null,
185185
$heartbeat = 0,
186186
$connection_timeout = 0,
187187
$channel_rpc_timeout = 0.0
188188
) {
189+
if (is_null($io)) {
190+
throw new \InvalidArgumentException('"io" can not be null');
191+
}
192+
189193
// save the params for the use of __clone
190194
$this->construct_params = func_get_args();
191195

PhpAmqpLib/Helper/Protocol/Protocol080.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Protocol080
2020
public function connectionStart(
2121
$version_major = 0,
2222
$version_minor = 8,
23-
$server_properties,
23+
$server_properties = [],
2424
$mechanisms = 'PLAIN',
2525
$locales = 'en_US'
2626
) {
@@ -143,7 +143,7 @@ public function connectionRedirect($host, $known_hosts = '')
143143
* @param int $method_id
144144
* @return array
145145
*/
146-
public function connectionClose($reply_code, $reply_text = '', $class_id, $method_id)
146+
public function connectionClose($reply_code, $reply_text, $class_id, $method_id)
147147
{
148148
$writer = new AMQPWriter();
149149
$writer->write_short($reply_code);
@@ -228,7 +228,7 @@ public function channelAlert($reply_code, $reply_text = '', $details = array())
228228
* @param int $method_id
229229
* @return array
230230
*/
231-
public function channelClose($reply_code, $reply_text = '', $class_id, $method_id)
231+
public function channelClose($reply_code, $reply_text, $class_id, $method_id)
232232
{
233233
$writer = new AMQPWriter();
234234
$writer->write_short($reply_code);
@@ -404,7 +404,7 @@ public static function queueDeclareOk(AMQPReader $reader)
404404
public function queueBind(
405405
$ticket = 1,
406406
$queue = '',
407-
$exchange,
407+
$exchange = '',
408408
$routing_key = '',
409409
$nowait = false,
410410
$arguments = array()
@@ -491,7 +491,7 @@ public static function queueDeleteOk(AMQPReader $reader)
491491
* @param \PhpAmqpLib\Wire\AMQPTable|array $arguments
492492
* @return array
493493
*/
494-
public function queueUnbind($ticket = 1, $queue = '', $exchange, $routing_key = '', $arguments = array())
494+
public function queueUnbind($ticket = 1, $queue = '', $exchange = '', $routing_key = '', $arguments = array())
495495
{
496496
$writer = new AMQPWriter();
497497
$writer->write_short($ticket);
@@ -624,7 +624,7 @@ public function basicPublish($ticket = 1, $exchange = '', $routing_key = '', $ma
624624
* @param string $routing_key
625625
* @return array
626626
*/
627-
public function basicReturn($reply_code, $reply_text = '', $exchange, $routing_key)
627+
public function basicReturn($reply_code, $reply_text, $exchange, $routing_key)
628628
{
629629
$writer = new AMQPWriter();
630630
$writer->write_short($reply_code);
@@ -642,7 +642,7 @@ public function basicReturn($reply_code, $reply_text = '', $exchange, $routing_k
642642
* @param string $routing_key
643643
* @return array
644644
*/
645-
public function basicDeliver($consumer_tag, $delivery_tag, $redelivered = false, $exchange, $routing_key)
645+
public function basicDeliver($consumer_tag, $delivery_tag, $redelivered, $exchange, $routing_key)
646646
{
647647
$writer = new AMQPWriter();
648648
$writer->write_shortstr($consumer_tag);
@@ -888,7 +888,7 @@ public function filePublish(
888888
$routing_key = '',
889889
$mandatory = false,
890890
$immediate = false,
891-
$identifier
891+
$identifier = ''
892892
) {
893893
$writer = new AMQPWriter();
894894
$writer->write_short($ticket);
@@ -906,7 +906,7 @@ public function filePublish(
906906
* @param string $routing_key
907907
* @return array
908908
*/
909-
public function fileReturn($reply_code = 200, $reply_text = '', $exchange, $routing_key)
909+
public function fileReturn($reply_code = 200, $reply_text = '', $exchange = '', $routing_key = '')
910910
{
911911
$writer = new AMQPWriter();
912912
$writer->write_short($reply_code);
@@ -928,7 +928,7 @@ public function fileReturn($reply_code = 200, $reply_text = '', $exchange, $rout
928928
public function fileDeliver(
929929
$consumer_tag,
930930
$delivery_tag,
931-
$redelivered = false,
931+
$redelivered,
932932
$exchange,
933933
$routing_key,
934934
$identifier
@@ -1086,7 +1086,7 @@ public function streamPublish(
10861086
* @param string $routing_key
10871087
* @return array
10881088
*/
1089-
public function streamReturn($reply_code = 200, $reply_text = '', $exchange, $routing_key)
1089+
public function streamReturn($reply_code = 200, $reply_text = '', $exchange = '', $routing_key = '')
10901090
{
10911091
$writer = new AMQPWriter();
10921092
$writer->write_short($reply_code);

PhpAmqpLib/Helper/Protocol/Protocol091.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Protocol091
2020
public function connectionStart(
2121
$version_major = 0,
2222
$version_minor = 9,
23-
$server_properties,
23+
$server_properties = [],
2424
$mechanisms = 'PLAIN',
2525
$locales = 'en_US'
2626
) {
@@ -130,7 +130,7 @@ public static function connectionOpenOk(AMQPReader $reader)
130130
* @param int $method_id
131131
* @return array
132132
*/
133-
public function connectionClose($reply_code, $reply_text = '', $class_id, $method_id)
133+
public function connectionClose($reply_code, $reply_text, $class_id, $method_id)
134134
{
135135
$writer = new AMQPWriter();
136136
$writer->write_short($reply_code);
@@ -222,7 +222,7 @@ public static function channelFlowOk(AMQPReader $reader)
222222
* @param int $method_id
223223
* @return array
224224
*/
225-
public function channelClose($reply_code, $reply_text = '', $class_id, $method_id)
225+
public function channelClose($reply_code, $reply_text, $class_id, $method_id)
226226
{
227227
$writer = new AMQPWriter();
228228
$writer->write_short($reply_code);
@@ -290,7 +290,7 @@ public static function accessRequestOk(AMQPReader $reader)
290290
*/
291291
public function exchangeDeclare(
292292
$ticket = 0,
293-
$exchange,
293+
$exchange = '',
294294
$type = 'direct',
295295
$passive = false,
296296
$durable = false,
@@ -325,7 +325,7 @@ public static function exchangeDeclareOk(AMQPReader $reader)
325325
* @param bool $nowait
326326
* @return array
327327
*/
328-
public function exchangeDelete($ticket = 0, $exchange, $if_unused = false, $nowait = false)
328+
public function exchangeDelete($ticket = 0, $exchange = '', $if_unused = false, $nowait = false)
329329
{
330330
$writer = new AMQPWriter();
331331
$writer->write_short($ticket);
@@ -355,8 +355,8 @@ public static function exchangeDeleteOk(AMQPReader $reader)
355355
*/
356356
public function exchangeBind(
357357
$ticket = 0,
358-
$destination,
359-
$source,
358+
$destination = '',
359+
$source = '',
360360
$routing_key = '',
361361
$nowait = false,
362362
$arguments = array()
@@ -392,8 +392,8 @@ public static function exchangeBindOk(AMQPReader $reader)
392392
*/
393393
public function exchangeUnbind(
394394
$ticket = 0,
395-
$destination,
396-
$source,
395+
$destination = '',
396+
$source = '',
397397
$routing_key = '',
398398
$nowait = false,
399399
$arguments = array()
@@ -472,7 +472,7 @@ public static function queueDeclareOk(AMQPReader $reader)
472472
public function queueBind(
473473
$ticket = 0,
474474
$queue = '',
475-
$exchange,
475+
$exchange = '',
476476
$routing_key = '',
477477
$nowait = false,
478478
$arguments = array()
@@ -559,7 +559,7 @@ public static function queueDeleteOk(AMQPReader $reader)
559559
* @param \PhpAmqpLib\Wire\AMQPTable|array $arguments
560560
* @return array
561561
*/
562-
public function queueUnbind($ticket = 0, $queue = '', $exchange, $routing_key = '', $arguments = array())
562+
public function queueUnbind($ticket = 0, $queue = '', $exchange = '', $routing_key = '', $arguments = array())
563563
{
564564
$writer = new AMQPWriter();
565565
$writer->write_short($ticket);
@@ -700,7 +700,7 @@ public function basicPublish(
700700
* @param string $routing_key
701701
* @return array
702702
*/
703-
public function basicReturn($reply_code, $reply_text = '', $exchange, $routing_key)
703+
public function basicReturn($reply_code, $reply_text, $exchange, $routing_key)
704704
{
705705
$writer = new AMQPWriter();
706706
$writer->write_short($reply_code);
@@ -718,7 +718,7 @@ public function basicReturn($reply_code, $reply_text = '', $exchange, $routing_k
718718
* @param string $routing_key
719719
* @return array
720720
*/
721-
public function basicDeliver($consumer_tag, $delivery_tag, $redelivered = false, $exchange, $routing_key)
721+
public function basicDeliver($consumer_tag, $delivery_tag, $redelivered, $exchange, $routing_key)
722722
{
723723
$writer = new AMQPWriter();
724724
$writer->write_shortstr($consumer_tag);

PhpAmqpLib/Wire/IO/SocketIO.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public function write($data)
228228
public function close()
229229
{
230230
$this->disableHeartbeat();
231-
if (is_resource($this->sock)) {
231+
if (is_resource($this->sock) || is_a($this->sock, \Socket::class)) {
232232
socket_close($this->sock);
233233
}
234234
$this->sock = null;
@@ -241,7 +241,7 @@ public function close()
241241
*/
242242
protected function do_select($sec, $usec)
243243
{
244-
if ($this->sock === null || !is_resource($this->sock)) {
244+
if (!is_resource($this->sock) && !is_a($this->sock, \Socket::class)) {
245245
$this->sock = null;
246246
throw new AMQPConnectionClosedException('Broken pipe or closed connection', 0);
247247
}

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ environment:
1919
PHP_VERSION: 7.3
2020
- dependencies: highest
2121
PHP_VERSION: 7.4
22+
- dependencies: highest
23+
PHP_VERSION: 8.0
2224
COMPOSER_CACHE: "%USERPROFILE%\\composer"
2325
RABBITMQ_VERSION: 3.7.17
2426
ERLANG_VERSION: 10.4

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
"require-dev": {
3838
"ext-curl": "*",
39-
"phpunit/phpunit": "^6.5|^7.5",
39+
"phpunit/phpunit": "^6.5|^7.0|^9.5",
4040
"squizlabs/php_codesniffer": "^3.5",
4141
"nategood/httpful": "^0.2.20"
4242
},

tests/Functional/AbstractConnectionTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use PhpAmqpLib\Connection\AMQPSSLConnection;
1010
use PhpAmqpLib\Connection\AMQPStreamConnection;
1111
use PhpAmqpLib\Exchange\AMQPExchangeType;
12-
use PHPUnit\Framework\TestCase;
12+
use PhpAmqpLib\Tests\TestCaseCompat;
1313

14-
abstract class AbstractConnectionTest extends TestCase
14+
abstract class AbstractConnectionTest extends TestCaseCompat
1515
{
1616
public static $blocked = false;
1717

@@ -159,8 +159,21 @@ protected function assertChannelClosed(AbstractChannel $channel)
159159
$this->assertFalse($channel->is_open());
160160
$this->assertEmpty($channel->callbacks);
161161
}
162+
163+
/**
164+
* @test
165+
*/
166+
public function testConstructorIOIsNull()
167+
{
168+
$this->expectException(\InvalidArgumentException::class);
169+
$this->expectExceptionMessage('"io" can not be null');
170+
171+
new AbstractConnectionDummy('', '');
172+
}
162173
}
163174

175+
class AbstractConnectionDummy extends AbstractConnection {}
176+
164177
// mock low level IO write functions
165178
namespace PhpAmqpLib\Wire\IO;
166179

tests/Functional/Bug/Bug256Test.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace PhpAmqpLib\Tests\Functional\Bug;
44

5-
use PhpAmqpLib\Connection\AMQPSocketConnection;
6-
use PhpAmqpLib\Connection\AMQPStreamConnection;
75
use PhpAmqpLib\Message\AMQPMessage;
86
use PhpAmqpLib\Tests\Functional\AbstractConnectionTest;
97
use PhpAmqpLib\Wire\AMQPTable;
@@ -29,7 +27,7 @@ class Bug256Test extends AbstractConnectionTest
2927

3028
protected $channel2;
3129

32-
public function setUp()
30+
protected function setUpCompat()
3331
{
3432
$this->connection = $this->conection_create('socket');
3533
$this->channel = $this->connection->channel();
@@ -43,7 +41,7 @@ public function setUp()
4341
$this->channel2->queue_bind($this->queueName, $this->exchangeName, $this->queueName);
4442
}
4543

46-
public function tearDown()
44+
protected function tearDownCompat()
4745
{
4846
if ($this->channel) {
4947
$this->channel->exchange_delete($this->exchangeName);

tests/Functional/Bug/Bug40Test.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
use PhpAmqpLib\Connection\AMQPStreamConnection;
66
use PhpAmqpLib\Message\AMQPMessage;
7-
use PHPUnit\Framework\TestCase;
7+
use PhpAmqpLib\Tests\TestCaseCompat;
88

99
/**
1010
* @group connection
1111
*/
12-
class Bug40Test extends TestCase
12+
class Bug40Test extends TestCaseCompat
1313
{
1414
protected $exchangeName = 'test_exchange';
1515

@@ -25,7 +25,7 @@ class Bug40Test extends TestCase
2525

2626
protected $channel2;
2727

28-
public function setUp()
28+
protected function setUpCompat()
2929
{
3030
$this->connection = new AMQPStreamConnection(HOST, PORT, USER, PASS, VHOST);
3131
$this->channel = $this->connection->channel();
@@ -38,7 +38,7 @@ public function setUp()
3838
$this->channel->queue_bind($this->queueName2, $this->exchangeName, $this->queueName2);
3939
}
4040

41-
public function tearDown()
41+
protected function tearDownCompat()
4242
{
4343
if ($this->channel) {
4444
$this->channel->exchange_delete($this->exchangeName);

0 commit comments

Comments
 (0)