Skip to content

Commit

Permalink
Merge pull request #102 from edudobay/php8
Browse files Browse the repository at this point in the history
Support PHP 8
  • Loading branch information
WyriHaximus authored Dec 10, 2020
2 parents 88836df + 9f4593a commit 9d6be4a
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/composer.phar
/composer.lock
/vendor
.phpunit.result.cache
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
dist: trusty
dist: bionic

os: linux

language: php

php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0
- nightly

cache:
Expand Down Expand Up @@ -41,3 +41,8 @@ script:

services:
- rabbitmq

addons:
apt:
packages:
- rabbitmq-server
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
## Requirements

BunnyPHP requires PHP 7.0 and newer.
BunnyPHP requires PHP 7.1 and newer.

## Installation

Expand Down Expand Up @@ -231,6 +231,8 @@ in.
```
$ docker-compose up -d
```

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`.

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

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
}
],
"require": {
"php": "~7.0",
"php": "^7.1 || ^8.0",
"psr/log": "~1.0",
"react/event-loop": "^1.0 || ^0.5 || ^0.4",
"react/promise": "~2.2"
},
"require-dev": {
"phpunit/phpunit": "~6.5"
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.3"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ networks:
services:
rabbit_node_1:
image: 'rabbitmq:3-management'
entrypoint: /opt/bunny/docker/rabbitmq/entrypoint.sh /usr/local/bin/docker-entrypoint.sh
command: rabbitmq-server
environment:
RABBITMQ_DEFAULT_USER: testuser
RABBITMQ_DEFAULT_PASS: testpassword
RABBITMQ_DEFAULT_VHOST: testvhost
RABBITMQ_ERLANG_COOKIE: bunny-test-secret
CONFIG_NAME: "${CONFIG_NAME:-rabbitmq.ssl.verify_peer}"
volumes:
- .:/opt/bunny
networks:
- main
hostname: rabbit_node_1
Expand All @@ -18,6 +23,13 @@ services:
tty: true
bunny:
build: docker/bunny
init: true
environment:
SSL_TEST: 'yes'
SSL_CA: ssl/ca.pem
SSL_PEER_NAME: server.rmq
SSL_CLIENT_CERT: ssl/client.pem
SSL_CLIENT_KEY: ssl/client.key
volumes:
- .:/opt/bunny
networks:
Expand Down
26 changes: 26 additions & 0 deletions docker/rabbitmq/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -eu

is_rabbitmq_gte_3_7_0() {
[[ "3.7.0" = $(echo -e "3.7.0\n$RABBITMQ_VERSION" | sort -V | head -n1) ]]
}

TEST_DATA_ROOT=/opt/bunny/test/ssl
CONFIG_NAME=${CONFIG_NAME:-}

cp ${TEST_DATA_ROOT}/{ca.pem,server.pem,server.key} /etc/rabbitmq/
chown rabbitmq /etc/rabbitmq/{ca.pem,server.pem,server.key}
chmod 0400 /etc/rabbitmq/{ca.pem,server.pem,server.key}

if [[ -n "$CONFIG_NAME" ]]; then
if is_rabbitmq_gte_3_7_0; then
cp ${TEST_DATA_ROOT}/${CONFIG_NAME}.conf /etc/rabbitmq/rabbitmq.conf
chown rabbitmq /etc/rabbitmq/rabbitmq.conf
else
cp ${TEST_DATA_ROOT}/${CONFIG_NAME}.config /etc/rabbitmq/rabbitmq.config
chown rabbitmq /etc/rabbitmq/rabbitmq.config
fi
fi

exec "$@"
17 changes: 7 additions & 10 deletions src/Bunny/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,13 @@ protected function getStream()
$uri .= (strpos($this->options["path"], "/") === 0) ? $this->options["path"] : "/" . $this->options["path"];
}

// tcp_nodelay was added in 7.1.0
if (PHP_VERSION_ID >= 70100) {
stream_context_set_option(
$context, [
"socket" => [
"tcp_nodelay" => true
]
]);
}

stream_context_set_option(
$context, [
"socket" => [
"tcp_nodelay" => true
]
]);

$this->stream = @stream_socket_client($uri, $errno, $errstr, (float)$this->options["timeout"], $flags, $context);

if (!$this->stream) {
Expand Down
4 changes: 2 additions & 2 deletions src/Bunny/ChannelMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function queueDeclare($queue = '', $passive = false, $durable = false, $e
*
* @return boolean|Promise\PromiseInterface|Protocol\MethodQueueBindOkFrame
*/
public function queueBind($queue = '', $exchange, $routingKey = '', $nowait = false, $arguments = [])
public function queueBind($queue, $exchange, $routingKey = '', $nowait = false, $arguments = [])
{
return $this->getClient()->queueBind($this->getChannelId(), $queue, $exchange, $routingKey, $nowait, $arguments);
}
Expand Down Expand Up @@ -165,7 +165,7 @@ public function queueDelete($queue = '', $ifUnused = false, $ifEmpty = false, $n
*
* @return boolean|Promise\PromiseInterface|Protocol\MethodQueueUnbindOkFrame
*/
public function queueUnbind($queue = '', $exchange, $routingKey = '', $arguments = [])
public function queueUnbind($queue, $exchange, $routingKey = '', $arguments = [])
{
return $this->getClient()->queueUnbind($this->getChannelId(), $queue, $exchange, $routingKey, $arguments);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Bunny/ClientMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function awaitConnectionStart()
throw new \LogicException('This statement should be never reached.');
}

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

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

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

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

public function queueUnbind($channel, $queue = '', $exchange, $routingKey = '', $arguments = [])
public function queueUnbind($channel, $queue, $exchange, $routingKey = '', $arguments = [])
{
$buffer = new Buffer();
$buffer->appendUint16(50);
Expand Down
7 changes: 1 addition & 6 deletions src/Bunny/Protocol/Buffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ public function __construct($buffer = "")
self::isLittleEndian();

if (self::$native64BitPack === null) {
if (!defined("PHP_VERSION_ID")) {
$version = explode(".", PHP_VERSION);
define("PHP_VERSION_ID", ($version[0] * 10000 + $version[1] * 100 + $version[2]));
}

self::$native64BitPack = PHP_VERSION_ID >= 50603 && PHP_INT_SIZE === 8;
self::$native64BitPack = PHP_INT_SIZE === 8;
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/Bunny/AsyncClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AsyncClientTest extends TestCase
*/
private $helper;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion test/Bunny/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ChannelTest extends TestCase
*/
private $helper;

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion test/Bunny/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ClientTest extends TestCase
*/
private $helper;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
29 changes: 24 additions & 5 deletions test/Bunny/SSLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Bunny\Async\Client as AsyncClient;
use Bunny\Exception\ClientException;
use Bunny\Test\Exception\TimeoutException;
use Bunny\Test\Library\AsynchronousClientHelper;
use Bunny\Test\Library\SynchronousClientHelper;
use PHPUnit\Framework\TestCase;

use React\EventLoop\Factory;
Expand All @@ -17,12 +19,29 @@

class SSLTest extends TestCase
{
/**
* @var SynchronousClientHelper
*/
private $helper;

/**
* @var AsynchronousClientHelper
*/
private $asyncHelper;

protected function setUp(): void
{
parent::setUp();

$this->helper = new SynchronousClientHelper();
$this->asyncHelper = new AsynchronousClientHelper();
}

public function testConnect()
{
$options = $this->getOptions();

$client = new Client($options);
$client = $this->helper->createClient($options);
$client->connect();
$client->disconnect();

Expand All @@ -37,7 +56,7 @@ public function testConnectAsync() {
throw new TimeoutException();
});

$client = new AsyncClient($loop, $options);
$client = $this->asyncHelper->createClient($loop, $options);
$client->connect()->then(function (AsyncClient $client) {
return $client->disconnect();
})->then(function () use ($loop) {
Expand All @@ -61,7 +80,7 @@ public function testConnectWithMissingClientCert()

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

$client = new Client($options);
$client = $this->helper->createClient($options);
$client->connect();
$client->disconnect();
}
Expand All @@ -73,7 +92,7 @@ public function testConnectToTcpPort()

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

$client = new Client($options);
$client = $this->helper->createClient($options);
$client->connect();
$client->disconnect();
}
Expand All @@ -85,7 +104,7 @@ public function testConnectWithWrongPeerName()

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

$client = new Client($options);
$client = $this->helper->createClient($options);
$client->connect();
$client->disconnect();
}
Expand Down
2 changes: 1 addition & 1 deletion test/Library/AsynchronousClientHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class AsynchronousClientHelper extends AbstractClientHelper
*/
public function createClient(LoopInterface $loop, array $options = null): Client
{
$options = $options ?? $this->getDefaultOptions();
$options = array_merge($this->getDefaultOptions(), $options ?? []);

return new Client($loop, $options);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Library/SynchronousClientHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class SynchronousClientHelper extends AbstractClientHelper
*/
public function createClient(array $options = null): Client
{
$options = $options ?? $this->getDefaultOptions();
$options = array_merge($this->getDefaultOptions(), $options ?? []);

return new Client($options);
}
Expand Down
2 changes: 1 addition & 1 deletion test/ssl/rabbitmq.ssl.verify_none.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ ssl_options.cacertfile = /etc/rabbitmq/ca.pem
ssl_options.certfile = /etc/rabbitmq/server.pem
ssl_options.keyfile = /etc/rabbitmq/server.key
ssl_options.verify = verify_none
ssl_options.fail_if_no_peer_cert = falsee
ssl_options.fail_if_no_peer_cert = false
2 changes: 1 addition & 1 deletion test/ssl/rabbitmq.ssl.verify_peer.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ ssl_options.cacertfile = /etc/rabbitmq/ca.pem
ssl_options.certfile = /etc/rabbitmq/server.pem
ssl_options.keyfile = /etc/rabbitmq/server.key
ssl_options.verify = verify_peer
ssl_options.fail_if_no_peer_cert = true
ssl_options.fail_if_no_peer_cert = true
3 changes: 2 additions & 1 deletion test/ssl/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ else
sudo cp rabbitmq.ssl.verify_peer.conf /etc/rabbitmq/rabbitmq.conf
sudo cp rabbitmq.ssl.verify_peer.config /etc/rabbitmq/rabbitmq.config
fi
sudo service rabbitmq-server restart
sudo chown rabbitmq: /etc/rabbitmq/{ca.pem,server.pem,server.key,rabbitmq.conf,rabbitmq.config}
sudo service rabbitmq-server restart

0 comments on commit 9d6be4a

Please sign in to comment.