Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c0d6f04

Browse files
Minor improvements to some session tests.
1 parent f350dc3 commit c0d6f04

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

tests/RedisTest.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7462,7 +7462,7 @@ public function testSession_lock_ttlMaxExecutionTime()
74627462
$end = microtime(true);
74637463
$elapsedTime = $end - $start;
74647464

7465-
$this->assertTrue($elapsedTime < 3);
7465+
$this->assertLess($elapsedTime, 3);
74667466
$this->assertTrue($sessionSuccessful);
74677467
}
74687468

@@ -7543,7 +7543,7 @@ public function testSession_defaultLockRetryCount()
75437543
$end = microtime(true);
75447544
$elapsedTime = $end - $start;
75457545

7546-
$this->assertTrue($elapsedTime > 2 && $elapsedTime < 3);
7546+
$this->assertBetween($elapsedTime, 2, 3);
75477547
$this->assertFalse($sessionSuccessful);
75487548
}
75497549

@@ -7931,7 +7931,14 @@ private function startSessionProcess($sessionId, $sleepTime, $background,
79317931

79327932
exec($command, $output);
79337933

7934-
return ($background || (count($output) == 1 && $output[0] == 'SUCCESS'));
7934+
if ($background)
7935+
return true;
7936+
7937+
$result = $output[0] == 'SUCCESS';
7938+
7939+
// var_dump(['command' => $command, 'output' => $output, 'result' => $result]);
7940+
7941+
return $result;
79357942
}
79367943

79377944
/**
@@ -8006,11 +8013,12 @@ private function getPhpCommand($script)
80068013
if (!$cmd) {
80078014
$cmd = (getenv('TEST_PHP_EXECUTABLE') ?: PHP_BINARY);
80088015

8009-
if ($test_args = getenv('TEST_PHP_ARGS')) {
8010-
$cmd .= ' ';
8011-
$cmd .= $test_args;
8016+
$test_args = getenv('TEST_PHP_ARGS');
8017+
if ($test_args !== false) {
8018+
$cmd .= ' ' . $test_args;
80128019
} else {
8013-
/* Only append specific extension directives if PHP hasn't been compiled with what we need statically */
8020+
/* Only append specific extension directives if PHP hasn't been compiled
8021+
* with what we need statically */
80148022
$modules = shell_exec("$cmd --no-php-ini -m");
80158023

80168024
/* Determine if we need to specifically add extensions */

tests/TestSuite.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,21 @@ protected function assertLess($a, $b) {
181181
$bt[0]["file"], $bt[0]["line"], $bt[1]["function"]);
182182
}
183183

184+
protected function assertBetween($value, $min, $max, bool $exclusive = false) {
185+
if ($exclusive) {
186+
if ($value > $min && $value < $max)
187+
return;
188+
} else {
189+
if ($value >= $min && $value <= $max)
190+
return;
191+
}
192+
193+
$bt = debug_backtrace(false);
194+
self::$errors []= sprintf("Assertion failed (%s not between %s and %s): %s:%d (%s)\n",
195+
print_r($value, true), print_r($min, true), print_r($max, true),
196+
$bt[0]["file"], $bt[0]["line"], $bt[1]["function"]);
197+
}
198+
184199
protected function assertEquals($a, $b) {
185200
if($a === $b)
186201
return;

0 commit comments

Comments
 (0)