Skip to content

Commit

Permalink
Fixes #140: Update test suites (#142)
Browse files Browse the repository at this point in the history
* Update Dockerfile

- Removed PHP 5.5 & Added PHP 7.4
- PHP Redis Extension 4.3.0 is the latest version to support PHP 5
- Update Redis to 6.0.8 and enable TLS support for PHP 7

* Update .travis.yml

- Update php-redis to 5.3.0
- Update redis-server to 6.0.8

* Fixes test failures

- Use [assertIsArray](sebastianbergmann/phpunit#3368) method since PHPUnit v7.5
- Fixes AUTH error message changed since Redis v6
- `getMock()` is deprecated since PHPUnit v5.4

* Update Client.php

- PHP Redis extension support TLS since [5.3.0](https://pecl.php.net/package/redis/5.3.0)
- Fixes AUTH may not cleanup last error
  • Loading branch information
akunzai authored Oct 12, 2020
1 parent 0a28686 commit e217dc3
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 61 deletions.
23 changes: 12 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,32 @@ matrix:
- PHPUNIT_VERSION=^5.7
- php: 7.0
env:
- PHPREDIS_VERSION=redis-5.0.0
- PHPUNIT_VERSION=^6.4
- PHPREDIS_VERSION=redis-5.3.0
- PHPUNIT_VERSION=^6.5
- php: 7.1
env:
- PHPREDIS_VERSION=redis-5.0.0
- PHPUNIT_VERSION=^6.4
- PHPREDIS_VERSION=redis-5.3.0
- PHPUNIT_VERSION=^7.5
- php: 7.2
env:
- PHPREDIS_VERSION=redis-5.0.0
- PHPREDIS_VERSION=redis-5.3.0
- PHPUNIT_VERSION=^7.5
- php: 7.3
env:
- PHPREDIS_VERSION=redis-5.0.0
- PHPREDIS_VERSION=redis-5.3.0
- PHPUNIT_VERSION=^7.5
- php: 7.4
env:
- PHPREDIS_VERSION=redis-5.0.0
- PHPREDIS_VERSION=redis-5.3.0
- PHPUNIT_VERSION=^7.5

install:
- yes '' | pecl install -f $PHPREDIS_VERSION
- wget http://download.redis.io/releases/redis-5.0.5.tar.gz
- tar -xzf redis-5.0.5.tar.gz
- make -s -C redis-5.0.5 -j4
- export PATH=$PATH:$PWD/redis-5.0.5/src/
- wget http://download.redis.io/releases/redis-6.0.8.tar.gz
- tar -xzf redis-6.0.8.tar.gz
- export BUILD_TLS=yes
- make -s -C redis-6.0.8 -j4
- export PATH=$PWD/redis-6.0.8/src/:$PATH
- |
if [ ! -z "$PHPUNIT_VERSION" ]; then
composer require "phpunit/phpunit:${PHPUNIT_VERSION}" --dev --no-update -n
Expand Down
8 changes: 6 additions & 2 deletions Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ public function __construct($host = '127.0.0.1', $port = 6379, $timeout = null,
$this->authPassword = $password;
$this->selectedDb = (int)$db;
$this->convertHost();
if ($this->scheme == 'tls') {
// PHP Redis extension doesn't work with TLS
// PHP Redis extension support TLS since 5.3.0
if ($this->scheme == 'tls' && !$this->standalone && version_compare(phpversion('redis'),'5.3.0','<')){
$this->standalone = true;
}
}
Expand Down Expand Up @@ -1231,6 +1231,10 @@ public function __call($name, $args)
}
}
break;
case 'auth':
if (is_bool($response) && $response === true){
$this->redis->clearLastError();
}
default:
$error = $this->redis->getLastError();
$this->redis->clearLastError();
Expand Down
10 changes: 5 additions & 5 deletions testenv/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
version: '2'
services:

php-55:
build: env/php-5.5/
volumes:
- ../:/src/

php-56:
build: env/php-5.6/
volumes:
Expand All @@ -30,3 +25,8 @@ services:
build: env/php-7.3/
volumes:
- ../:/src/

php-74:
build: env/php-7.4/
volumes:
- ../:/src/
2 changes: 1 addition & 1 deletion testenv/env/php-5.6/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN wget https://phar.phpunit.de/phpunit-${phpunit_verison}.phar && \
mv phpunit-${phpunit_verison}.phar /usr/local/bin/phpunit

# install php extension
RUN yes '' | pecl install -f redis && \
RUN yes '' | pecl install -f redis-4.3.0 && \
docker-php-ext-enable redis

# install redis server
Expand Down
7 changes: 4 additions & 3 deletions testenv/env/php-7.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM php:7.0
ENV phpunit_verison 6.4
ENV redis_version 4.0.11
ENV phpunit_verison 6.5
ENV redis_version 6.0.8

RUN apt-get update && \
apt-get install -y wget
apt-get install -y wget libssl-dev

RUN wget https://phar.phpunit.de/phpunit-${phpunit_verison}.phar && \
chmod +x phpunit-${phpunit_verison}.phar && \
Expand All @@ -16,6 +16,7 @@ RUN yes '' | pecl install -f redis && \
# install redis server
RUN wget http://download.redis.io/releases/redis-${redis_version}.tar.gz && \
tar -xzf redis-${redis_version}.tar.gz && \
export BUILD_TLS=yes && \
make -s -C redis-${redis_version} -j

CMD PATH=$PATH:/usr/local/bin/:/redis-${redis_version}/src/ && \
Expand Down
7 changes: 4 additions & 3 deletions testenv/env/php-7.1/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM php:7.1
ENV phpunit_verison 6.4
ENV redis_version 4.0.11
ENV phpunit_verison 7.5
ENV redis_version 6.0.8

RUN apt-get update && \
apt-get install -y wget
apt-get install -y wget libssl-dev

RUN wget https://phar.phpunit.de/phpunit-${phpunit_verison}.phar && \
chmod +x phpunit-${phpunit_verison}.phar && \
Expand All @@ -16,6 +16,7 @@ RUN yes '' | pecl install -f redis && \
# install redis server
RUN wget http://download.redis.io/releases/redis-${redis_version}.tar.gz && \
tar -xzf redis-${redis_version}.tar.gz && \
export BUILD_TLS=yes && \
make -s -C redis-${redis_version} -j

CMD PATH=$PATH:/usr/local/bin/:/redis-${redis_version}/src/ && \
Expand Down
5 changes: 3 additions & 2 deletions testenv/env/php-7.2/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM php:7.2
ENV phpunit_verison 7.5
ENV redis_version 4.0.11
ENV redis_version 6.0.8

RUN apt-get update && \
apt-get install -y wget
apt-get install -y wget libssl-dev

RUN wget https://phar.phpunit.de/phpunit-${phpunit_verison}.phar && \
chmod +x phpunit-${phpunit_verison}.phar && \
Expand All @@ -16,6 +16,7 @@ RUN yes '' | pecl install -f redis && \
# install redis server
RUN wget http://download.redis.io/releases/redis-${redis_version}.tar.gz && \
tar -xzf redis-${redis_version}.tar.gz && \
export BUILD_TLS=yes && \
make -s -C redis-${redis_version} -j

CMD PATH=$PATH:/usr/local/bin/:/redis-${redis_version}/src/ && \
Expand Down
5 changes: 3 additions & 2 deletions testenv/env/php-7.3/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM php:7.3
ENV phpunit_verison 7.5
ENV redis_version 4.0.11
ENV redis_version 6.0.8

RUN apt-get update && \
apt-get install -y wget
apt-get install -y wget libssl-dev

RUN wget https://phar.phpunit.de/phpunit-${phpunit_verison}.phar && \
chmod +x phpunit-${phpunit_verison}.phar && \
Expand All @@ -16,6 +16,7 @@ RUN yes '' | pecl install -f redis && \
# install redis server
RUN wget http://download.redis.io/releases/redis-${redis_version}.tar.gz && \
tar -xzf redis-${redis_version}.tar.gz && \
export BUILD_TLS=yes && \
make -s -C redis-${redis_version} -j

CMD PATH=$PATH:/usr/local/bin/:/redis-${redis_version}/src/ && \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM php:5.5
ENV phpunit_verison 4.8
ENV redis_version 4.0.11
FROM php:7.4
ENV phpunit_verison 7.5
ENV redis_version 6.0.8

RUN apt-get update && \
apt-get install -y wget
apt-get install -y wget libssl-dev

RUN wget https://phar.phpunit.de/phpunit-${phpunit_verison}.phar && \
chmod +x phpunit-${phpunit_verison}.phar && \
Expand All @@ -16,6 +16,7 @@ RUN yes '' | pecl install -f redis && \
# install redis server
RUN wget http://download.redis.io/releases/redis-${redis_version}.tar.gz && \
tar -xzf redis-${redis_version}.tar.gz && \
export BUILD_TLS=yes && \
make -s -C redis-${redis_version} -j

CMD PATH=$PATH:/usr/local/bin/:/redis-${redis_version}/src/ && \
Expand Down
6 changes: 5 additions & 1 deletion tests/CredisClusterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ public function testMasterWithoutSlavesAndWriteOnlyFlag()
}
public function testDontHashForCodeCoverage()
{
$this->assertInternalType('array',$this->cluster->info());
if (method_exists($this,'assertIsArray')){
$this->assertIsArray($this->cluster->info());
} else {
$this->assertInternalType('array',$this->cluster->info());
}
}
public function testByHash()
{
Expand Down
38 changes: 31 additions & 7 deletions tests/CredisSentinelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public function testMasterClient()
public function testMasters()
{
$masters = $this->sentinel->masters();
$this->assertInternalType('array',$masters);
if (method_exists($this,'assertIsArray')){
$this->assertIsArray($masters);
} else {
$this->assertInternalType('array',$masters);
}
$this->assertCount(2,$masters);
$this->assertArrayHasKey(0,$masters);
$this->assertArrayHasKey(1,$masters);
Expand All @@ -95,7 +99,11 @@ public function testMasters()
public function testMaster()
{
$master = $this->sentinel->master($this->sentinelConfig->clustername);
$this->assertInternalType('array',$master);
if (method_exists($this,'assertIsArray')){
$this->assertIsArray($master);
} else {
$this->assertInternalType('array',$master);
}
$this->assertArrayHasKey(1,$master);
$this->assertArrayHasKey(5,$master);
$this->assertEquals($this->sentinelConfig->clustername,$master[1]);
Expand All @@ -107,7 +115,11 @@ public function testMaster()
public function testSlaveClient()
{
$slaves = $this->sentinel->getSlaveClients($this->sentinelConfig->clustername);
$this->assertInternalType('array',$slaves);
if (method_exists($this,'assertIsArray')){
$this->assertIsArray($slaves);
} else {
$this->assertInternalType('array',$slaves);
}
$this->assertCount(1,$slaves);
foreach($slaves as $slave){
$this->assertInstanceOf('Credis_Client',$slave);
Expand All @@ -118,14 +130,22 @@ public function testSlaveClient()
public function testSlaves()
{
$slaves = $this->sentinel->slaves($this->sentinelConfig->clustername);
$this->assertInternalType('array',$slaves);
if (method_exists($this,'assertIsArray')){
$this->assertIsArray($slaves);
} else {
$this->assertInternalType('array',$slaves);
}
$this->assertCount(1,$slaves);
$this->assertArrayHasKey(0,$slaves);
$this->assertArrayHasKey(5,$slaves[0]);
$this->assertEquals(6385,$slaves[0][5]);

$slaves = $this->sentinel->slaves('masterdown');
$this->assertInternalType('array',$slaves);
if (method_exists($this,'assertIsArray')){
$this->assertIsArray($slaves);
} else {
$this->assertInternalType('array',$slaves);
}
$this->assertCount(0,$slaves);

$this->setExpectedExceptionShim('CredisException','No such master with that name');
Expand Down Expand Up @@ -165,7 +185,11 @@ public function testGetClusterOnDbNumber2()
public function testGetMasterAddressByName()
{
$address = $this->sentinel->getMasterAddressByName($this->sentinelConfig->clustername);
$this->assertInternalType('array',$address);
if (method_exists($this,'assertIsArray')){
$this->assertIsArray($address);
} else {
$this->assertInternalType('array',$address);
}
$this->assertCount(2,$address);
$this->assertArrayHasKey(0,$address);
$this->assertArrayHasKey(1,$address);
Expand All @@ -184,7 +208,7 @@ public function testGetHostAndPort()
$host = 'localhost';
$port = '123456';

$client = $this->createMockShim('\Credis_Client');
$client = $this->createMock('\Credis_Client');
$sentinel = new Credis_Sentinel($client);

$client->expects($this->once())->method('getHost')->willReturn($host);
Expand Down
5 changes: 2 additions & 3 deletions tests/CredisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ public function testPassword()
}
catch(CredisException $e)
{
$this->assertStringStartsWith('ERR invalid password', $e->getMessage());
$this->assertStringStartsWith('WRONGPASS invalid username-password pair', $e->getMessage());
$this->credis->close();
}
$this->credis = new Credis_Client($this->redisConfig[4]['host'], $this->redisConfig[4]['port'], $this->redisConfig[4]['timeout'], false, 0);
Expand All @@ -592,15 +592,14 @@ public function testPassword()
catch(CredisException $e)
{
$this->assertStringStartsWith('NOAUTH Authentication required', $e->getMessage());

}
try
{
$this->credis->auth('anotherwrongpassword');
}
catch(CredisException $e)
{
$this->assertStringStartsWith('ERR invalid password', $e->getMessage());
$this->assertStringStartsWith('WRONGPASS invalid username-password pair', $e->getMessage());
}
$this->assertTrue($this->credis->auth('thepassword'));
$this->assertTrue($this->credis->set('key','value'));
Expand Down
17 changes: 0 additions & 17 deletions tests/CredisTestCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,6 @@ public static function tearDownAfterClass()
}
}


//
/**
* php 7.2 compat fix, as directly polyfilling for older PHPUnit causes a function signature compatibility issue
* This is due to the defined return type
*
* Polyfill for older PHPUnit
*/
protected function createMockShim($originalClassName)
{
if (method_exists($this, 'getMock')) {
return $this->getMock($originalClassName);
} else {
return parent::createMock($originalClassName);
}
}

/**
* php 7.2 compat fix, as directly polyfilling for older PHPUnit causes a function signature compatibility issue
* This is due to the defined return type
Expand Down

0 comments on commit e217dc3

Please sign in to comment.