Skip to content

Commit 9b0db83

Browse files
committed
Add support for the emulatore tests
1 parent f261ed5 commit 9b0db83

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

Datastore/src/DatastoreClient.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Google\Cloud\Core\ArrayTrait;
2828
use Google\Cloud\Core\ClientTrait;
2929
use Google\Cloud\Core\DetectProjectIdTrait;
30+
use Google\Cloud\Core\EmulatorTrait;
3031
use Google\Cloud\Core\Int64;
3132
use Google\Cloud\Core\TimestampTrait;
3233
use Google\Cloud\Datastore\Query\AggregationQuery;
@@ -99,6 +100,7 @@ class DatastoreClient
99100
use TimestampTrait;
100101
use ApiHelperTrait;
101102
use ClientOptionsTrait;
103+
use EmulatorTrait;
102104

103105
const VERSION = '1.34.0';
104106

@@ -212,9 +214,33 @@ public function __construct(array $config = [])
212214
'emulatorHost' => $emulatorHost,
213215
];
214216

215-
$gapicConfig = $this->buildClientOptions($config);
216-
$this->projectId = $this->detectProjectId($gapicConfig);
217-
$this->gapicClient = $this->getGapicClient($gapicConfig);
217+
$gapicOptions = $this->buildClientOptions($config);
218+
219+
if (isset($gapicOptions['credentialsConfig']['scopes'])) {
220+
$options['credentialsConfig']['scopes'] = array_merge(
221+
$gapicOptions['credentialsConfig']['scopes'],
222+
$config['scopes']
223+
);
224+
} else {
225+
$options['credentialsConfig']['scopes'] = $config['scopes'];
226+
}
227+
228+
if ($emulatorHost) {
229+
$emulatorConfig = $this->emulatorGapicConfig($emulatorHost);
230+
$gapicOptions = array_merge(
231+
$gapicOptions,
232+
$emulatorConfig
233+
);
234+
} else {
235+
$gapicOptions['credentials'] = $this->createCredentialsWrapper(
236+
$gapicOptions['credentials'],
237+
$gapicOptions['credentialsConfig'],
238+
$gapicOptions['universeDomain']
239+
);
240+
}
241+
242+
$this->projectId = $this->detectProjectId($gapicOptions);
243+
$this->gapicClient = $this->getGapicClient($gapicOptions);
218244

219245
// The second parameter here should change to a variable
220246
// when gRPC support is added for variable encoding.

0 commit comments

Comments
 (0)