33namespace Google \Cloud \Spanner \Tests \Unit \Session ;
44
55use DG \BypassFinals ;
6+ use Exception ;
7+ use Google \Auth \Cache \FileSystemCacheItemPool ;
68use Google \Cloud \Spanner \Session \SessionCache ;
79use Google \Cloud \Spanner \V1 \Client \SpannerClient ;
810use Prophecy \Argument ;
1214/**
1315 * Runs a process which is designed to wait while a session is acquired.
1416 */
15- if (count ($ argv ) !== 2 ) {
16- die ('Usage: lock_test_process.php DATABASE_NAME ' . PHP_EOL );
17+ if (count ($ argv ) !== 3 ) {
18+ die ('Usage: lock_test_process.php DATABASE_NAME CACHE_PATH ' . PHP_EOL );
1719}
1820
19- if (file_exists (__DIR__ . '/../../../vendor/autoload.php ' )) {
21+ $ spannerAutoload = __DIR__ . '/../../../vendor/autoload.php ' ;
22+ $ googleCloudAutoload = __DIR__ . '/../../../../vendor/autoload.php ' ;
23+
24+ if (file_exists ($ spannerAutoload ) && file_exists ($ googleCloudAutoload )) {
25+ throw new Exception ('Both autoloaders exist, please remove one ' );
26+ }
27+
28+ if (file_exists ($ spannerAutoload )) {
2029 // google/cloud-spanner autoload
21- require __DIR__ . ' /../../../vendor/autoload.php ' ;
22- } elseif (file_exists (__DIR__ . ' /../../../../vendor/autoload.php ' )) {
30+ require $ spannerAutoload ;
31+ } elseif (file_exists ($ googleCloudAutoload )) {
2332 // google/cloud autoload
24- require __DIR__ . '/../../../../vendor/autoload.php ' ;
33+ require $ googleCloudAutoload ;
34+ } else {
35+ throw new Exception ('no autoloader found ' );
2536}
2637
2738BypassFinals::enable ();
2839
29- $ acquireSession = new class ($ argv [1 ]) {
40+ [$ _cmd , $ databaseName , $ cachePath ] = $ argv ;
41+
42+ $ acquireSession = new class ($ databaseName , $ cachePath ) {
3043 use ProphecyTrait;
3144
32- public function __construct (private string $ databaseName )
33- {
45+ public function __construct (
46+ private string $ databaseName ,
47+ private string $ cachePath
48+ ) {
3449 }
3550
3651 public function run (): string
@@ -41,11 +56,10 @@ public function run(): string
4156 throw new \Exception ('createSession called in child process - this shouldn \'t happen ' );
4257 });
4358
44- $ parts = explode ('/ ' , $ this ->databaseName );
4559 $ sessionCache = new SessionCache (
4660 $ spannerClient ->reveal (),
4761 $ this ->databaseName ,
48- ['cacheItemPool ' => new FilesystemAdapter ( array_pop ( $ parts ) )]
62+ ['cacheItemPool ' => new FileSystemCacheItemPool ( $ this -> cachePath )]
4963 );
5064
5165 return $ sessionCache ->name ();
0 commit comments