[tests] Fix the very few remaining warnings emitted by test suite.

Basically assertMatchesRegularExpression() replaces assertRegExp() which
has been deprecated since PHPUnit 9.1 and will be removed in PHPUnit 10,
unfortunately we still depend on PHPUnit 8.4 to support PHP 7.2 and this
version does not have assertMatchesRegularExpression() so we implemented
it in our base testcase class with a fallback to the old assertRegExp()
when tests are executed on older versions of PHPUnit.
This commit is contained in:
Daniele Alessandri
2020-09-04 20:45:36 +02:00
parent e5f44c33a2
commit b1ea4374d4
4 changed files with 20 additions and 3 deletions
+3 -1
View File
@@ -442,7 +442,9 @@ abstract class PredisConnectionTestCase extends PredisTestCase
$connection->writeRequest($commands->create('rpush', array('foo', 'baz')));
$this->assertInstanceOf('Predis\Response\Error', $error = $connection->read());
$this->assertRegExp('/[ERR|WRONGTYPE] Operation against a key holding the wrong kind of value/', $error->getMessage());
$this->assertMatchesRegularExpression(
'/[ERR|WRONGTYPE] Operation against a key holding the wrong kind of value/', $error->getMessage()
);
}
/**
+15
View File
@@ -93,6 +93,21 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase
$this->assertThat($actual, new ArrayHasSameValuesConstraint($expected), $message);
}
/**
* Asserts that a string matches a given regular expression.
*
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public static function assertMatchesRegularExpression(string $pattern, string $string, $message = ''): void
{
if (is_callable('parent::' . __FUNCTION__)) {
call_user_func('parent::' . __FUNCTION__, $pattern, $string, $message);
} else {
static::assertRegExp($pattern, $string, $message);
}
}
/**
* Returns a named array with default values for connection parameters.
*
+1 -1
View File
@@ -66,7 +66,7 @@ class MONITOR_Test extends PredisCommandTestCase
// NOTE: Starting with 2.6 Redis does not return the "MONITOR" message after
// +OK to the client that issued the MONITOR command.
if ($this->isRedisServerVersion('<=', '2.4.0')) {
$this->assertRegExp('/\d+.\d+(\s?\(db \d+\))? "MONITOR"/', $connection->read());
$this->assertMatchesRegularExpression('/\d+.\d+(\s?\(db \d+\))? "MONITOR"/', $connection->read());
}
}
}
+1 -1
View File
@@ -88,7 +88,7 @@ class OBJECT_Test extends PredisCommandTestCase
$redis = $this->getClient();
$redis->lpush('list:metavars', 'foo', 'bar');
$this->assertRegExp('/[zip|quick]list/', $redis->object('ENCODING', 'list:metavars'));
$this->assertMatchesRegularExpression('/[zip|quick]list/', $redis->object('ENCODING', 'list:metavars'));
}
/**