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 ;
911use Prophecy \PhpUnit \ProphecyTrait ;
10- use Symfony \Component \Cache \Adapter \FilesystemAdapter ;
1112
1213/**
1314 * Runs a process which is designed to wait while a session is acquired.
1617 die ('Usage: lock_test_process.php DATABASE_NAME ' . PHP_EOL );
1718}
1819
19- if (file_exists (__DIR__ . '/../../../vendor/autoload.php ' )) {
20+ $ spannerAutoload = __DIR__ . '/../../../vendor/autoload.php ' ;
21+ $ googleCloudAutoload = __DIR__ . '/../../../../vendor/autoload.php ' ;
22+
23+ if (file_exists ($ spannerAutoload ) && file_exists ($ googleCloudAutoload )) {
24+ throw new Exception ('Both autoloaders exist, please remove one ' );
25+ }
26+
27+ if (file_exists ($ spannerAutoload )) {
2028 // google/cloud-spanner autoload
21- require __DIR__ . ' /../../../vendor/autoload.php ' ;
22- } elseif (file_exists (__DIR__ . ' /../../../../vendor/autoload.php ' )) {
29+ require $ spannerAutoload ;
30+ } elseif (file_exists ($ googleCloudAutoload )) {
2331 // google/cloud autoload
24- require __DIR__ . '/../../../../vendor/autoload.php ' ;
32+ require $ googleCloudAutoload ;
33+ } else {
34+ throw new Exception ('no autoloader found ' );
2535}
2636
2737BypassFinals::enable ();
2838
29- $ acquireSession = new class ($ argv [1 ]) {
39+ [$ _cmd , $ databaseName ] = $ argv ;
40+
41+ $ acquireSession = new class ($ databaseName ) {
3042 use ProphecyTrait;
3143
32- public function __construct (private string $ databaseName )
33- {
44+ public function __construct (
45+ private string $ databaseName ,
46+ ) {
3447 }
3548
3649 public function run (): string
@@ -41,11 +54,9 @@ public function run(): string
4154 throw new \Exception ('createSession called in child process - this shouldn \'t happen ' );
4255 });
4356
44- $ parts = explode ('/ ' , $ this ->databaseName );
4557 $ sessionCache = new SessionCache (
4658 $ spannerClient ->reveal (),
47- $ this ->databaseName ,
48- ['cacheItemPool ' => new FilesystemAdapter (array_pop ($ parts ))]
59+ $ this ->databaseName
4960 );
5061
5162 return $ sessionCache ->name ();
0 commit comments