Skip to content

Commit 9d6be4a

Browse files
authored
Merge pull request #102 from edudobay/php8
Support PHP 8
2 parents 88836df + 9f4593a commit 9d6be4a

19 files changed

+99
-41
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/composer.phar
44
/composer.lock
55
/vendor
6+
.phpunit.result.cache

Diff for: .travis.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
dist: trusty
1+
dist: bionic
22

33
os: linux
44

55
language: php
66

77
php:
8-
- 7.0
98
- 7.1
109
- 7.2
1110
- 7.3
1211
- 7.4
12+
- 8.0
1313
- nightly
1414

1515
cache:
@@ -41,3 +41,8 @@ script:
4141

4242
services:
4343
- rabbitmq
44+
45+
addons:
46+
apt:
47+
packages:
48+
- rabbitmq-server

Diff for: README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
## Requirements
1111

12-
BunnyPHP requires PHP 7.0 and newer.
12+
BunnyPHP requires PHP 7.1 and newer.
1313

1414
## Installation
1515

@@ -231,6 +231,8 @@ in.
231231
```
232232
$ docker-compose up -d
233233
```
234+
235+
To test against different SSL configurations (as in CI builds), you can set environment variable `CONFIG_NAME=rabbitmq.ssl.verify_none` before running `docker-compose up`.
234236

235237
- Optionally use `docker ps` to display the running containers.
236238

