Skip to content

Commit c3d83d4

Browse files
Create a specific exception for 'test skipped'
I our test suite we were only checking if an exception was an instance of `RedisException` and marking the test 'SKIPPED' if not. This was masking a failure in the RedisCluster test for testMultiExec by showing it as skipped when it was actually throwing an exception (not being able to execute the MULTI across the cluster).
1 parent a107c9f commit c3d83d4

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

tests/RedisTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2876,7 +2876,7 @@ protected function sequence($mode) {
28762876
$ret = $this->redis->multi($mode)
28772877
->ttl('key')
28782878
->mget(['{key}1', '{key}2', '{key}3'])
2879-
->mset(['{key}3' => 'value3', 'key4' => 'value4'])
2879+
->mset(['{key}3' => 'value3', '{key}4' => 'value4'])
28802880
->set('key', 'value')
28812881
->expire('key', 5)
28822882
->ttl('key')

tests/TestSuite.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php defined('PHPREDIS_TESTRUN') or die("Use TestRedis.php to run tests!\n");
22

3+
/* A specific exception for when we skip a test */
4+
class TestSkippedException extends Exception {}
5+
36
// phpunit is such a pain to install, we're going with pure-PHP here.
47
class TestSuite {
58
/* Host the tests will use */
@@ -120,7 +123,7 @@ protected function markTestSkipped($msg='') {
120123
self::$warnings []= sprintf("Skipped test: %s:%d (%s) %s\n",
121124
$bt[0]["file"], $bt[0]["line"], $bt[1]["function"], $msg);
122125

123-
throw new Exception($msg);
126+
throw new TestSkippedException($msg);
124127
}
125128

126129
private static function getMaxTestLen($arr_methods, $str_limit) {
@@ -185,11 +188,12 @@ public static function run($className, $str_limit = NULL, $str_host = NULL) {
185188
}
186189
//echo ($count === count($className::$errors)) ? "." : "F";
187190
} catch (Exception $e) {
188-
if ($e instanceof RedisException) {
191+
/* We may have simply skipped the test */
192+
if ($e instanceof TestSkippedException) {
193+
$str_msg = self::make_warning('SKIPPED');
194+
} else {
189195
$className::$errors[] = "Uncaught exception '".$e->getMessage()."' ($name)\n";
190196
$str_msg = self::make_fail('FAILED');
191-
} else {
192-
$str_msg = self::make_warning('SKIPPED');
193197
}
194198
}
195199

0 commit comments

Comments
 (0)