8000 Refactor session tests (#2492) · phpredis/phpredis@b88e72b · GitHub
[go: up one dir, main page]

Skip to content

Commit b88e72b

Browse files
Refactor session tests (#2492)
* Refactor session tests * Update these external scripts to take formal arguments with `getopt` to make it more straightforward what each of the currently positional arguments are actually for. * Create small helper classes for invoking these external scripts. Instead of `startSessionProcess` that takes a dozen argument all but three of which have defaults, we can use a construct like this: ```php $runner = $this->sessionRunner() ->maxExecutionTime(300) ->lockingEnabled(true) ->lockWaitTime(-1) ->lockExpires(0) ->data($data) ->compression($name); // Invokes startSession.php with above args. $result = $runner->execFg(); // Invokes regenerateSessionId.php with above args $new_id = $runner->regenerateId(); // Invokes getSessionData.php for this session ID. $data = $runner->getData(); ``` * Add a bit of logic to TestSuite to dump more information about the source of an assertion to make it easier to track down problems when we assert outside of a top level public `test_*` method. * Create a few new assertions like `assertKeyExists` and `assertKeyMissing` which will generate much nicer assertions as opposed to ```php $this->assertTrue($this->redis->exists($some_key)); ``` * If our externally spawned session scripts fail output the exact call that was made along with all arguments as well as the output that we received to make it easier to narrow down. * snake_case -> camelCase
1 parent d68c30f commit b88e72b

7 files changed

+858
-584
lines changed

tests/RedisClusterTest.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ class Redis_Cluster_Test extends Redis_Test {
2222
];
2323

2424
protected static $_arr_node_map = [];
25-
/**
26-
* @var string
27-
*/
28-
protected $sessionPrefix = 'PHPREDIS_CLUSTER_SESSION:';
29-
30-
/**
31-
* @var string
32-
*/
33-
protected $sessionSaveHandler = 'rediscluster';
3425

3526
/* Tests we'll skip all together in the context of RedisCluster. The
3627
* RedisCluster class doesn't implement specialized (non-redis) commands
@@ -709,12 +700,14 @@ public function testAcl() {
709700
public function testSession()
710701
{
711702
@ini_set('session.save_handler', 'rediscluster');
712-
@ini_set('session.save_path', $this->getFullHostPath() . '&failover=error');
703+
@ini_set('session.save_path', $this->sessionSavePath() . '&failover=error');
704+
713705
if< 10614 /span> (!@session_start()) {
714706
return $this->markTestSkipped();
715707
}
716708
session_write_close();
717-
$this->assertTrue($this->redis->exists('PHPREDIS_CLUSTER_SESSION:' . session_id()));
709+
710+
$this->assertKeyExists($this->sessionPrefix() . session_id());
718711
}
719712

720713

@@ -748,16 +741,21 @@ public function testConnectionPool() {
748741
ini_set('redis.pconnect.pooling_enabled', $prev_value);
749742
}
750743

744+
protected function sessionPrefix(): string {
745+
return 'PHPREDIS_CLUSTER_SESSION:';
746+
}
747+
748+
protected function sessionSaveHandler(): string {
749+
return 'rediscluster';
750+
}
751+
751752
/**
752753
* @inheritdoc
753754
*/
754-
protected function getFullHostPath()
755-
{
756-
$auth = $this->getAuthFragment();
757-
755+
protected function sessionSavePath(): string {
758756
return implode('&', array_map(function ($host) {
759757
return 'seed[]=' . $host;
760-
}, self::$_arr_node_map)) . ($auth ? "&$auth" : '');
758+
}, self::$_arr_node_map)) . '&' . $this->getAuthFragment();
761759
}
762760

763761
/* Test correct handling of null multibulk replies */

0 commit comments

Comments
 (0)
0