Skip to content

Commit

Permalink
WIP: Add unit tests for PHP 5.5 (#95)
Browse files Browse the repository at this point in the history
* Add unit tests for PHP 5.5
  • Loading branch information
colinmollenhour authored Oct 5, 2017
1 parent 696f224 commit 049ccfb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1
Expand Down
2 changes: 1 addition & 1 deletion tests/CredisClusterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function testMasterSlave()
$this->waitForSlaveReplication();
$this->assertEquals('value',$this->cluster->client('slave')->get('key'));
$this->assertEquals('value',$this->cluster->get('key'));
$this->expectException('CredisException','read-only slaves should not be writeable');
$this->expectException('CredisException');
$this->assertFalse($this->cluster->client('slave')->set('key2','value'));
}
public function testMasterWithoutSlavesAndWriteOnlyFlag()
Expand Down
32 changes: 31 additions & 1 deletion tests/CredisTestCommon.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
// backward compatibility (https://stackoverflow.com/a/42828632/187780)
if (!class_exists('\PHPUnit\Framework\TestCase') && class_exists('\PHPUnit_Framework_TestCase')) {
//class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase');
class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase');
}

class CredisTestCommon extends \PHPUnit\Framework\TestCase
Expand Down Expand Up @@ -150,4 +150,34 @@ public static function tearDownAfterClass()
@copy('redis-sentinel.conf.bak','redis-sentinel.conf');
}
}

/**
* Polyfill for older PHPUnit
*/
public function createMock($class)
{
if (method_exists($this, 'getMock')) {
return $this->getMock($class);
} else {
return parent::createMock($class);
}
}

/**
* Polyfill for older PHPUnit
*/
public function expectException($class, $message = NULL, $code = NULL)
{
if (method_exists($this, 'setExpectedException')) {
$this->setExpectedException($class, $message, $code);
} else {
parent::expectException($class);
if ($message !== null) {
$this->expectExceptionMessage($message);
}
if ($code !== null) {
$this->expectExceptionCode($code);
}
}
}
}

0 comments on commit 049ccfb

Please sign in to comment.