From a4ffa048e2a770703cfa4ce0ad68e93056bf81be Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 29 Apr 2025 13:51:26 -0700 Subject: [PATCH 1/7] fix: remove legacy google-cloud-resource-prefix in favor of x-goog-request-params --- Firestore/src/Connection/Grpc.php | 21 +++++++------------- Firestore/tests/Unit/Connection/GrpcTest.php | 7 +++++-- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Firestore/src/Connection/Grpc.php b/Firestore/src/Connection/Grpc.php index 608b7e18c109..cc3df4c86939 100644 --- a/Firestore/src/Connection/Grpc.php +++ b/Firestore/src/Connection/Grpc.php @@ -51,11 +51,6 @@ class Grpc implements ConnectionInterface */ private $firestore; - /** - * @var string - */ - private $resourcePrefixHeader; - /** * @var string */ @@ -121,14 +116,12 @@ public function __construct(array $config = []) $projectId = $this->pluck('projectId', $config); $databaseId = $this->pluck('database', $config); - $this->resourcePrefixHeader = FirestoreClient::databaseRootName( - $projectId, - $databaseId - ); + $database = FirestoreClient::databaseRootName($projectId, $databaseId); $this->databaseRoutingHeader = sprintf( - 'project_id=%s&database_id=%s', + 'project_id=%s&database_id=%s&database=%s', $projectId, - $databaseId + $databaseId, + urlencode($database) ); } @@ -312,8 +305,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) { @@ -351,7 +345,6 @@ public function __debugInfo() return [ 'serializer' => get_class($this->serializer), 'firestore' => get_class($this->firestore), - 'resourcePrefixHeader' => $this->resourcePrefixHeader, 'databaseRoutingHeader' => $this->databaseRoutingHeader, 'isUsingEmulator' => $this->isUsingEmulator ]; diff --git a/Firestore/tests/Unit/Connection/GrpcTest.php b/Firestore/tests/Unit/Connection/GrpcTest.php index 0202ec87c489..d763f68069e9 100644 --- a/Firestore/tests/Unit/Connection/GrpcTest.php +++ b/Firestore/tests/Unit/Connection/GrpcTest.php @@ -404,8 +404,11 @@ 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" => [ + 'project_id=test' + . '&database_id=(default)' + . '&database=projects%2Ftest%2Fdatabases%2F%28default%29' + ] ] ]; } From f30b2b2da337531f4901aed3f665681b4ff92d47 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Thu, 1 May 2025 10:19:52 -0700 Subject: [PATCH 2/7] remove legacy params --- Firestore/src/Connection/Grpc.php | 7 +------ Firestore/tests/Unit/Connection/GrpcTest.php | 4 +--- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/Firestore/src/Connection/Grpc.php b/Firestore/src/Connection/Grpc.php index cc3df4c86939..6c5f765d1a9d 100644 --- a/Firestore/src/Connection/Grpc.php +++ b/Firestore/src/Connection/Grpc.php @@ -117,12 +117,7 @@ public function __construct(array $config = []) $databaseId = $this->pluck('database', $config); $database = FirestoreClient::databaseRootName($projectId, $databaseId); - $this->databaseRoutingHeader = sprintf( - 'project_id=%s&database_id=%s&database=%s', - $projectId, - $databaseId, - urlencode($database) - ); + $this->databaseRoutingHeader = sprintf('database=%s', urlencode($database)); } /** diff --git a/Firestore/tests/Unit/Connection/GrpcTest.php b/Firestore/tests/Unit/Connection/GrpcTest.php index d763f68069e9..5368985f84bb 100644 --- a/Firestore/tests/Unit/Connection/GrpcTest.php +++ b/Firestore/tests/Unit/Connection/GrpcTest.php @@ -405,9 +405,7 @@ private function header() return [ "headers" => [ "x-goog-request-params" => [ - 'project_id=test' - . '&database_id=(default)' - . '&database=projects%2Ftest%2Fdatabases%2F%28default%29' + 'database=projects%2Ftest%2Fdatabases%2F%28default%29' ] ] ]; From a3e2be6412223398baa22c00fb218937ac0a8be8 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Thu, 15 May 2025 12:46:05 -0700 Subject: [PATCH 3/7] update emulator versions --- .github/workflows/system-tests-bigtable-emulator.yaml | 2 +- .github/workflows/system-tests-datastore-emulator.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/system-tests-bigtable-emulator.yaml b/.github/workflows/system-tests-bigtable-emulator.yaml index 6cc00a8032cb..bac12357e22f 100644 --- a/.github/workflows/system-tests-bigtable-emulator.yaml +++ b/.github/workflows/system-tests-bigtable-emulator.yaml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v4 - - run: ./.github/emulator/start-emulator.sh bigtable 419.0.0-emulators + - run: ./.github/emulator/start-emulator.sh bigtable 521.0.0-emulators - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/system-tests-datastore-emulator.yaml b/.github/workflows/system-tests-datastore-emulator.yaml index 722ebd2a9546..1fafdc5bf11a 100644 --- a/.github/workflows/system-tests-datastore-emulator.yaml +++ b/.github/workflows/system-tests-datastore-emulator.yaml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v4 - - run: ./.github/emulator/start-emulator.sh datastore 419.0.0-emulators + - run: ./.github/emulator/start-emulator.sh datastore 521.0.0-emulators - name: Setup PHP uses: shivammathur/setup-php@v2 From 50f9046be92066538a713a08a2a5bda3345b6497 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 May 2025 16:19:06 -0700 Subject: [PATCH 4/7] WIP: add test --- .../system-tests-firestore-emulator.yaml | 2 +- Firestore/tests/System/ListenTest.php | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 Firestore/tests/System/ListenTest.php diff --git a/.github/workflows/system-tests-firestore-emulator.yaml b/.github/workflows/system-tests-firestore-emulator.yaml index 0a9c182c507e..a37278f0d642 100644 --- a/.github/workflows/system-tests-firestore-emulator.yaml +++ b/.github/workflows/system-tests-firestore-emulator.yaml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v4 - - 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 diff --git a/Firestore/tests/System/ListenTest.php b/Firestore/tests/System/ListenTest.php new file mode 100644 index 000000000000..2e66e9a181c1 --- /dev/null +++ b/Firestore/tests/System/ListenTest.php @@ -0,0 +1,67 @@ +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(); + $stream->writeAll([$request,]); + + /** @var ListenResponse $element */ + foreach ($stream->closeWriteAndReadAll() as $element) { + // TODO: Assert something + } + } +} From 15c6f8a2ca91594dd2e78aa4e5cf6e5d0e4dbd2c Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 9 Jul 2025 09:48:12 -0700 Subject: [PATCH 5/7] fix cs --- Firestore/tests/System/ListenTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Firestore/tests/System/ListenTest.php b/Firestore/tests/System/ListenTest.php index 2e66e9a181c1..7aadc0d61a22 100644 --- a/Firestore/tests/System/ListenTest.php +++ b/Firestore/tests/System/ListenTest.php @@ -23,7 +23,6 @@ use Google\Cloud\Firestore\V1\ListenRequest; use Google\Cloud\Firestore\V1\ListenResponse; - /** * @group firestore * @group firestore-listen From a68e4ea9cdfc36251a01fefe358446ca673db3b9 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 27 Aug 2025 14:54:09 -0700 Subject: [PATCH 6/7] add tests, update emulator versions --- .../emulator-system-tests-bigtable.yaml | 2 +- .../emulator-system-tests-datastore.yaml | 2 +- Firestore/tests/System/ListenTest.php | 33 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/.github/workflows/emulator-system-tests-bigtable.yaml b/.github/workflows/emulator-system-tests-bigtable.yaml index b29eaf4a3f72..fc49ee42f6a4 100644 --- a/.github/workflows/emulator-system-tests-bigtable.yaml +++ b/.github/workflows/emulator-system-tests-bigtable.yaml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v5 - - run: ./.github/emulator/start-emulator.sh bigtable 521.0.0-emulators + - run: ./.github/emulator/start-emulator.sh bigtable 522.0.0-emulators - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/emulator-system-tests-datastore.yaml b/.github/workflows/emulator-system-tests-datastore.yaml index bb44626dbb3a..b562e9931b83 100644 --- a/.github/workflows/emulator-system-tests-datastore.yaml +++ b/.github/workflows/emulator-system-tests-datastore.yaml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v5 - - run: ./.github/emulator/start-emulator.sh datastore 521.0.0-emulators + - run: ./.github/emulator/start-emulator.sh datastore 522.0.0-emulators - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/Firestore/tests/System/ListenTest.php b/Firestore/tests/System/ListenTest.php index 7aadc0d61a22..bede6a572eb5 100644 --- a/Firestore/tests/System/ListenTest.php +++ b/Firestore/tests/System/ListenTest.php @@ -49,6 +49,39 @@ public function testListen() // 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); From dbb2a72c0efc36d261a684ef88a2cc0ae6b60506 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 27 Aug 2025 14:58:09 -0700 Subject: [PATCH 7/7] fix cs --- Firestore/tests/System/ListenTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Firestore/tests/System/ListenTest.php b/Firestore/tests/System/ListenTest.php index bede6a572eb5..ce5bcc206e48 100644 --- a/Firestore/tests/System/ListenTest.php +++ b/Firestore/tests/System/ListenTest.php @@ -75,7 +75,8 @@ 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\'.' + 'Missing required http header (\'google-cloud-resource-prefix\' or \'x-goog-request-params\')' + . ' or query param \'database\'.' ); $database = sprintf(self::DATABASE, $this->projectId);