Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/emulator-system-tests-bigtable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@v5

- run: ./.github/emulator/start-emulator.sh bigtable 419.0.0-emulators
- run: ./.github/emulator/start-emulator.sh bigtable 522.0.0-emulators

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/emulator-system-tests-datastore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@v5

- run: ./.github/emulator/start-emulator.sh datastore 419.0.0-emulators
- run: ./.github/emulator/start-emulator.sh datastore 522.0.0-emulators

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/emulator-system-tests-firestore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@v5

- run: ./.github/emulator/start-emulator.sh firestore 453.0.0-emulators
- run: ./.github/emulator/start-emulator.sh firestore 522.0.0-emulators

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
22 changes: 5 additions & 17 deletions Firestore/src/Connection/Grpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ class Grpc implements ConnectionInterface
*/
private $firestore;

/**
* @var string
*/
private $resourcePrefixHeader;

/**
* @var string
*/
Expand Down Expand Up @@ -124,15 +119,8 @@ public function __construct(array $config = [])
$projectId = $this->pluck('projectId', $config);
$databaseId = $this->pluck('database', $config);

$this->resourcePrefixHeader = FirestoreClient::databaseRootName(
$projectId,
$databaseId
);
$this->databaseRoutingHeader = sprintf(
'project_id=%s&database_id=%s',
$projectId,
$databaseId
);
$database = FirestoreClient::databaseRootName($projectId, $databaseId);
$this->databaseRoutingHeader = sprintf('database=%s', urlencode($database));
}

/**
Expand Down Expand Up @@ -315,8 +303,9 @@ private function addRequestHeaders(array $args)
'headers' => []
];

$args['headers']['google-cloud-resource-prefix'] = [$this->resourcePrefixHeader];
$args['headers']['x-goog-request-params'] = [$this->databaseRoutingHeader];
$args['headers']['x-goog-request-params'] = [
$this->databaseRoutingHeader,
];

// Provide authentication header for requests when emulator is enabled.
if ($this->isUsingEmulator) {
Expand Down Expand Up @@ -354,7 +343,6 @@ public function __debugInfo()
return [
'serializer' => get_class($this->serializer),
'firestore' => get_class($this->firestore),
'resourcePrefixHeader' => $this->resourcePrefixHeader,
'databaseRoutingHeader' => $this->databaseRoutingHeader,
'isUsingEmulator' => $this->isUsingEmulator
];
Expand Down
99 changes: 99 additions & 0 deletions Firestore/tests/System/ListenTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Firestore\Tests\System;

use Google\ApiCore\ApiException;
use Google\ApiCore\BidiStream;
use Google\Cloud\Firestore\V1\Client\FirestoreClient;
use Google\Cloud\Firestore\V1\ListenRequest;
use Google\Cloud\Firestore\V1\ListenResponse;

/**
* @group firestore
* @group firestore-listen
*/
class ListenTest extends FirestoreTestCase
{
const DATABASE = 'projects/%s/databases/(default)';

private $query;

public function setUp(): void
{
$this->query = self::$client->collection(uniqid(self::COLLECTION_NAME));
self::$localDeletionQueue->add($this->query);
if (!$this->projectId = getenv('GOOGLE_CLOUD_FIRESTORE_PROJECT')) {
$this->markTestSkipped('please set the GOOGLE_CLOUD_FIRESTORE_PROJECT env var');
}
}

public function testListen()
{
$database = sprintf(self::DATABASE, $this->projectId);

// Create a client.
$firestoreClient = new FirestoreClient();

// Prepare the request message.
$request = (new ListenRequest())
->setDatabase($database);

// Call the API and handle any network failures.
/** @var BidiStream $stream */
$stream = $firestoreClient->listen([
'headers' => [
'x-goog-request-params' => [
'database=' . $database
]
]
]);
$stream->writeAll([$request,]);

/** @var ListenResponse $element */
foreach ($stream->closeWriteAndReadAll() as $element) {
// TODO: Assert something
}
$this->assertTrue(true);
}

public function testListenThrowsExceptionWithoutDatabaseHeader()
{
$this->expectException(ApiException::class);
$this->expectExceptionMessage(
'Missing required http header (\'google-cloud-resource-prefix\' or \'x-goog-request-params\') or query param \'database\'.'
);
$database = sprintf(self::DATABASE, $this->projectId);

// Create a client.
$firestoreClient = new FirestoreClient();

// Prepare the request message.
$request = (new ListenRequest())
->setDatabase($database);

// Call the API and handle any network failures.
/** @var BidiStream $stream */
$stream = $firestoreClient->listen();
$stream->writeAll([$request,]);

/** @var ListenResponse $element */
foreach ($stream->closeWriteAndReadAll() as $element) {
// TODO: Assert something
}
}
}
5 changes: 3 additions & 2 deletions Firestore/tests/Unit/Connection/GrpcTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,9 @@ private function header()
{
return [
"headers" => [
"google-cloud-resource-prefix" => ["projects/test/databases/(default)"],
"x-goog-request-params" => ["project_id=test&database_id=(default)"]
"x-goog-request-params" => [
'database=projects%2Ftest%2Fdatabases%2F%28default%29'
]
]
];
}
Expand Down
Loading