33namespace Google \Cloud \Spanner \Tests \Unit \Session ;
44
55use DG \BypassFinals ;
6+ use Exception ;
7+ use Google \Auth \Cache \SysVCacheItemPool ;
68use Google \Cloud \Spanner \Session \SessionCache ;
79use Google \Cloud \Spanner \V1 \Client \SpannerClient ;
810use Prophecy \Argument ;
1517 die ('Usage: lock_test_process.php DATABASE_NAME ' . PHP_EOL );
1618}
1719
18- 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 )) {
1928 // google/cloud-spanner autoload
20- require __DIR__ . ' /../../../vendor/autoload.php ' ;
21- } elseif (file_exists (__DIR__ . ' /../../../../vendor/autoload.php ' )) {
29+ require $ spannerAutoload ;
30+ } elseif (file_exists ($ googleCloudAutoload )) {
2231 // google/cloud autoload
23- require __DIR__ . '/../../../../vendor/autoload.php ' ;
32+ require $ googleCloudAutoload ;
33+ } else {
34+ throw new Exception ('no autoloader found ' );
2435}
2536
2637BypassFinals::enable ();
@@ -39,13 +50,17 @@ public function run(): string
3950 ->will (function () {
4051 throw new \Exception ('createSession called in child process - this shouldn \'t happen ' );
4152 });
42-
43- $ parts = explode ('/ ' , $ this ->databaseName );
4453 $ sessionCache = new SessionCache (
4554 $ spannerClient ->reveal (),
4655 $ this ->databaseName ,
4756 );
4857
58+ $ cacheItemPoolProp = (new \ReflectionClass ($ sessionCache ))->getProperty ('cacheItemPool ' );
59+ $ cacheItemPool = $ cacheItemPoolProp ->getValue ($ sessionCache );
60+ if (!$ cacheItemPool instanceof SysVCacheItemPool) {
61+ throw new \Exception ('Expected SysvCacheItemPool, found ' . get_class ($ cacheItemPool ));
62+ }
63+
4964 return $ sessionCache ->name ();
5065 }
5166
0 commit comments