Skip to content

Commit

Permalink
Merge pull request #96 from ably/php8
Browse files Browse the repository at this point in the history
Support PHP 8.0; Drop 5.6, 7.0 & 7.1
  • Loading branch information
owenpearson authored Mar 9, 2021
2 parents 4b43f11 + e5b5881 commit dc73009
Show file tree
Hide file tree
Showing 22 changed files with 142 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [5.6, 7.0, 7.1, 7.2, 7.3, 7.4]
php-version: [7.2, 7.3, 7.4, 8.0]

steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
.DS_Store
tmp/
config.php
vendor/
composer.lock
/composer.lock
/.phpunit.result.cache
/vendor/

.*.swp
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A PHP REST client library for [www.ably.io](https://www.ably.io), the realtime m

## Supported Platforms

This SDK supports PHP 5.6 and 7.0+
This SDK supports PHP 7.2+ and 8.0

We regression-test the library against a selection of PHP versions (which will change over time, but usually consists of the versions that are supported upstream). Please refer to [the check workflow](.github/workflows/check.yml) for the set of versions that currently undergo CI testing.

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"keywords": ["messaging", "messages", "ably"],
"homepage": "https://www.ably.io/",
"require": {
"php": "^5.6 || ^7.0",
"php": "^7.2 || ^8.0",
"ext-json" : "*",
"ext-curl" : "*",
"ext-openssl" : "*"
},
"require-dev": {
"phpunit/phpunit": "^4.8 || ^5.7"
"phpunit/phpunit": "^8.5 || ^9.5"
},
"license": "Apache-2.0",
"authors": [
Expand Down
31 changes: 16 additions & 15 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<phpunit>
<testsuites>
<testsuite name="ably">
<directory>tests</directory>
</testsuite>
</testsuites>
<listeners>
<listener file="tests/extensions/DebugTestListener.php" class="DebugTestListener" />
</listeners>
<filter>
<blacklist>
<directory suffix=".php">tests</directory>
</blacklist>
</filter>
</phpunit>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="ably">
<directory>tests</directory>
</testsuite>
</testsuites>
<listeners>
<listener file="tests/extensions/DebugTestListener.php" class="DebugTestListener"/>
</listeners>
</phpunit>
18 changes: 13 additions & 5 deletions tests/AblyRestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

require_once __DIR__ . '/factories/TestApp.php';

class AblyRestTest extends \PHPUnit_Framework_TestCase {
class AblyRestTest extends \PHPUnit\Framework\TestCase {

protected static $testApp;
protected static $defaultOptions;

public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
self::$testApp = new \tests\TestApp();
self::$defaultOptions = self::$testApp->getOptions();
}

public static function tearDownAfterClass() {
public static function tearDownAfterClass(): void {
self::$testApp->release();
}

Expand Down Expand Up @@ -97,7 +97,11 @@ public function testInitLibWithSpecifiedPort() {
];
$ably = new AblyRest( $opts );
$ably->time(); // make a request
$this->assertContains( 'https://' . $opts['restHost'] . ':' . $opts['tlsPort'], $ably->http->lastUrl, 'Unexpected host/port mismatch' );
$this->assertStringContainsString(
'https://' . $opts['restHost'] . ':' . $opts['tlsPort'],
$ably->http->lastUrl,
'Unexpected host/port mismatch'
);

$opts = [
'token' => 'fakeToken',
Expand All @@ -108,7 +112,11 @@ public function testInitLibWithSpecifiedPort() {
];
$ably = new AblyRest( $opts );
$ably->time(); // make a request
$this->assertContains( 'http://' . $opts['restHost'] . ':' . $opts['port'], $ably->http->lastUrl, 'Unexpected host/port mismatch' );
$this->assertStringContainsString(
'http://' . $opts['restHost'] . ':' . $opts['port'],
$ably->http->lastUrl,
'Unexpected host/port mismatch'
);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/AppStatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require_once __DIR__ . '/factories/TestApp.php';

class AppStatsTest extends \PHPUnit_Framework_TestCase {
class AppStatsTest extends \PHPUnit\Framework\TestCase {

protected static $testApp;
protected static $defaultOptions;
Expand All @@ -14,7 +14,7 @@ class AppStatsTest extends \PHPUnit_Framework_TestCase {
protected static $timestampMs;
protected static $timestampOlderMs;

public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
self::$testApp = new TestApp();
self::$defaultOptions = self::$testApp->getOptions();
self::$ably = new AblyRest( array_merge( self::$defaultOptions, [
Expand Down Expand Up @@ -61,7 +61,7 @@ public static function setUpBeforeClass() {
self::$ably->post( '/stats', [], $fixtureJSON );
}

public static function tearDownAfterClass() {
public static function tearDownAfterClass(): void {
self::$testApp->release();
}

Expand Down
6 changes: 3 additions & 3 deletions tests/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@

require_once __DIR__ . '/factories/TestApp.php';

class AuthTest extends \PHPUnit_Framework_TestCase {
class AuthTest extends \PHPUnit\Framework\TestCase {

protected static $testApp;
protected static $defaultOptions;

public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
self::$testApp = new \tests\TestApp();
self::$defaultOptions = self::$testApp->getOptions();
}

public static function tearDownAfterClass() {
public static function tearDownAfterClass(): void {
self::$testApp->release();
}

Expand Down
6 changes: 3 additions & 3 deletions tests/ChannelHistoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@

require_once __DIR__ . '/factories/TestApp.php';

class ChannelHistoryTest extends \PHPUnit_Framework_TestCase {
class ChannelHistoryTest extends \PHPUnit\Framework\TestCase {

protected static $testApp;
protected static $defaultOptions;
protected static $ably;

public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
self::$testApp = new TestApp();
self::$defaultOptions = self::$testApp->getOptions();
self::$ably = new AblyRest( array_merge( self::$defaultOptions, [
'key' => self::$testApp->getAppKeyDefault()->string,
] ) );
}

public static function tearDownAfterClass() {
public static function tearDownAfterClass(): void {
self::$testApp->release();
}

Expand Down
10 changes: 5 additions & 5 deletions tests/ChannelIdempotentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public function request( $method, $url, $headers = [], $params = [] ) {
}


class ChannelIdempotentTest extends \PHPUnit_Framework_TestCase {
class ChannelIdempotentTest extends \PHPUnit\Framework\TestCase {
protected static $testApp;
protected static $defaultOptions;
protected static $ably;

public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
self::$testApp = new TestApp();
self::$defaultOptions = self::$testApp->getOptions();
self::$ably = new AblyRest( array_merge( self::$defaultOptions, [
Expand All @@ -36,7 +36,7 @@ public static function setUpBeforeClass() {
] ) );
}

public static function tearDownAfterClass() {
public static function tearDownAfterClass(): void {
self::$testApp->release();
}

Expand Down Expand Up @@ -76,12 +76,12 @@ public function testIdempotentLibraryGenerated() {

$id = explode ( ":", $body->id);
$this->assertEquals( count($id), 2);
$this->assertGreaterThanOrEqual( base64_decode($id[0]), 9);
$this->assertGreaterThanOrEqual( 9, strlen(base64_decode($id[0])) );
$this->assertEquals( $id[1], "0");

$channel->publish($msg);
$messages = $channel->history();
$this->assertEquals(count($messages->items), 1);
$this->assertEquals(1, count($messages->items));
$this->assertEquals($messages->items[0]->id, $msg->id);
}

Expand Down
64 changes: 27 additions & 37 deletions tests/ChannelMessagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@

require_once __DIR__ . '/factories/TestApp.php';

class ChannelMessagesTest extends \PHPUnit_Framework_TestCase {
class ChannelMessagesTest extends \PHPUnit\Framework\TestCase {
protected static $testApp;
protected static $defaultOptions;
protected static $ably;

public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
self::$testApp = new TestApp();
self::$defaultOptions = self::$testApp->getOptions();
self::$ably = new AblyRest( array_merge( self::$defaultOptions, [
'key' => self::$testApp->getAppKeyDefault()->string,
] ) );
}

public static function tearDownAfterClass() {
public static function tearDownAfterClass(): void {
self::$testApp->release();
}

Expand Down Expand Up @@ -204,62 +204,52 @@ public function testMessageArraySingleRequest() {
/**
* Verify that publishing invalid types fails
*/
public function testInvalidTypes() {
public function testInvalidTypesInt() {
$channel = self::$ably->channel( 'invalidTypes' );

$msg = new Message();
$msg->name = 'int';
$msg->data = 81403;
$this->expectException(AblyException::class);
$this->expectExceptionCode(40003);
$channel->publish( $msg );
}

try {
$channel->publish( $msg );
$this->fail( 'Expected an exception' );
} catch (AblyException $e) {
if ( $e->getCode() != 40003 ) $this->fail('Expected exception error code 40003');
}

public function testInvalidTypesBool() {
$channel = self::$ably->channel( 'invalidTypes' );
$msg = new Message();
$msg->name = 'bool';
$msg->data = true;
$this->expectException(AblyException::class);
$this->expectExceptionCode(40003);
$channel->publish( $msg );
}

try {
$channel->publish( $msg );
$this->fail( 'Expected an exception' );
} catch (AblyException $e) {
if ( $e->getCode() != 40003 ) $this->fail('Expected exception error code 40003');
}

public function testInvalidTypesFloat() {
$channel = self::$ably->channel( 'invalidTypes' );
$msg = new Message();
$msg->name = 'float';
$msg->data = 42.23;
$this->expectException(AblyException::class);
$this->expectExceptionCode(40003);
$channel->publish( $msg );
}

try {
$channel->publish( $msg );
$this->fail( 'Expected an exception' );
} catch (AblyException $e) {
if ( $e->getCode() != 40003 ) $this->fail('Expected exception error code 40003');
}

public function testInvalidTypesFunction() {
$channel = self::$ably->channel( 'invalidTypes' );
$msg = new Message();
$msg->name = 'function';
$msg->data = function($param) {
return "mock function";
};

try {
$channel->publish( $msg );
$this->fail( 'Expected an exception' );
} catch (AblyException $e) {
if ( $e->getCode() != 40003 ) $this->fail('Expected exception error code 40003');
}
$msg->data = function($param) { return "mock function"; };
$this->expectException(AblyException::class);
$this->expectExceptionCode(40003);
$channel->publish( $msg );
}

/**
* Verify that publishing too large message (>128KB) fails
*/
public function testTooLargeMessage() {
$channel = self::$ably->channel( 'huge' );

$msg = new Message();
$msg->name = 'huge';
$msg->data = str_repeat("~", 128 * 1024); // 128 kilobytes + message JSON
Expand Down
6 changes: 3 additions & 3 deletions tests/ClientIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

require_once __DIR__ . '/factories/TestApp.php';

class ClientIdTest extends \PHPUnit_Framework_TestCase {
class ClientIdTest extends \PHPUnit\Framework\TestCase {

protected static $testApp;
protected static $defaultOptions;

public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
self::$testApp = new TestApp();
self::$defaultOptions = self::$testApp->getOptions();
}

public static function tearDownAfterClass() {
public static function tearDownAfterClass(): void {
self::$testApp->release();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/CryptoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

require_once __DIR__ . '/factories/TestApp.php';

class CryptoTest extends \PHPUnit_Framework_TestCase {
class CryptoTest extends \PHPUnit\Framework\TestCase {

public function testGenerateRandomKey() {
$keyDefault = Crypto::generateRandomKey();
$this->assertEquals( 256, strlen( $keyDefault ) * 8, 'Expected the default key length to be 256 bits' );
$this->assertInternalType( 'string', $keyDefault, 'Expected to return a binary string' );
$this->assertIsString( $keyDefault, 'Expected to return a binary string' );

$key128 = Crypto::generateRandomKey( 128 );
$this->assertEquals( 128, strlen( $key128 ) * 8, 'Expected to return a random key of specified length (128 bits)' );
Expand Down
Loading

0 comments on commit dc73009

Please sign in to comment.