Diff for: composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
}
2626
],
2727
"require": {
28-
"php": "~7.0",
28+
"php": "^7.1 || ^8.0",
2929
"psr/log": "~1.0",
3030
"react/event-loop": "^1.0 || ^0.5 || ^0.4",
3131
"react/promise": "~2.2"
3232
},
3333
"require-dev": {
34-
"phpunit/phpunit": "~6.5"
34+
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.3"
3535
},
3636
"autoload": {
3737
"psr-4": {

Diff for: docker-compose.yml

+12
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ networks:
44
services:
55
rabbit_node_1:
66
image: 'rabbitmq:3-management'
7+
entrypoint: /opt/bunny/docker/rabbitmq/entrypoint.sh /usr/local/bin/docker-entrypoint.sh
8+
command: rabbitmq-server
79
environment:
810
RABBITMQ_DEFAULT_USER: testuser
911
RABBITMQ_DEFAULT_PASS: testpassword
1012
RABBITMQ_DEFAULT_VHOST: testvhost
1113
RABBITMQ_ERLANG_COOKIE: bunny-test-secret
14+
CONFIG_NAME: "${CONFIG_NAME:-rabbitmq.ssl.verify_peer}"
15+
volumes:
16+
- .:/opt/bunny
1217
networks:
1318
- main
1419
hostname: rabbit_node_1
@@ -18,6 +23,13 @@ services:
1823
tty: true
1924
bunny:
2025
build: docker/bunny
26+
init: true
27+
environment:
28+
SSL_TEST: 'yes'
29+
SSL_CA: ssl/ca.pem
30+
SSL_PEER_NAME: server.rmq
31+
SSL_CLIENT_CERT: ssl/client.pem
32+
SSL_CLIENT_KEY: ssl/client.key
2133
volumes:
2234
- .:/opt/bunny
2335
networks:

Diff for: docker/rabbitmq/entrypoint.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
is_rabbitmq_gte_3_7_0() {
6+
[[ "3.7.0" = $(echo -e "3.7.0\n$RABBITMQ_VERSION" | sort -V | head -n1) ]]
7+
}
8+
9+
TEST_DATA_ROOT=/opt/bunny/test/ssl
10+
CONFIG_NAME=${CONFIG_NAME:-}
11+
12+
cp ${TEST_DATA_ROOT}/{ca.pem,server.pem,server.key} /etc/rabbitmq/
13+
chown rabbitmq /etc/rabbitmq/{ca.pem,server.pem,server.key}
14+
chmod 0400 /etc/rabbitmq/{ca.pem,server.pem,server.key}
15+
16+
if [[ -n "$CONFIG_NAME" ]]; then
17+
if is_rabbitmq_gte_3_7_0; then
18+
cp ${TEST_DATA_ROOT}/${CONFIG_NAME}.conf /etc/rabbitmq/rabbitmq.conf
19+
chown rabbitmq /etc/rabbitmq/rabbitmq.conf
20+
else
21+
cp ${TEST_DATA_ROOT}/${CONFIG_NAME}.config /etc/rabbitmq/rabbitmq.config
22+
chown rabbitmq /etc/rabbitmq/rabbitmq.config
23+
fi
24+
fi
25+
26+
exec "$@"

Diff for: src/Bunny/AbstractClient.php

+7-10
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,13 @@ protected function getStream()
248248
$uri .= (strpos($this->options["path"], "/") === 0) ? $this->options["path"] : "/" . $this->options["path"];
249249
}
250250

251-
// tcp_nodelay was added in 7.1.0
252-
if (PHP_VERSION_ID >= 70100) {
253-
stream_context_set_option(
254-
$context, [
255-
"socket" => [
256-
"tcp_nodelay" => true
257-
]
258-
]);
259-
}
260-
251+
stream_context_set_option(
252+
$context, [
253+
"socket" => [
254+
"tcp_nodelay" => true
255+
]
256+
]);
257+
261258
$this->stream = @stream_socket_client($uri, $errno, $errstr, (float)$this->options["timeout"], $flags, $context);
262259

263260
if (!$this->stream) {

Diff for: src/Bunny/ChannelMethods.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function queueDeclare($queue = '', $passive = false, $durable = false, $e
122122
*
123123
* @return boolean|Promise\PromiseInterface|Protocol\MethodQueueBindOkFrame
124124
*/
125-
public function queueBind($queue = '', $exchange, $routingKey = '', $nowait = false, $arguments = [])
125+
public function queueBind($queue, $exchange, $routingKey = '', $nowait = false, $arguments = [])
126126
{
127127
return $this->getClient()->queueBind($this->getChannelId(), $queue, $exchange, $routingKey, $nowait, $arguments);
128128
}
@@ -165,7 +165,7 @@ public function queueDelete($queue = '', $ifUnused = false, $ifEmpty = false, $n
165165
*
166166
* @return boolean|Promise\PromiseInterface|Protocol\MethodQueueUnbindOkFrame
167167
*/
168-
public function queueUnbind($queue = '', $exchange, $routingKey = '', $arguments = [])
168+
public function queueUnbind($queue, $exchange, $routingKey = '', $arguments = [])
169169
{
170170
return $this->getClient()->queueUnbind($this->getChannelId(), $queue, $exchange, $routingKey, $arguments);
171171
}

Diff for: src/Bunny/ClientMethods.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function awaitConnectionStart()
208208
throw new \LogicException('This statement should be never reached.');
209209
}
210210

211-
public function connectionStartOk($clientProperties = [], $mechanism = 'PLAIN', $response, $locale = 'en_US')
211+
public function connectionStartOk($clientProperties, $mechanism, $response, $locale = 'en_US')
212212
{
213213
$buffer = new Buffer();
214214
$buffer->appendUint16(10);
@@ -383,7 +383,7 @@ public function awaitConnectionOpenOk()
383383
throw new \LogicException('This statement should be never reached.');
384384
}
385385

386-
public function connectionClose($replyCode, $replyText = '', $closeClassId, $closeMethodId)
386+
public function connectionClose($replyCode, $replyText, $closeClassId, $closeMethodId)
387387
{
388388
$buffer = $this->getWriteBuffer();
389389
$buffer->appendUint8(1);
@@ -749,7 +749,7 @@ public function awaitChannelFlowOk($channel)
749749
throw new \LogicException('This statement should be never reached.');
750750
}
751751

752-
public function channelClose($channel, $replyCode, $replyText = '', $closeClassId, $closeMethodId)
752+
public function channelClose($channel, $replyCode, $replyText, $closeClassId, $closeMethodId)
753753
{
754754
$buffer = $this->getWriteBuffer();
755755
$buffer->appendUint8(1);
@@ -1289,7 +1289,7 @@ public function awaitQueueDeclareOk($channel)
12891289
throw new \LogicException('This statement should be never reached.');
12901290
}
12911291

1292-
public function queueBind($channel, $queue = '', $exchange, $routingKey = '', $nowait = false, $arguments = [])
1292+
public function queueBind($channel, $queue, $exchange, $routingKey = '', $nowait = false, $arguments = [])
12931293
{
12941294
$buffer = new Buffer();
12951295
$buffer->appendUint16(50);
@@ -1497,7 +1497,7 @@ public function awaitQueueDeleteOk($channel)
14971497
throw new \LogicException('This statement should be never reached.');
14981498
}
14991499

1500-
public function queueUnbind($channel, $queue = '', $exchange, $routingKey = '', $arguments = [])
1500+
public function queueUnbind($channel, $queue, $exchange, $routingKey = '', $arguments = [])
15011501
{
15021502
$buffer = new Buffer();
15031503
$buffer->appendUint16(50);

Diff for: src/Bunny/Protocol/Buffer.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ public function __construct($buffer = "")
4343
self::isLittleEndian();
4444

4545
if (self::$native64BitPack === null) {
46-
if (!defined("PHP_VERSION_ID")) {
47-
$version = explode(".", PHP_VERSION);
48-
define("PHP_VERSION_ID", ($version[0] * 10000 + $version[1] * 100 + $version[2]));
49-
}
50-
51-
self::$native64BitPack = PHP_VERSION_ID >= 50603 && PHP_INT_SIZE === 8;
46+
self::$native64BitPack = PHP_INT_SIZE === 8;
5247
}
5348
}
5449

Diff for: test/Bunny/AsyncClientTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AsyncClientTest extends TestCase
2222
*/
2323
private $helper;
2424

25-
public function setUp()
25+
public function setUp(): void
2626
{
2727
parent::setUp();
2828

Diff for: test/Bunny/ChannelTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ChannelTest extends TestCase
1616
*/
1717
private $helper;
1818

19-
protected function setUp()
19+
protected function setUp(): void
2020
{
2121
parent::setUp();
2222

Diff for: test/Bunny/ClientTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ClientTest extends TestCase
2020
*/
2121
private $helper;
2222

23-
public function setUp()
23+
public function setUp(): void
2424
{
2525
parent::setUp();
2626

Diff for: test/Bunny/SSLTest.php

+24-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Bunny\Async\Client as AsyncClient;
66
use Bunny\Exception\ClientException;
77
use Bunny\Test\Exception\TimeoutException;
8+
use Bunny\Test\Library\AsynchronousClientHelper;
9+
use Bunny\Test\Library\SynchronousClientHelper;
810
use PHPUnit\Framework\TestCase;
911

1012
use React\EventLoop\Factory;
@@ -17,12 +19,29 @@
1719

1820
class SSLTest extends TestCase
1921
{
22+
/**
23+
* @var SynchronousClientHelper
24+
*/
25+
private $helper;
26+
27+
/**
28+
* @var AsynchronousClientHelper
29+
*/
30+
private $asyncHelper;
31+
32+
protected function setUp(): void
33+
{
34+
parent::setUp();
35+
36+
$this->helper = new SynchronousClientHelper();
37+
$this->asyncHelper = new AsynchronousClientHelper();
38+
}
2039

2140
public function testConnect()
2241
{
2342
$options = $this->getOptions();
2443

25-
$client = new Client($options);
44+
$client = $this->helper->createClient($options);
2645
$client->connect();
2746
$client->disconnect();
2847

@@ -37,7 +56,7 @@ public function testConnectAsync() {
3756
throw new TimeoutException();
3857
});
3958

40-
$client = new AsyncClient($loop, $options);
59+
$client = $this->asyncHelper->createClient($loop, $options);
4160
$client->connect()->then(function (AsyncClient $client) {
4261
return $client->disconnect();
4362
})->then(function () use ($loop) {
@@ -61,7 +80,7 @@ public function testConnectWithMissingClientCert()
6180

6281
$this->expectException(ClientException::class);
6382

64-
$client = new Client($options);
83+
$client = $this->helper->createClient($options);
6584
$client->connect();
6685
$client->disconnect();
6786
}
@@ -73,7 +92,7 @@ public function testConnectToTcpPort()
7392

7493
$this->expectException(ClientException::class);
7594

76-
$client = new Client($options);
95+
$client = $this->helper->createClient($options);
7796
$client->connect();
7897
$client->disconnect();
7998
}
@@ -85,7 +104,7 @@ public function testConnectWithWrongPeerName()
85104

86105
$this->expectException(ClientException::class);
87106

88-
$client = new Client($options);
107+
$client = $this->helper->createClient($options);
89108
$client->connect();
90109
$client->disconnect();
91110
}

Diff for: test/Library/AsynchronousClientHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class AsynchronousClientHelper extends AbstractClientHelper
1717
*/
1818
public function createClient(LoopInterface $loop, array $options = null): Client
1919
{
20-
$options = $options ?? $this->getDefaultOptions();
20+
$options = array_merge($this->getDefaultOptions(), $options ?? []);
2121

2222
return new Client($loop, $options);
2323
}

Diff for: test/Library/SynchronousClientHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class SynchronousClientHelper extends AbstractClientHelper
1616
*/
1717
public function createClient(array $options = null): Client
1818
{
19-
$options = $options ?? $this->getDefaultOptions();
19+
$options = array_merge($this->getDefaultOptions(), $options ?? []);
2020

2121
return new Client($options);
2222
}

Diff for: test/ssl/rabbitmq.ssl.verify_none.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ ssl_options.cacertfile = /etc/rabbitmq/ca.pem
77
ssl_options.certfile = /etc/rabbitmq/server.pem
88
ssl_options.keyfile = /etc/rabbitmq/server.key
99
ssl_options.verify = verify_none
10-
ssl_options.fail_if_no_peer_cert = falsee
10+
ssl_options.fail_if_no_peer_cert = false

Diff for: test/ssl/rabbitmq.ssl.verify_peer.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ ssl_options.cacertfile = /etc/rabbitmq/ca.pem
77
ssl_options.certfile = /etc/rabbitmq/server.pem
88
ssl_options.keyfile = /etc/rabbitmq/server.key
99
ssl_options.verify = verify_peer
10-
ssl_options.fail_if_no_peer_cert = true
10+
ssl_options.fail_if_no_peer_cert = true

Diff for: test/ssl/travis.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ else
1515
sudo cp rabbitmq.ssl.verify_peer.conf /etc/rabbitmq/rabbitmq.conf
1616
sudo cp rabbitmq.ssl.verify_peer.config /etc/rabbitmq/rabbitmq.config
1717
fi
18-
sudo service rabbitmq-server restart
18+
sudo chown rabbitmq: /etc/rabbitmq/{ca.pem,server.pem,server.key,rabbitmq.conf,rabbitmq.config}
19+
sudo service rabbitmq-server restart

0 commit comments

Comments
 (0)